package hep.aida.ref;
/**
* Implementation of IAnnotation.
*
* It keeps the exact case of added keys, but all other methods
* are not case sensitive
* @author The AIDA Team at SLAC.
*
*/
import hep.aida.IAnnotation;
import java.util.Vector;
public class Annotation implements IAnnotation, Cloneable {
protected Vector keyVector = new Vector();
protected Vector valVector = new Vector();
protected Vector stkVector = new Vector();
protected boolean fillable = true;
public static String titleKey = "Title";
public static String aidaPathKey = "AidaPath"; // Path in the local AIDA ITree
public static String fullPathKey = "FullPath"; // Path in the top-level AIDA Tree (aidaMasterTree)
/**
* Creates a new instance of Annotation.
*
*/
public Annotation() {
addItem(titleKey,"",true);
}
public Annotation(IAnnotation an) {
this();
copyAn(an);
}
public Object clone() {
try {
Annotation copy = new Annotation(this);
return copy;
} catch (Exception e) {
throw new RuntimeException("Error while cloning Annotation", e);
}
}
private void copyAn(IAnnotation an) {
int size = an.size();
for (int i=0; i -1; i-- ) {
if ( ! ((Boolean)stkVct[i]).booleanValue() ) {
keyVector.remove(i);
valVector.remove(i);
stkVector.remove(i);
}
}
}
/**
* Utility method to check if an index is valid for the current configuration of the Annotation.
* @param index The index to be checked.
*
*/
protected void checkIndex(int index) {
if ( index + 1 > size() ) throw new IllegalArgumentException("Index "+index+" exceeds the dimension of the Annotation: "+size());
if ( index < 0 ) throw new IllegalArgumentException("Index "+index+" cannot be negative");
}
public int findKey(String key) {
String localKey = getKeyForKey(key);
if ( localKey == null || ! keyVector.contains(localKey) ) throw new IllegalArgumentException("Item "+key+" does not exist");
return keyVector.indexOf(localKey);
}
public boolean hasKey(String key) {
String localKey = getKeyForKey(key);
return localKey != null;
}
}
Ads help maintain this website.