use of java.util.TreeSet in project mapdb by jankotek.
the class TreeSetTest method testIterator.
/**
* iterator iterates through all elements
*/
public void testIterator() {
TreeSet q = populatedSet(SIZE);
Iterator it = q.iterator();
int i;
for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next()));
assertEquals(i, SIZE);
assertIteratorExhausted(it);
}
use of java.util.TreeSet in project mapdb by jankotek.
the class TreeSetTest method testAddAll_idempotent.
/**
* addAll is idempotent
*/
public void testAddAll_idempotent() throws Exception {
Set x = populatedSet(SIZE);
Set y = new TreeSet(x);
y.addAll(x);
assertEquals(x, y);
assertEquals(y, x);
}
use of java.util.TreeSet in project mapdb by jankotek.
the class TreeSetTest method testAddAll2.
/**
* addAll of a collection with null elements throws NPE
*/
public void testAddAll2() {
TreeSet q = new TreeSet();
Integer[] ints = new Integer[SIZE];
try {
q.addAll(Arrays.asList(ints));
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.TreeSet in project mapdb by jankotek.
the class TreeSubSetTest method dset0.
private static NavigableSet dset0() {
TreeSet set = new TreeSet();
assertTrue(set.isEmpty());
return set;
}
use of java.util.TreeSet in project jna by java-native-access.
the class RasterRangesUtils method outputOccupiedRangesOfBinaryPixels.
/**
* Output the non-null values of a binary image as ranges of contiguous values.
* @param binaryBits byte-packed binary bits of an image
* @param w width of the image (in pixels)
* @param h height of the image
* @param out
* @return true if the output succeeded, false otherwise
*/
public static boolean outputOccupiedRangesOfBinaryPixels(byte[] binaryBits, int w, int h, RangesOutput out) {
Set<Rectangle> rects = new HashSet<Rectangle>();
Set<Rectangle> prevLine = Collections.<Rectangle>emptySet();
int scanlineBytes = binaryBits.length / h;
for (int row = 0; row < h; row++) {
Set<Rectangle> curLine = new TreeSet<Rectangle>(COMPARATOR);
int rowOffsetBytes = row * scanlineBytes;
int startCol = -1;
// Look at each batch of 8 columns in this row
for (int byteCol = 0; byteCol < scanlineBytes; byteCol++) {
int firstByteCol = byteCol << 3;
byte byteColBits = binaryBits[rowOffsetBytes + byteCol];
if (byteColBits == 0) {
// all 8 bits are zeroes
if (startCol >= 0) {
// end of current region
curLine.add(new Rectangle(startCol, row, firstByteCol - startCol, 1));
startCol = -1;
}
} else if (byteColBits == 0xff) {
// all 8 bits are ones
if (startCol < 0) {
// start of new region
startCol = firstByteCol;
}
} else {
// mixed case : some bits are ones, others are zeroes
for (int subCol = 0; subCol < 8; subCol++) {
int col = firstByteCol | subCol;
if ((byteColBits & subColMasks[subCol]) != 0) {
if (startCol < 0) {
// start of new region
startCol = col;
}
} else {
if (startCol >= 0) {
// end of current region
curLine.add(new Rectangle(startCol, row, col - startCol, 1));
startCol = -1;
}
}
}
}
}
if (startCol >= 0) {
// end of last region
curLine.add(new Rectangle(startCol, row, w - startCol, 1));
}
Set<Rectangle> unmerged = mergeRects(prevLine, curLine);
rects.addAll(unmerged);
prevLine = curLine;
}
// Add anything left over
rects.addAll(prevLine);
for (Iterator<Rectangle> i = rects.iterator(); i.hasNext(); ) {
Rectangle r = i.next();
if (!out.outputRange(r.x, r.y, r.width, r.height)) {
return false;
}
}
return true;
}
Aggregations