Example usage for java.util TreeSet headSet

List of usage examples for java.util TreeSet headSet

Introduction

In this page you can find the example usage for java.util TreeSet headSet.

Prototype

public SortedSet<E> headSet(E toElement) 

Source Link

Usage

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    String elements[] = { "A", "C", "D", "G", "F" };
    TreeSet set = new TreeSet(Arrays.asList(elements));

    System.out.println(set.headSet("D"));
    System.out.println(set.tailSet(""));
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    String elements[] = { "java2s.com", "C", "D", "G", "F" };
    TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements));

    System.out.println(set.headSet("D"));
    System.out.println(set.tailSet(""));
}

From source file:Main.java

public static void main(String args[]) throws Exception {

    String elements[] = { "A", "C", "D", "G", "F" };
    TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements));

    System.out.println(set.headSet("D"));
    System.out.println(set.tailSet(""));
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    String elements[] = { "A", "C", "D", "G", "F" };
    TreeSet set = new TreeSet(Arrays.asList(elements));

    System.out.println(set.tailSet("C"));
    System.out.println(set.headSet("C"));
    System.out.println(set.headSet("C\0"));
    System.out.println(set.tailSet("C\0"));
    System.out.println(set.subSet("C", "F\0"));
    System.out.println(set.subSet("C", "C\0"));
    System.out.println(set.subSet("C", "C"));
}

From source file:Main.java

public static void main(String[] args) {
    TreeSet<String> tSet = new TreeSet<String>();
    tSet.add("1");
    tSet.add("2");
    tSet.add("3");
    tSet.add("4");
    tSet.add("5");
    SortedSet sortedSet = tSet.headSet("3");
    System.out.println("Head Set Contains : " + sortedSet);
}

From source file:Main.java

public static void main(String[] args) {
    TreeSet<Integer> tree = new TreeSet<Integer>();

    tree.add(12);//from   w w w  .  j  av a 2 s  . co m
    tree.add(13);
    tree.add(14);
    tree.add(15);
    tree.add(16);
    tree.add(17);

    // getting values less than 15
    TreeSet<Integer> treeheadset = (TreeSet) tree.headSet(15);

    Iterator<Integer> iterator = treeheadset.iterator();

    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}

From source file:org.apache.hadoop.hbase.zookeeper.lock.HReadLockImpl.java

/**
 * {@inheritDoc}/*from w ww  .  j a  v a 2  s .  c o  m*/
 */
@Override
protected String getLockPath(String createdZNode, List<String> children)
        throws IOException, InterruptedException {
    TreeSet<String> writeChildren = new TreeSet<String>(new ZNodeComparator(zkWrapper.getIdentifier()));
    for (String child : children) {
        if (isWriteChild(child)) {
            writeChildren.add(child);
        }
    }
    if (writeChildren.isEmpty()) {
        return null;
    }
    SortedSet<String> lowerChildren = writeChildren.headSet(createdZNode);
    if (lowerChildren.isEmpty()) {
        return null;
    }
    String pathToWatch = lowerChildren.last();
    String nodeHoldingLock = lowerChildren.first();
    try {
        handleLockMetadata(nodeHoldingLock);
    } catch (IOException e) {
        LOG.warn("Error processing lock metadata in " + nodeHoldingLock, e);
    }
    return pathToWatch;
}

From source file:org.apache.hadoop.hbase.zookeeper.lock.ZKInterProcessReadLock.java

/**
 * {@inheritDoc}//from  w  w  w  .j  av  a 2 s . co  m
 */
@Override
protected String getLockPath(String createdZNode, List<String> children) throws IOException {
    TreeSet<String> writeChildren = new TreeSet<String>(ZNodeComparator.COMPARATOR);
    for (String child : children) {
        if (isChildWriteLock(child)) {
            writeChildren.add(child);
        }
    }
    if (writeChildren.isEmpty()) {
        return null;
    }
    SortedSet<String> lowerChildren = writeChildren.headSet(createdZNode);
    if (lowerChildren.isEmpty()) {
        return null;
    }
    String pathToWatch = lowerChildren.last();
    String nodeHoldingLock = lowerChildren.first();
    String znode = ZKUtil.joinZNode(parentLockNode, nodeHoldingLock);
    handleLockMetadata(znode);

    return pathToWatch;
}

From source file:org.cloudata.core.commitlog.pipe.BufferPool.java

int clearExpiredEntries(int msec) {
    PoolEntry e = new PoolEntry((System.currentTimeMillis() + 10) - msec);
    int sizeOfDeallocated = 0;

    synchronized (bufferMap) {
        Iterator<TreeSet<PoolEntry>> iter = bufferMap.values().iterator();
        while (iter.hasNext()) {
            TreeSet<PoolEntry> entrySet = iter.next();
            SortedSet<PoolEntry> expiredSet = entrySet.headSet(e);

            if (expiredSet.isEmpty() == false) {
                LOG.debug(expiredSet.size() + " pool entries are removed");
                Iterator<PoolEntry> expiredIter = expiredSet.iterator();

                while (expiredIter.hasNext()) {
                    PoolEntry expiredEntry = expiredIter.next();
                    poolMonitor.deallocated(expiredEntry.buffer.capacity());
                    sizeOfDeallocated += expiredEntry.buffer.capacity();
                }//from w w w  .j av  a2s. c  o  m

                expiredSet.clear();

                if (entrySet.isEmpty()) {
                    LOG.debug("entry set is removed");
                    iter.remove();
                }
            }
        }
    }

    return sizeOfDeallocated;
}

From source file:org.hyperic.hq.measurement.server.session.AvailabilityManagerImpl.java

private AvailabilityDataRLE findAvailBefore(DataPoint state,
        Map<Integer, TreeSet<AvailabilityDataRLE>> currAvails) {
    Integer mId = state.getMeasurementId();
    TreeSet<AvailabilityDataRLE> rles = currAvails.get(mId);
    long start = state.getTimestamp();
    AvailabilityDataRLE tmp = new AvailabilityDataRLE();
    // headSet is inclusive so we need to subtract 1 from start
    tmp.setStartime(start - 1);//from  www.  ja  v  a2s  .  c o  m
    SortedSet<AvailabilityDataRLE> set = rles.headSet(tmp);
    if (set.size() == 0) {
        return null;
    }
    return set.last();
}