List of usage examples for java.util SortedSet isEmpty
boolean isEmpty();
From source file:org.apache.hadoop.hbase.regionserver.SegmentScanner.java
/** * Seek the scanner at the first Cell of the row which is the previous row * of specified key//from w w w . j ava2 s . co m * * @param cell seek value * @return true if the scanner at the first valid Cell of previous row, * false if not existing such Cell */ @Override public boolean seekToPreviousRow(Cell cell) throws IOException { if (closed) { return false; } boolean keepSeeking; Cell key = cell; do { Cell firstKeyOnRow = PrivateCellUtil.createFirstOnRow(key); SortedSet<Cell> cellHead = segment.headSet(firstKeyOnRow); Cell lastCellBeforeRow = cellHead.isEmpty() ? null : cellHead.last(); if (lastCellBeforeRow == null) { current = null; return false; } Cell firstKeyOnPreviousRow = PrivateCellUtil.createFirstOnRow(lastCellBeforeRow); this.stopSkippingKVsIfNextRow = true; this.stopSkippingKVsRow = firstKeyOnPreviousRow; seek(firstKeyOnPreviousRow); this.stopSkippingKVsIfNextRow = false; if (peek() == null || segment.getComparator().compareRows(peek(), firstKeyOnPreviousRow) > 0) { keepSeeking = true; key = firstKeyOnPreviousRow; continue; } else { keepSeeking = false; } } while (keepSeeking); return true; }
From source file:com.alibaba.otter.shared.arbitrate.impl.zookeeper.lock.DistributedLock.java
/** * lock??watch????lock?//from ww w . j a va 2 s .c om */ private Boolean acquireLock(final BooleanMutex mutex) { try { do { if (id == null) {// ?lock long sessionId = getSessionId(); String prefix = "x-" + sessionId + "-"; // String path = zookeeper.create(root + "/" + prefix, data, CreateMode.EPHEMERAL_SEQUENTIAL); int index = path.lastIndexOf("/"); id = StringUtils.substring(path, index + 1); idName = new LockNode(id); } if (id != null) { List<String> names = zookeeper.getChildren(root); if (names.isEmpty()) { logger.warn("lock lost with scene:empty list, id[] and node[]", id, idName); unlock();// ?? } else { // ? SortedSet<LockNode> sortedNames = new TreeSet<LockNode>(); for (String name : names) { sortedNames.add(new LockNode(name)); } if (sortedNames.contains(idName) == false) { logger.warn("lock lost with scene:not contains ,id[] and node[]", id, idName); unlock();// ?? continue; } // ?ownerId ownerId = sortedNames.first().getName(); if (mutex != null && isOwner()) { mutex.set(true);// ? return true; } else if (mutex == null) { return isOwner(); } SortedSet<LockNode> lessThanMe = sortedNames.headSet(idName); if (!lessThanMe.isEmpty()) { // ? LockNode lastChildName = lessThanMe.last(); lastChildId = lastChildName.getName(); // watcher? IZkConnection connection = zookeeper.getConnection(); // zkclient?zk?lock??watcher?zk? ZooKeeper orginZk = ((ZooKeeperx) connection).getZookeeper(); Stat stat = orginZk.exists(root + "/" + lastChildId, new AsyncWatcher() { public void asyncProcess(WatchedEvent event) { if (!mutex.state()) { // ?????lock acquireLock(mutex); } else { logger.warn("locked successful."); } } }); if (stat == null) { acquireLock(mutex);// ????watcher? } } else { if (isOwner()) { mutex.set(true); } else { logger.warn("lock lost with scene:no less ,id[] and node[]", id, idName); unlock();// ?idownerId?? } } } } } while (id == null); } catch (KeeperException e) { exception = e; if (mutex != null) { mutex.set(true); } } catch (InterruptedException e) { interrupt = e; if (mutex != null) { mutex.set(true); } } catch (Throwable e) { other = e; if (mutex != null) { mutex.set(true); } } if (isOwner() && mutex != null) { mutex.set(true); } return Boolean.FALSE; }
From source file:com.sap.research.connectivity.gw.GwOperationsImpl.java
public boolean isCommandGWEntityAvailable() { SortedSet<FileDetails> files = fileManager .findMatchingAntPath(getSubPackagePath(oDataFolder) + SEPARATOR + "*_metadata.xml"); return !files.isEmpty(); }
From source file:co.rsk.peg.BridgeStorageProviderTest.java
@Test public void createSaveAndRecreateInstance() throws IOException { Repository repository = new RepositoryImpl(); Repository track = repository.startTracking(); BridgeStorageProvider provider0 = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); provider0.getBtcTxHashesAlreadyProcessed(); provider0.getRskTxsWaitingForBroadcasting(); provider0.getRskTxsWaitingForConfirmations(); provider0.getRskTxsWaitingForSignatures(); provider0.getBtcUTXOs();//from w w w.j a v a 2 s . c o m provider0.save(); track.commit(); track = repository.startTracking(); byte[] contractAddress = Hex.decode(PrecompiledContracts.BRIDGE_ADDR); Assert.assertNotNull(repository.getContractDetails(contractAddress)); Assert.assertNotNull(repository.getStorageBytes(contractAddress, new DataWord("btcTxHashesAP".getBytes()))); Assert.assertNotNull( repository.getStorageBytes(contractAddress, new DataWord("rskTxsWaitingFC".getBytes()))); Assert.assertNotNull( repository.getStorageBytes(contractAddress, new DataWord("rskTxsWaitingFS".getBytes()))); Assert.assertNotNull( repository.getStorageBytes(contractAddress, new DataWord("rskTxsWaitingFB".getBytes()))); Assert.assertNotNull(repository.getStorageBytes(contractAddress, new DataWord("btcUTXOs".getBytes()))); BridgeStorageProvider provider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR); SortedSet<Sha256Hash> processed = provider.getBtcTxHashesAlreadyProcessed(); Assert.assertNotNull(processed); Assert.assertTrue(processed.isEmpty()); SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> broadcasting = provider.getRskTxsWaitingForBroadcasting(); Assert.assertNotNull(broadcasting); Assert.assertTrue(broadcasting.isEmpty()); SortedMap<Sha3Hash, BtcTransaction> confirmations = provider.getRskTxsWaitingForConfirmations(); Assert.assertNotNull(confirmations); Assert.assertTrue(confirmations.isEmpty()); SortedMap<Sha3Hash, BtcTransaction> signatures = provider.getRskTxsWaitingForSignatures(); Assert.assertNotNull(signatures); Assert.assertTrue(signatures.isEmpty()); List<UTXO> utxos = provider.getBtcUTXOs(); Assert.assertNotNull(utxos); Assert.assertTrue(utxos.isEmpty()); Wallet wallet = provider.getWallet(); Assert.assertNotNull(wallet); Assert.assertNotNull(wallet.getCoinSelector()); }
From source file:org.isatools.tablib.export.graph2tab.LayersBuilder.java
/** * Set the layer for a node, which means all the two internal structures used for that are updated. * //from www . j a v a 2 s .co m */ private void setLayer(Node node, int layer) { // Remove from the old layer Integer oldLayer = node2Layer.get(node); if (oldLayer != null) { SortedSet<Node> oldLayerNodes = layer2Nodes.get(oldLayer); if (oldLayerNodes.remove(node) && oldLayerNodes.isEmpty() && oldLayer == maxLayer) maxLayer--; } // Add to the new layer SortedSet<Node> lnodes = layer2Nodes.get(layer); if (lnodes == null) { lnodes = new TreeSet<Node>(); layer2Nodes.put(layer, lnodes); } lnodes.add(node); node2Layer.put(node, layer); if (layer > maxLayer) maxLayer = layer; }
From source file:com.sap.research.connectivity.gw.GwOperationsImpl.java
public boolean isCommandGWMVCAdaptCommandAvailable() throws IOException { /*//from ww w . j a v a 2 s . com * We check first to see if there is a gateway entity available. If so, we check if there are any generated controllers. */ boolean returnResults = false; if (isCommandGWFieldAvailable() == true) { SortedSet<FileDetails> files = fileManager .findMatchingAntPath(getSubPackagePath(web) + SEPARATOR + "*Controller.java"); if (!files.isEmpty()) returnResults = true; } return returnResults; }
From source file:org.kalypso.model.wspm.ui.profil.wizard.createDivider.CreateDividerOperation.java
private Integer[] mixExistingWithIntersectionPoint(final IProfile profil, final Integer intersectionIndex) { final Integer[] markerPoints = existingMarkersAsIndices(profil); final SortedSet<Integer> markerIndices = new TreeSet<>(Arrays.asList(markerPoints)); // depends on the side of the profile! final IProfileRecord lowestPoint = ProfileVisitors.findLowestPoint(profil); if (Objects.isNull(lowestPoint)) return new Integer[] { intersectionIndex }; final Collection<Integer> result = new ArrayList<>(2); result.add(intersectionIndex);// w w w .ja v a2 s . co m if (intersectionIndex > lowestPoint.getIndex()) { // use leftmost of all left markers final SortedSet<Integer> leftSet = markerIndices.headSet(lowestPoint.getIndex()); if (!leftSet.isEmpty()) { result.add(leftSet.first()); } } else { // use leftmost of all left markers final SortedSet<Integer> rightSet = markerIndices.tailSet(lowestPoint.getIndex()); if (!rightSet.isEmpty()) { result.add(rightSet.last()); } } return result.toArray(new Integer[result.size()]); }
From source file:org.apache.nifi.registry.web.api.ExtensionRepositoryResource.java
@GET @Path("{groupId}/{artifactId}/{version}/sha256") @Consumes(MediaType.WILDCARD)//from w w w .j av a 2 s . c o m @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Gets the hex representation of the SHA-256 digest for the binary content of the version of the extension bundle. Since the " + "same group-artifact-version can exist in multiple buckets, this will return the checksum of the first one returned. This will be " + "consistent since the checksum must be the same when existing in multiple buckets.", response = String.class) @ApiResponses({ @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400), @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401), @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403), @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404), @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) }) public Response getExtensionBundleVersionSha256( @PathParam("groupId") @ApiParam("The group identifier") final String groupId, @PathParam("artifactId") @ApiParam("The artifact identifier") final String artifactId, @PathParam("version") @ApiParam("The version") final String version) { final Set<String> authorizedBucketIds = getAuthorizedBucketIds(RequestAction.READ); if (authorizedBucketIds == null || authorizedBucketIds.isEmpty()) { // not authorized for any bucket, return empty list of items return Response.status(Response.Status.OK).entity(new ArrayList<>()).build(); } // Since we are using the filter params which are optional in the service layer, we need to validate these path params here if (StringUtils.isBlank(groupId)) { throw new IllegalArgumentException("Group id cannot be null or blank"); } if (StringUtils.isBlank(artifactId)) { throw new IllegalArgumentException("Artifact id cannot be null or blank"); } if (StringUtils.isBlank(version)) { throw new IllegalArgumentException("Version cannot be null or blank"); } final ExtensionBundleVersionFilterParams filterParams = ExtensionBundleVersionFilterParams.of(groupId, artifactId, version); final SortedSet<ExtensionBundleVersionMetadata> bundleVersions = registryService .getExtensionBundleVersions(authorizedBucketIds, filterParams); if (bundleVersions.isEmpty()) { throw new ResourceNotFoundException( "An extension bundle version does not exist with the specific group, artifact, and version"); } else { ExtensionBundleVersionMetadata latestVersionMetadata = null; for (ExtensionBundleVersionMetadata versionMetadata : bundleVersions) { if (latestVersionMetadata == null || versionMetadata.getTimestamp() > latestVersionMetadata.getTimestamp()) { latestVersionMetadata = versionMetadata; } } return Response.ok(latestVersionMetadata.getSha256(), MediaType.TEXT_PLAIN).build(); } }
From source file:com.spotify.heroic.filter.impl.OrFilterImpl.java
private static Filter optimize(SortedSet<Filter> statements) { final SortedSet<Filter> result = new TreeSet<>(); root: for (final Filter f : statements) { if (f instanceof Filter.Not) { final Filter.Not not = (Filter.Not) f; if (statements.contains(not.first())) { return TrueFilterImpl.get(); }//from ww w . j a v a2 s . c o m result.add(f); continue; } if (f instanceof Filter.StartsWith) { final Filter.StartsWith outer = (Filter.StartsWith) f; for (final Filter inner : statements) { if (inner.equals(outer)) { continue; } if (inner instanceof Filter.StartsWith) { final Filter.StartsWith starts = (Filter.StartsWith) inner; if (!outer.first().equals(starts.first())) { continue; } if (FilterComparatorUtils.prefixedWith(outer.second(), starts.second())) { continue root; } } } result.add(f); continue; } // all ok! result.add(f); } if (result.isEmpty()) { return TrueFilterImpl.get(); } if (result.size() == 1) { return result.iterator().next(); } return new OrFilterImpl(new ArrayList<>(result)); }
From source file:org.mousephenotype.dcc.crawler.Downloader.java
private void downloadFiles() throws InterruptedException { ExecutorService workers = Executors.newFixedThreadPool(poolSize); while (true) { SortedSet<FileSourceHasZip> f = getActionAndSources(); if (f == null || f.isEmpty()) { logger.info("No download pending; downloader will now exit"); break; } else {/* w ww .j a v a 2 s.c om*/ ZipDownload zd = attemptDownload(f); if (zd != null) { logger.debug("Successfully downloaded '{}'... will now extract contents", zd.getZfId().getZaId().getZipId().getFileName()); workers.submit(new XmlExtractor(backupDir, zd)); } } } workers.shutdown(); workers.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); }