package jetbrains.mps.make.java;
/*Generated by MPS */
import java.util.Map;
import jetbrains.mps.internal.collections.runtime.MapSequence;
import java.util.HashMap;
import org.jdom.Element;
import jetbrains.mps.internal.collections.runtime.SetSequence;
import java.util.Arrays;
import java.util.List;
public class ModelDependencies {
private static final String DEPENDENCY = "dependency";
private static final String DEPENDENCIES_ROOT = "dependenciesRoot";
private Map<String, RootDependencies> myDependencies = MapSequence.fromMap(new HashMap<String, RootDependencies>());
public ModelDependencies() {
}
public void addDependencies(RootDependencies newDependency) {
MapSequence.fromMap(myDependencies).put(newDependency.getFileName(), newDependency);
}
public Iterable<RootDependencies> getDependencies() {
return MapSequence.fromMap(myDependencies).values();
}
public RootDependencies getDependency(String fileName) {
return MapSequence.fromMap(myDependencies).get(fileName);
}
public void replaceRoot(RootDependencies rootDependencies) {
MapSequence.fromMap(myDependencies).put(rootDependencies.getFileName(), rootDependencies);
}
public Element toXml() {
Element root = new Element(DEPENDENCIES_ROOT);
String[] list = SetSequence.fromSet(MapSequence.fromMap(myDependencies).keySet()).toGenericArray(String.class);
Arrays.sort(list);
for (String rootName : list) {
Element e = new Element(DEPENDENCY);
MapSequence.fromMap(myDependencies).get(rootName).saveTo(e);
root.addContent(e);
}
return root;
}
public static ModelDependencies fromXml(Element root) {
ModelDependencies result = new ModelDependencies();
for (Element e : ((List<Element>) root.getChildren(DEPENDENCY))) {
result.addDependencies(new RootDependencies(e));
}
return result;
}
}