List of usage examples for java.util Collections emptySortedSet
@SuppressWarnings("unchecked") public static <E> SortedSet<E> emptySortedSet()
From source file:ddf.security.impl.SubjectIdentityImpl.java
private SortedSet<String> getSubjectAttribute(Subject subject) { Map<String, SortedSet<String>> attrs = SubjectUtils.getSubjectAttributes(subject); if (attrs.containsKey(identityAttribute)) { return attrs.get(identityAttribute); }//w w w. j a v a 2 s . c o m return Collections.emptySortedSet(); }
From source file:org.apache.hadoop.hbase.replication.ZKReplicationQueueStorage.java
@Override public Pair<String, SortedSet<String>> claimQueue(ServerName sourceServerName, String queueId, ServerName destServerName) throws ReplicationException { LOG.info("Atomically moving {}/{}'s WALs to {}", sourceServerName, queueId, destServerName); try {// w ww .j a v a 2s . co m ZKUtil.createWithParents(zookeeper, getRsNode(destServerName)); } catch (KeeperException e) { throw new ReplicationException("Claim queue queueId=" + queueId + " from " + sourceServerName + " to " + destServerName + " failed when creating the node for " + destServerName, e); } String newQueueId = queueId + "-" + sourceServerName; try { String oldQueueNode = getQueueNode(sourceServerName, queueId); List<String> wals = ZKUtil.listChildrenNoWatch(zookeeper, oldQueueNode); if (CollectionUtils.isEmpty(wals)) { ZKUtil.deleteNodeFailSilent(zookeeper, oldQueueNode); LOG.info("Removed empty {}/{}", sourceServerName, queueId); return new Pair<>(newQueueId, Collections.emptySortedSet()); } String newQueueNode = getQueueNode(destServerName, newQueueId); List<ZKUtilOp> listOfOps = new ArrayList<>(); SortedSet<String> logQueue = new TreeSet<>(); // create the new cluster znode listOfOps.add(ZKUtilOp.createAndFailSilent(newQueueNode, HConstants.EMPTY_BYTE_ARRAY)); // get the offset of the logs and set it to new znodes for (String wal : wals) { String oldWalNode = getFileNode(oldQueueNode, wal); byte[] logOffset = ZKUtil.getData(this.zookeeper, oldWalNode); LOG.debug("Creating {} with data {}", wal, Bytes.toStringBinary(logOffset)); String newWalNode = getFileNode(newQueueNode, wal); listOfOps.add(ZKUtilOp.createAndFailSilent(newWalNode, logOffset)); listOfOps.add(ZKUtilOp.deleteNodeFailSilent(oldWalNode)); logQueue.add(wal); } // add delete op for peer listOfOps.add(ZKUtilOp.deleteNodeFailSilent(oldQueueNode)); LOG.trace("The multi list size is {}", listOfOps.size()); ZKUtil.multiOrSequential(zookeeper, listOfOps, false); LOG.info("Atomically moved {}/{}'s WALs to {}", sourceServerName, queueId, destServerName); return new Pair<>(newQueueId, logQueue); } catch (NoNodeException | NodeExistsException | NotEmptyException | BadVersionException e) { // Multi call failed; it looks like some other regionserver took away the logs. // These exceptions mean that zk tells us the request can not be execute. So return an empty // queue to tell the upper layer that claim nothing. For other types of exception should be // thrown out to notify the upper layer. LOG.info("Claim queue queueId={} from {} to {} failed with {}, someone else took the log?", queueId, sourceServerName, destServerName, e.toString()); return new Pair<>(newQueueId, Collections.emptySortedSet()); } catch (KeeperException | InterruptedException e) { throw new ReplicationException("Claim queue queueId=" + queueId + " from " + sourceServerName + " to " + destServerName + " failed", e); } }
From source file:org.eclipse.sw360.licenseinfo.outputGenerators.OutputGenerator.java
/** * Helper function to sort a set by the given key extractor. Falls back to the * unsorted set if sorting the set would squash values. * * @param unsorted/*from w w w . j a v a 2s. com*/ * set to be sorted * @param keyExtractor * function to extract the key to use for sorting * * @return the sorted set */ private static <U, K extends Comparable<K>> SortedSet<U> sortSet(Set<U> unsorted, Function<U, K> keyExtractor) { if (unsorted == null || unsorted.isEmpty()) { return Collections.emptySortedSet(); } SortedSet<U> sorted = new TreeSet<>(Comparator.comparing(keyExtractor)); sorted.addAll(unsorted); if (sorted.size() != unsorted.size()) { // there were key collisions and some data was lost -> throw away the sorted set // and sort by U's natural order sorted = new TreeSet<>(); sorted.addAll(unsorted); } return sorted; }
From source file:org.hippoecm.frontend.editor.workflow.model.ReferringDocumentsProvider.java
static SortedSet<Node> getReferrersSortedByName(Node handle, final boolean retrieveUnpublished, final int resultMaxCount) throws RepositoryException { if (handle.isNodeType(HippoNodeType.NT_DOCUMENT)) { handle = handle.getParent();//from www . jav a 2s. c o m } if (!handle.isNodeType(HippoNodeType.NT_HANDLE)) { return Collections.emptySortedSet(); } final Map<String, Node> referrers = new HashMap<>(); final String uuid = handle.getIdentifier(); final String requiredAvailability; if (retrieveUnpublished) { requiredAvailability = "preview"; } else { requiredAvailability = "live"; } StringBuilder queryBuilder = new StringBuilder("//element(*,hippo:facetselect)[@hippo:docbase='") .append(uuid).append("']"); addReferrers(handle, requiredAvailability, resultMaxCount, queryBuilder.toString(), referrers); queryBuilder = new StringBuilder("//element(*,hippo:mirror)[@hippo:docbase='").append(uuid).append("']"); addReferrers(handle, requiredAvailability, resultMaxCount, queryBuilder.toString(), referrers); return getSortedReferrers(referrers.values()); }