public Object next() { // see if there is another duplicate to emit if (this.currentDup < this.dupLimit) { this.currentDup++; return this.current; } //otherwise, go to next object this.mapIterator.advance(); this.dupLimit = this.mapIterator.value(); this.currentDup = 1; this.current = this.mapIterator.key(); return this.current; }
/** * @return an iterator over the entries in this map */ public TObjectIntIterator iterator() { return new TObjectIntIterator(this); }
public boolean hasNext() { if (this.emitNull) { return true; } return it.hasNext(); }
public void toData(DataOutput out) throws IOException { DataSerializer.writeObject(this.elementType, out); out.writeInt(this.size()); this.writeNumNulls(out); // TODO:Asif: Should we actually pass the limit in serialization? // For the time being not passing , assuming PR Has parsed // it // out.writeInt(this.limit); int numLeft = this.size() - this.numNulls; for (TObjectIntIterator itr = this.map.iterator(); itr.hasNext() && numLeft > 0;) { itr.advance(); Object key = itr.key(); DataSerializer.writeObject(key, out); int occurence = itr.value(); if (numLeft < occurence) { occurence = numLeft; } out.writeInt(occurence); numLeft -= occurence; } }
/** Creates a StructSet directly from a StructBag; * (internal use) * @since 5.1 */ StructSet(StructBag bag) { super(new ObjectArrayHashingStrategy()); this.structType = (StructType)bag.elementType; if (bag.hasLimitIterator) { // Asif: Since the number of unique keys which // will be returned by Bag with limit in place // cannot be more than the size of the bag ( i.e // the limit) , we can safely assume HashMap size // to equal to bag's size ensureCapacity(bag.size()); Iterator itr = bag.fieldValuesIterator(); while (itr.hasNext()) { addFieldValues((Object[])itr.next()); } } else { TObjectIntIterator itr = bag.map.iterator(); ensureCapacity(bag.map.size()); while (itr.hasNext()) { itr.advance(); addFieldValues((Object[])itr.key()); } } }
/** * Replace the value of the mapping at the iterator's position with the * specified value. Note that you must <tt>advance()</tt> the iterator at * least once before invoking this method. * * @param val the value to set in the current entry * @return the old value of the entry. */ public int setValue(int val) { int old = value(); _map._values[_index] = val; return old; } }// TObjectIntIterator
public void remove() { // if (this.currentDup == 0) { // // next has not yet been called // throw new IllegalStateException(LocalizedStrings.ResultsBag_NEXT_MUST_BE_CALLED_BEFORE_REMOVE.toLocalizedString()); // } this.dupLimit--; assert this.dupLimit >= 0 : this.dupLimit; if (this.current == null) { GfshResultsBag.this.numNulls = this.dupLimit; assert GfshResultsBag.this.numNulls >= 0 : GfshResultsBag.this.numNulls; } else { if (this.dupLimit > 0) { this.mapIterator.setValue(this.dupLimit); } else { this.mapIterator.remove(); } } GfshResultsBag.this.size--; this.currentDup--; assert GfshResultsBag.this.size >= 0 : GfshResultsBag.this.size; assert this.currentDup >= 0 : this.currentDup; } }
public void remove() { if(currentIsNull) { GfshResultsBag.this.numNulls = 0; } else { it.remove(); } } };
/** * Moves the iterator forward to the next entry in the underlying map. * * @exception java.util.NoSuchElementException if the iterator is already exhausted */ public void advance() { moveToNextIndex(); }
@Override public void remove() { if (this.currPos == 0) { // next has not yet been called throw new IllegalStateException("next() must be called before remove()"); } synchronized (GfshResultsBag.this.limitLock) { if(currentIsNull) { GfshResultsBag.this.limit -= GfshResultsBag.this.numNulls; GfshResultsBag.this.numNulls = 0; GfshResultsBag.SetView.this.localLimit--; } else { Object key = this.it.key(); int count = GfshResultsBag.this.map.remove(key); assert count != 0 : "Attempted to remove an element that was not in the map."; GfshResultsBag.this.limit -= count; GfshResultsBag.SetView.this.localLimit--; } } } }
public void toData(DataOutput out) throws IOException { DataSerializer.writeObject(this.elementType, out); out.writeInt(this.size()); this.writeNumNulls(out); // TODO:Asif: Should we actually pass the limit in serialization? // For the time being not passing , assuming PR Has parsed // it // out.writeInt(this.limit); int numLeft = this.size() - this.numNulls; for (TObjectIntIterator itr = this.map.iterator(); itr.hasNext() && numLeft > 0;) { itr.advance(); Object key = itr.key(); DataSerializer.writeObject(key, out); int occurence = itr.value(); if (numLeft < occurence) { occurence = numLeft; } out.writeInt(occurence); numLeft -= occurence; } }
public void remove() { if(currentIsNull) { ResultsBag.this.numNulls = 0; } else { it.remove(); } } };
public Object next() { // see if there is another duplicate to emit if (this.currentDup < this.dupLimit) { this.currentDup++; return (this.currentKey != null) ? this.currentKey : null; } //otherwise, go to next object this.mapIterator.advance(); this.currentKey = this.mapIterator.key(); this.currentValue = this.mapIterator.value(); this.dupLimit = this.currentValue; this.currentDup = 1; return this.currentKey; }
public boolean hasNext() { if (this.emitNull) { return true; } return it.hasNext(); }
public void remove() { if (this.currentDup == 0) { // next has not yet been called throw new IllegalStateException(LocalizedStrings.ResultsBag_NEXT_MUST_BE_CALLED_BEFORE_REMOVE.toLocalizedString()); } this.dupLimit--; assert this.dupLimit >= 0 : this.dupLimit; if (this.currentKey == null) { ResultsBag.this.numNulls = this.dupLimit; assert ResultsBag.this.numNulls >= 0 : ResultsBag.this.numNulls; } else { if (this.dupLimit > 0) { ResultsBag.this.map.put(this.currentKey, this.dupLimit); } else { this.mapIterator.remove(); } } ResultsBag.this.size--; this.currentDup--; assert ResultsBag.this.size >= 0 : ResultsBag.this.size; assert this.currentDup >= 0 : this.currentDup; } }
public boolean hasNext() { return this.mapIterator.hasNext() || this.currentDup < this.dupLimit; }
public boolean hasNext() { return this.mapIterator.hasNext() || this.currentDup < this.dupLimit; }