Java Code Examples for java.util.SortedSet.headSet()

The following are Jave code examples for showing how to use headSet() of the java.util.SortedSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sstore-soft   File: Sets.java   View Source Code Vote up 5 votes
@Override
public E last() {
  SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered;
  while (true) {
    E element = sortedUnfiltered.last();
    if (predicate.apply(element)) {
      return element;
    }
    sortedUnfiltered = sortedUnfiltered.headSet(element);
  }
}
 
Example 2
Project: guava-mock   File: Sets.java   View Source Code Vote up 5 votes
@Override
public E last() {
  SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered;
  while (true) {
    E element = sortedUnfiltered.last();
    if (predicate.apply(element)) {
      return element;
    }
    sortedUnfiltered = sortedUnfiltered.headSet(element);
  }
}
 
Example 3
Project: guava-mock   File: DerivedCollectionGenerators.java   View Source Code Vote up 5 votes
/**
 * Calls the smallest subSet overload that filters out the extreme values.
 */
SortedSet<E> createSubSet(SortedSet<E> set, E firstExclusive, E lastExclusive) {
  if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
    return set.headSet(lastExclusive);
  } else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
    return set.tailSet(firstInclusive);
  } else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
    return set.subSet(firstInclusive, lastExclusive);
  } else {
    throw new IllegalArgumentException();
  }
}
 
Example 4
Project: s-store   File: Sets.java   View Source Code Vote up 5 votes
@Override
public E last() {
  SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered;
  while (true) {
    E element = sortedUnfiltered.last();
    if (predicate.apply(element)) {
      return element;
    }
    sortedUnfiltered = sortedUnfiltered.headSet(element);
  }
}
 
Example 5
Project: Equella   File: PagesHandler.java   View Source Code Vote up 5 votes
public void versions(HttpExchange exchange) throws Exception
{
	SortedSet<WebVersion> allVersions = new Version(config).getVersions();
	WebVersion deployedVersion = new Version(config).getDeployedVersion();

	Set<WebVersion> newer = allVersions.headSet(deployedVersion);
	Set<WebVersion> older = allVersions.tailSet(deployedVersion);
	older.remove(deployedVersion);

	StringTemplate st = templates.getInstanceOf("templates/versions");
	st.setAttribute("newer", newer);
	st.setAttribute("older", older);
	st.setAttribute("current", Collections.singleton(deployedVersion));
	HttpExchangeUtils.respondHtmlMessage(exchange, 200, st.toString());
}
 
Example 6
Project: googles-monorepo-demo   File: Sets.java   View Source Code Vote up 5 votes
@Override
public E last() {
  SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered;
  while (true) {
    E element = sortedUnfiltered.last();
    if (predicate.apply(element)) {
      return element;
    }
    sortedUnfiltered = sortedUnfiltered.headSet(element);
  }
}
 
Example 7
Project: googles-monorepo-demo   File: DerivedCollectionGenerators.java   View Source Code Vote up 5 votes
/**
 * Calls the smallest subSet overload that filters out the extreme values.
 */
SortedSet<E> createSubSet(SortedSet<E> set, E firstExclusive, E lastExclusive) {
  if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
    return set.headSet(lastExclusive);
  } else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
    return set.tailSet(firstInclusive);
  } else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
    return set.subSet(firstInclusive, lastExclusive);
  } else {
    throw new IllegalArgumentException();
  }
}
 
Example 8
Project: ditb   File: ReplicationSourceManager.java   View Source Code Vote up 5 votes
private void cleanOldLogs(SortedSet<String> wals, String key, String id) {
  SortedSet<String> walSet = wals.headSet(key);
  LOG.debug("Removing " + walSet.size() + " logs in the list: " + walSet);
  for (String wal : walSet) {
    this.replicationQueues.removeLog(id, wal);
  }
  walSet.clear();
}
 
Example 9
Project: fuck_zookeeper   File: WriteLock.java   View Source Code Vote up 4 votes
/**
 * the command that is run and retried for actually 
 * obtaining the lock
 * @return if the command was successful or not
 */
