Search in sources :

Example 41 with TreeSet

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);
}
Also used : TreeSet(java.util.TreeSet) Iterator(java.util.Iterator)

Example 42 with TreeSet

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);
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) TreeSet(java.util.TreeSet) BitSet(java.util.BitSet) TreeSet(java.util.TreeSet)

Example 43 with TreeSet

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) {
    }
}
Also used : TreeSet(java.util.TreeSet)

Example 44 with TreeSet

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;
}
Also used : TreeSet(java.util.TreeSet)

Example 45 with TreeSet

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;
}
Also used : TreeSet(java.util.TreeSet) Rectangle(java.awt.Rectangle) HashSet(java.util.HashSet)

Aggregations

TreeSet (java.util.TreeSet)3795 ArrayList (java.util.ArrayList)835 Test (org.junit.Test)544 HashMap (java.util.HashMap)502 HashSet (java.util.HashSet)430 Set (java.util.Set)424 Map (java.util.Map)405 IOException (java.io.IOException)378 File (java.io.File)341 List (java.util.List)323 TreeMap (java.util.TreeMap)229 Iterator (java.util.Iterator)189 SortedSet (java.util.SortedSet)186 LinkedList (java.util.LinkedList)110 LinkedHashSet (java.util.LinkedHashSet)106 Date (java.util.Date)94 Collection (java.util.Collection)92 Comparator (java.util.Comparator)85 Test (org.testng.annotations.Test)81 Text (org.apache.hadoop.io.Text)79