org.yamcs.xtce.NamedDescriptionIndex Maven / Gradle / Ivy
The newest version!
package org.yamcs.xtce;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.yamcs.xtce.xml.XtceAliasSet;
/**
* Keeps a list of {@link NameDescription} objects with corresponding indexes to be able to retrieve them in any namespace.
*
* Note that the names are case sensitive while aliases are not.
*
* @author nm
*
*/
public class NamedDescriptionIndex implements Serializable, Iterable {
private static final long serialVersionUID = 4L;
private LinkedHashMap> aliasIndex = new LinkedHashMap>();
private LinkedHashMap index = new LinkedHashMap();
public void add(T o) {
XtceAliasSet aliases = o.getAliasSet();
if (aliases != null) {
for (String ns : aliases.getNamespaces()) {
LinkedHashMap m = aliasIndex.computeIfAbsent(ns, k -> new LinkedHashMap());
m.put(aliases.getAlias(ns).toUpperCase(), o);
}
}
//add an "alias" for (fq_space_system_name, name)
LinkedHashMap m = aliasIndex.computeIfAbsent(o.getSubsystemName(), k -> new LinkedHashMap());
m.put(o.getName().toUpperCase(), o);
if (o.getQualifiedName() != null) {
index.put(o.getQualifiedName(), o);
} else {
index.put(o.getName(), o); // Happens for Derived Values
}
}
/**
* returns the object based on its qualified name
*/
public T get(String qualifiedName) {
return index.get(qualifiedName);
}
/**
* returns the object in namespace
*
* @param name
* @param nameSpace
* @return
*/
public T get(String nameSpace, String name) {
Map m = aliasIndex.get(nameSpace);
if (m != null) {
return m.get(name.toUpperCase());
} else {
return null;
}
}
/**
* returns a collection of all the objects (parameters) in the index
*
* @return
*/
public Collection getObjects() {
return index.values();
}
/**
*
* @return number of objects in index
*/
public int size() {
return index.size();
}
@Override
public Iterator iterator() {
return index.values().iterator();
}
}