Search in sources :

Example 1 with RBTreeMap

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;
}
Also used : Node(gate.Node) AnnotationSet(gate.AnnotationSet) IOException(java.io.IOException) Annotation(gate.Annotation) HashMap(java.util.HashMap) Map(java.util.Map) FeatureMap(gate.FeatureMap) RBTreeMap(gate.util.RBTreeMap) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Annotation (gate.Annotation)1 AnnotationSet (gate.AnnotationSet)1 FeatureMap (gate.FeatureMap)1 Node (gate.Node)1 RBTreeMap (gate.util.RBTreeMap)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1