public boolean execute() throws KeeperException, InterruptedException {
    do {
        if (id == null) {
            long sessionId = zookeeper.getSessionId();
            String prefix = "x-" + sessionId + "-";
            // lets try look up the current ID if we failed 
            // in the middle of creating the znode
            findPrefixInChildren(prefix, zookeeper, dir);
            idName = new ZNodeName(id);
        }
        if (id != null) {
            List<String> names = zookeeper.getChildren(dir, false);
            if (names.isEmpty()) {
                LOG.warn("No children in: " + dir + " when we've just " +
                "created one! Lets recreate it...");
                // lets force the recreation of the id
                id = null;
            } else {
                // lets sort them explicitly (though they do seem to come back in order ususally :)
                SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
                for (String name : names) {
                    sortedNames.add(new ZNodeName(dir + "/" + name));
                }
                ownerId = sortedNames.first().getName();
                SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
                if (!lessThanMe.isEmpty()) {
                    ZNodeName lastChildName = lessThanMe.last();
                    lastChildId = lastChildName.getName();
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("watching less than me node: " + lastChildId);
                    }
                    Stat stat = zookeeper.exists(lastChildId, new LockWatcher());
                    if (stat != null) {
                        return Boolean.FALSE;
                    } else {
                        LOG.warn("Could not find the" +
                        		" stats for less than me: " + lastChildName.getName());
                    }
                } else {
                    if (isOwner()) {
                        if (callback != null) {
                            callback.lockAcquired();
                        }
                        return Boolean.TRUE;
                    }
                }
            }
        }
    }
    while (id == null);
    return Boolean.FALSE;
}
 
Example 10
Project: guava-mock   File: ImmutableSortedSetTest.java   View Source Code Vote up 4 votes
public void testCopyOf_headSet() {
  SortedSet<String> set = of("e", "a", "f", "b", "d", "c");
  SortedSet<String> headset = set.headSet("d");
  SortedSet<String> copy = copyOf(headset);
  assertEquals(headset, copy);
}
 
Example 11
Project: https-github.com-apache-zookeeper   File: WriteLock.java   View Source Code Vote up 4 votes
/**
 * the command that is run and retried for actually 
 * obtaining the lock
 * @return if the command was successful or not
 */
public boolean execute() throws KeeperException, InterruptedException {
    do {
        if (id == null) {
            long sessionId = zookeeper.getSessionId();
            String prefix = "x-" + sessionId + "-";
            // lets try look up the current ID if we failed 
            // in the middle of creating the znode
            findPrefixInChildren(prefix, zookeeper, dir);
            idName = new ZNodeName(id);
        }
        if (id != null) {
            List<String> names = zookeeper.getChildren(dir, false);
            if (names.isEmpty()) {
                LOG.warn("No children in: " + dir + " when we've just " +
                "created one! Lets recreate it...");
                // lets force the recreation of the id
                id = null;
            } else {
                // lets sort them explicitly (though they do seem to come back in order ususally :)
                SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
                for (String name : names) {
                    sortedNames.add(new ZNodeName(dir + "/" + name));
                }
                ownerId = sortedNames.first().getName();
                SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
                if (!lessThanMe.isEmpty()) {
                    ZNodeName lastChildName = lessThanMe.last();
                    lastChildId = lastChildName.getName();
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("watching less than me node: " + lastChildId);
                    }
                    Stat stat = zookeeper.exists(lastChildId, new LockWatcher());
                    if (stat != null) {
                        return Boolean.FALSE;
                    } else {
                        LOG.warn("Could not find the" +
                        		" stats for less than me: " + lastChildName.getName());
                    }
                } else {
                    if (isOwner()) {
                        if (callback != null) {
                            callback.lockAcquired();
                        }
                        return Boolean.TRUE;
                    }
                }
            }
        }
    }
    while (id == null);
    return Boolean.FALSE;
}
 
