/** * Write the bag into a string. */ @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append('{'); Iterator<Tuple> it = iterator(); while ( it.hasNext() ) { Tuple t = it.next(); String s = t.toString(); sb.append(s); if (it.hasNext()) sb.append(","); } sb.append('}'); return sb.toString(); }
/** * Write a bag's contents to disk. * @param out DataOutput to write data to. * @throws IOException (passes it on from underlying calls). */ public void write(DataOutput out) throws IOException { // We don't care whether this bag was sorted or distinct because // using the iterator to write it will guarantee those things come // correctly. And on the other end there'll be no reason to waste // time re-sorting or re-applying distinct. out.writeLong(size()); Iterator<Tuple> it = iterator(); while (it.hasNext()) { Tuple item = it.next(); item.write(out); } }
DataBag otherClone; thisClone = factory.newSortedBag(null); Iterator<Tuple> i = iterator(); while (i.hasNext()) thisClone.add(i.next()); if (((DataBag) other).isSorted() || ((DataBag) other).isDistinct()) {