/** * Creates a new iterator for the current object. The iterator can be used to iterate through * the list of sources/targets associated with the current line of anchor text. * * @return A new iterator object. */ public Iterator<Integer> iterator() { return new Iterator<Integer>() { IntIterator iterator = documentList.iterator(); public boolean hasNext() { return iterator.hasNext(); } public Integer next() { return iterator.next(); } public void remove() { iterator.remove(); } }; } }
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { final IntIterator i = iterator(); s.defaultWriteObject(); for (int j = size; j-- != 0;) s.writeInt(i.nextInt()); }
/** * Serializes an AnchorText object * * @param out * Output Stream */ public void write(DataOutput out) throws IOException { out.writeByte(type); if(hasValidText()) { out.writeUTF(text); } if(hasValidDocumentList()) { out.writeInt(documentList.size()); IntIterator iterator = documentList.iterator(); while(iterator.hasNext()) { out.writeInt(iterator.next()); } } if(hasValidWeight()) { out.writeFloat(weight); } }
/** * Adds the sources/targets from another AnchorText to the current object * * @param other The other AnchorText object from which the * sources/targets are to be copied. */ public void addDocumentsFrom(AnchorText other) { if(!hasValidDocumentList()) { return; } IntIterator iterator = other.documentList.iterator(); while(iterator.hasNext()) { addDocument(iterator.next()); } }
/** * Checks whether two lines of anchor text share a source/target document * * @param other The other anchor text * @return True if this line of anchor text has a common source/target * with the other line of anchor text. */ public boolean intersects(AnchorText other) { if(!hasValidDocumentList() || !other.hasValidDocumentList()) { return false; } if(getSize() < other.getSize()) { IntIterator iterator = documentList.iterator(); while(iterator.hasNext()) { if(other.containsDocument(iterator.next())) { return true; } } } else { IntIterator iterator = other.documentList.iterator(); while(iterator.hasNext()) { if(documentList.contains(iterator.next())) { return true; } } } return false; }
/** * Does a thorough comparison of two AnchorText objects. */ public boolean equals(Object obj) { AnchorText other = (AnchorText) obj; if(hasValidDocumentList() && other.hasValidDocumentList()) { if(documentList.size() != other.documentList.size()) { return false; } IntIterator iterator = documentList.iterator(); while(iterator.hasNext()) { if(!other.containsDocument(iterator.next())) { return false; } } } return equalsIgnoreSources(other); }
for(final IntIterator iterator = hashesSeen.iterator(); iterator.hasNext();) assert overallHashes.add(iterator.nextInt());