Example 12
Project: ZooKeeper   File: WriteLock.java   View Source Code Vote up 4 votes
/**
 * the command that is run and retried for actually 
 * obtaining the lock
 * @return if the command was successful or not
 */
public boolean execute() throws KeeperException, InterruptedException {
    do {
        if (id == null) {
            long sessionId = zookeeper.getSessionId();
            String prefix = "x-" + sessionId + "-";
            // lets try look up the current ID if we failed 
            // in the middle of creating the znode
            findPrefixInChildren(prefix, zookeeper, dir);
            idName = new ZNodeName(id);
        }
        if (id != null) {
            List<String> names = zookeeper.getChildren(dir, false);
            if (names.isEmpty()) {
                LOG.warn("No children in: " + dir + " when we've just " +
                "created one! Lets recreate it...");
                // lets force the recreation of the id
                id = null;
            } else {
                // lets sort them explicitly (though they do seem to come back in order ususally :)
                SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
                for (String name : names) {
                    sortedNames.add(new ZNodeName(dir + "/" + name));
                }
                ownerId = sortedNames.first().getName();
                SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
                if (!lessThanMe.isEmpty()) {
                    ZNodeName lastChildName = lessThanMe.last();
                    lastChildId = lastChildName.getName();
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("watching less than me node: " + lastChildId);
                    }
                    Stat stat = zookeeper.exists(lastChildId, new LockWatcher());
                    if (stat != null) {
                        return Boolean.FALSE;
                    } else {
                        LOG.warn("Could not find the" +
                        		" stats for less than me: " + lastChildName.getName());
                    }
                } else {
                    if (isOwner()) {
                        if (callback != null) {
                            callback.lockAcquired();
                        }
                        return Boolean.TRUE;
                    }
                }
            }
        }
    }
    while (id == null);
    return Boolean.FALSE;
}
 
Example 13
Project: ZooKeeper   File: WriteLock.java   View Source Code Vote up 4 votes
/**
 * the command that is run and retried for actually 
 * obtaining the lock
 * @return if the command was successful or not
 */
public boolean execute() throws KeeperException, InterruptedException {
    do {
        if (id == null) {
            long sessionId = zookeeper.getSessionId();
            String prefix = "x-" + sessionId + "-";
            // lets try look up the current ID if we failed 
            // in the middle of creating the znode
            findPrefixInChildren(prefix, zookeeper, dir);
            idName = new ZNodeName(id);
        }
        if (id != null) {
            List<String> names = zookeeper.getChildren(dir, false);
            if (names.isEmpty()) {
                LOG.warn("No children in: " + dir + " when we've just " +
                "created one! Lets recreate it...");
                // lets force the recreation of the id
                id = null;
            } else {
                // lets sort them explicitly (though they do seem to come back in order ususally :)
                SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
                for (String name : names) {
                    sortedNames.add(new ZNodeName(dir + "/" + name));
                }
                ownerId = sortedNames.first().getName();
                SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
                if (!lessThanMe.isEmpty()) {
                    ZNodeName lastChildName = lessThanMe.last();
                    lastChildId = lastChildName.getName();
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("watching less than me node: " + lastChildId);
                    }
                    Stat stat = zookeeper.exists(lastChildId, new LockWatcher());
                    if (stat != null) {
                        return Boolean.FALSE;
                    } else {
                        LOG.warn("Could not find the" +
                        		" stats for less than me: " + lastChildName.getName());
                    }
                } else {
                    if (isOwner()) {
                        if (callback != null) {
                            callback.lockAcquired();
                        }
                        return Boolean.TRUE;
                    }
                }
            }
        }
    }
    while (id == null);
    return Boolean.FALSE;
}
 
Example 14
Project: googles-monorepo-demo   File: ImmutableSortedSetTest.java   View Source Code Vote up 4 votes
public void testCopyOf_headSet() {
  SortedSet<String> set = of("e", "a", "f", "b", "d", "c");
  SortedSet<String> headset = set.headSet("d");
  SortedSet<String> copy = copyOf(headset);
  assertEquals(headset, copy);
}