use of gate.util.RBTreeMap in project gate-core by GateNLP.
the class AnnotationSetImpl method readObject.
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
this.longestAnnot = 0l;
ObjectInputStream.GetField gf = in.readFields();
this.name = (String) gf.get("name", null);
this.doc = (DocumentImpl) gf.get("doc", null);
boolean isIndexedByType = false;
boolean isIndexedByStartNode = false;
this.annotations = (Annotation[]) gf.get("annotations", null);
if (this.annotations == null) {
// old style serialised version
@SuppressWarnings("unchecked") Map<Integer, Annotation> annotsByIdMap = (Map<Integer, Annotation>) gf.get("annotsById", null);
if (annotsByIdMap == null)
throw new IOException("Invalid serialised data: neither annotations array or map by id" + " are present.");
annotations = annotsByIdMap.values().toArray(new Annotation[] {});
} else {
// new style serialised version
isIndexedByType = in.readBoolean();
isIndexedByStartNode = in.readBoolean();
}
// this.name = (String)in.readObject();
// this.doc = (DocumentImpl)in.readObject();
// Annotation[] annotations = (Annotation[])in.readObject();
// do we need to create the indices?
// boolean isIndexedByType = in.readBoolean();
// boolean isIndexedByStartNode = in.readBoolean();
this.annotsById = new HashMap<Integer, Annotation>(annotations.length);
// rebuilds the indices if required
if (isIndexedByType) {
annotsByType = new HashMap<String, AnnotationSet>(Gate.HASH_STH_SIZE);
}
if (isIndexedByStartNode) {
nodesByOffset = new RBTreeMap<Long, Node>();
annotsByStartNode = new HashMap<Integer, Object>(annotations.length);
}
// add all the annotations one by one
for (int i = 0; i < annotations.length; i++) {
add(annotations[i]);
}
this.relations = (RelationSet) gf.get("relations", null);
annotations = null;
}
Aggregations