private SpanNode copySpan(SpanNode spanTree) { if (spanTree instanceof Span) { return new Span((Span) spanTree); } else if (spanTree instanceof AlternateSpanList) { return new AlternateSpanList((AlternateSpanList) spanTree); } else if (spanTree instanceof SpanList) { return new SpanList((SpanList) spanTree); } else if (spanTree instanceof DummySpanNode) { return spanTree; //shouldn't really happen } else { throw new IllegalStateException("Cannot create copy of " + spanTree + " with class " + ((spanTree == null) ? "null" : spanTree.getClass())); } }
/** * Deep-copies a SpanList. * * @param other the SpanList to copy. */ public SpanList(SpanList other) { this.children = new LinkedList<SpanNode>(); for (SpanNode otherNode : other.children) { if (otherNode instanceof Span) { children.add(new Span((Span) otherNode)); } else if (otherNode instanceof AlternateSpanList) { children.add(new AlternateSpanList((AlternateSpanList) otherNode)); } else if (otherNode instanceof SpanList) { children.add(new SpanList((SpanList) otherNode)); } else if (otherNode instanceof DummySpanNode) { children.add(otherNode); //shouldn't really happen } else { throw new IllegalStateException("Cannot create copy of " + otherNode + " with class " + ((otherNode == null) ? "null" : otherNode.getClass())); } } }
public AlternateSpanList(AlternateSpanList otherSpanList) { super((List<SpanNode>) null); for (Children otherSubtree : otherSpanList.childTrees) { //create our own subtree: Children children = new Children(this); //copy nodes: for (SpanNode otherNode : otherSubtree.children()) { if (otherNode instanceof Span) { children.add(new Span((Span) otherNode)); } else if (otherNode instanceof AlternateSpanList) { children.add(new AlternateSpanList((AlternateSpanList) otherNode)); } else if (otherNode instanceof SpanList) { children.add(new SpanList((SpanList) otherNode)); } else if (otherNode instanceof DummySpanNode) { children.add(otherNode); //shouldn't really happen } else { throw new IllegalStateException("Cannot create copy of " + otherNode + " with class " + ((otherNode == null) ? "null" : otherNode.getClass())); } } //add this subtree to our subtrees: childTrees.add(children); } }
private SpanNode readSpanNode() { byte type = buf.get(); buf.position(buf.position() - 1); SpanNode retval; if ((type & Span.ID) == Span.ID) { retval = new Span(); if (spanNodes != null) { spanNodes.add(retval); } read((Span) retval); } else if ((type & SpanList.ID) == SpanList.ID) { retval = new SpanList(); if (spanNodes != null) { spanNodes.add(retval); } read((SpanList) retval); } else if ((type & AlternateSpanList.ID) == AlternateSpanList.ID) { retval = new AlternateSpanList(); if (spanNodes != null) { spanNodes.add(retval); } read((AlternateSpanList) retval); } else { throw new DeserializationException("Cannot read SpanNode of type " + type); } return retval; }
private SpanNode readSpanNode() { byte type = buf.get(); buf.position(buf.position() - 1); SpanNode retval; if ((type & Span.ID) == Span.ID) { retval = new Span(); if (spanNodes != null) { spanNodes.add(retval); } read((Span) retval); } else if ((type & SpanList.ID) == SpanList.ID) { retval = new SpanList(); if (spanNodes != null) { spanNodes.add(retval); } read((SpanList) retval); } else if ((type & AlternateSpanList.ID) == AlternateSpanList.ID) { retval = new AlternateSpanList(); if (spanNodes != null) { spanNodes.add(retval); } read((AlternateSpanList) retval); } else { throw new DeserializationException("Cannot read SpanNode of type " + type); } return retval; }