Java Code Examples for java.util.NavigableMap#descendingMap()
The following examples show how to use
java.util.NavigableMap#descendingMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaProjectPipelineOptionsHierarchy.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Override public NavigableMap<PipelineOptionsType, Set<PipelineOptionsProperty>> getOptionsHierarchy( String... typeNames) { NavigableMap<PipelineOptionsType, Set<PipelineOptionsProperty>> result = new TreeMap<>(new PipelineOptionsTypeWeightOrdering()); Queue<PipelineOptionsType> optionsTypesToAdd = new ArrayDeque<>(); for (String typeName : typeNames) { if (!Strings.isNullOrEmpty(typeName)) { PipelineOptionsType pipelineOptionsType = getPipelineOptionsType(typeName); if (pipelineOptionsType != null) { optionsTypesToAdd.add(pipelineOptionsType); } } } while (!optionsTypesToAdd.isEmpty()) { PipelineOptionsType type = optionsTypesToAdd.poll(); if (!result.containsKey(type)) { result.put(type, type.getDeclaredProperties()); optionsTypesToAdd.addAll(type.getDirectSuperInterfaces()); } } return result.descendingMap(); }
Example 2
Source File: VolumeReplicaGroup.java From sfs with Apache License 2.0 | 4 votes |
protected Observable<List<ConnectedVolume>> getVolumesForWrite(NavigableMap<Long, Set<String>> volumesBySpace, List<ConnectedVolume> toSkip, long requiredSpace, int numberToCollect, boolean allowSameNode, MessageDigestFactory... messageDigestFactories) { if (volumesBySpace != null && numberToCollect > 0) { NavigableMap<Long, Set<String>> descendingMap = volumesBySpace.descendingMap(); List<ConnectedVolume> results = new ArrayList<>(numberToCollect); Set<String> seenNodes = new HashSet<>(); Set<String> seenVolumes = new HashSet<>(); for (ConnectedVolume primaryTargetVolume : toSkip) { seenNodes.add(primaryTargetVolume.getNodeId()); seenVolumes.add(primaryTargetVolume.getVolumeId()); } if (excludeVolumes != null) { seenVolumes.addAll(excludeVolumes); } Vertx vertx = vertxContext.vertx(); return RxHelper.iterate(vertx, descendingMap.entrySet(), entry -> { long useableSpace = entry.getKey(); if (useableSpace * 0.90 >= requiredSpace) { Set<String> volumeIds = entry.getValue(); return RxHelper.iterate(vertx, volumeIds, volumeId -> { if (seenVolumes.add(volumeId)) { Optional<TransientServiceDef> oServiceDef = clusterInfo.getServiceDefForVolume(volumeId); if (oServiceDef.isPresent()) { TransientServiceDef serviceDef = oServiceDef.get(); Optional<XNode> oXNode = clusterInfo.getNodeForVolume(vertxContext, volumeId); if (oXNode.isPresent()) { XNode xNode = oXNode.get(); return xNode.createWriteStream(volumeId, requiredSpace, messageDigestFactories) .onErrorResumeNext(throwable -> { LOGGER.warn(String.format("Failed to connect to volume %s", volumeId), throwable); return Defer.just(null); }) .doOnNext(nodeWriteStreamBlob -> { if (nodeWriteStreamBlob != null) { ConnectedVolume connectedVolume = new ConnectedVolume(); connectedVolume.setxNode(xNode); connectedVolume.setVolumeId(volumeId); connectedVolume.setNodeId(serviceDef.getId()); connectedVolume.setNodeWriteStreamBlob(nodeWriteStreamBlob); if (allowSameNode || seenNodes.add(connectedVolume.getNodeId())) { results.add(connectedVolume); } } }) .map(nodeWriteStreamBlob -> { if (results.size() >= numberToCollect) { return false; } else { return true; } }); } else { return Defer.just(true); } } } return Defer.just(true); }); } else { return Defer.just(true); } }).map(aBoolean -> results); } return Defer.just(Collections.emptyList()); }