public final int nextClear(int index) { return super.nextClearBit(index); }
@SuppressWarnings("WeakerAccess") protected int allocateShapeId() { final int nextId = shapeIds.nextClearBit(1); shapeIds.set(nextId); return nextId; }
public boolean hasLowHighSurrogates() { return altSurrogates ? lowHighSurrogates.nextClearBit(0) < SURROGATE_CARDINALITY : lowHighSurrogates .nextSetBit(0) < SURROGATE_CARDINALITY; }
/** * Get the position of the first free space. * * @return the position. */ public long getFirstFree() { return getPos(set.nextClearBit(0)); }
private static void assertAllIdsOccupied( long highId, BitSet seenIds ) { long expectedNumberOfPages = highId - IdSpace.MIN_TREE_NODE_ID; if ( seenIds.cardinality() != expectedNumberOfPages ) { StringBuilder builder = new StringBuilder( "[" ); int index = (int) IdSpace.MIN_TREE_NODE_ID; int count = 0; while ( index >= 0 && index < highId ) { index = seenIds.nextClearBit( index ); if ( index != -1 ) { if ( count++ > 0 ) { builder.append( "," ); } builder.append( index ); index++; } } builder.append( "]" ); throw new RuntimeException( "There are " + count + " unused pages in the store:" + builder ); } }
/** * Checks that all the required props are supplied, and if not throws a useful exception * * @param requiredPropsCount expected number of props * @param required the bit set that identifies which props have been supplied * @param requiredPropsNames the names of all props used for a useful error message */ protected static void checkArgs( int requiredPropsCount, BitSet required, String[] requiredPropsNames) { if (required != null && required.nextClearBit(0) < requiredPropsCount) { List<String> missingProps = new ArrayList<>(); for (int i = 0; i < requiredPropsCount; i++) { if (!required.get(i)) { missingProps.add(requiredPropsNames[i]); } } throw new IllegalStateException( "The following props are not marked as optional and were not supplied: " + Arrays.toString(missingProps.toArray())); } }
/** * Checks that all the required props are supplied, and if not throws a useful exception * * @param requiredPropsCount expected number of props * @param required the bit set that identifies which props have been supplied * @param requiredPropsNames the names of all props used for a useful error message */ protected static void checkArgs( int requiredPropsCount, BitSet required, String[] requiredPropsNames) { if (required != null && required.nextClearBit(0) < requiredPropsCount) { List<String> missingProps = new ArrayList<>(); for (int i = 0; i < requiredPropsCount; i++) { if (!required.get(i)) { missingProps.add(requiredPropsNames[i]); } } throw new IllegalStateException( "The following props are not marked as optional and were not supplied: " + Arrays.toString(missingProps.toArray())); } } }
/** * Finds the next available (1 based) drawing group id * * @return the next available drawing group id */ public short findNewDrawingGroupId() { BitSet bs = new BitSet(); bs.set(0); for (FileIdCluster fic : field_5_fileIdClusters) { bs.set(fic.getDrawingGroupId()); } return (short)bs.nextClearBit(0); }
destIndex += count; srcIndex = indices.nextClearBit(set);
/** * @param commState Node communication state. * @param initialNodes Topology snapshot when communication error resolve started. * @param top Current topology. * @return {@code True} if node has connection to all alive nodes. */ private boolean checkFullyConnected(BitSet commState, List<ClusterNode> initialNodes, ZkClusterNodes top) { int startIdx = 0; for (;;) { int idx = commState.nextClearBit(startIdx); if (idx >= initialNodes.size()) return true; ClusterNode node = initialNodes.get(idx); if (top.nodesById.containsKey(node.id())) return false; startIdx = idx + 1; } }
/** * Allocate a number of blocks and mark them as used. * * @param length the number of bytes to allocate * @return the start position in bytes */ public long allocate(int length) { int blocks = getBlockCount(length); for (int i = 0;;) { int start = set.nextClearBit(i); int end = set.nextSetBit(start + 1); if (end < 0 || end - start >= blocks) { set.set(start, start + blocks); return getPos(start); } i = end; } }
if (needRemove || pos.nextClearBit(0) < arrayObject.size || pos.nextSetBit(arrayObject.size) >= 0) { it.remove();
private List<T> toList(BitSet bits, int base) { final int len = bits.cardinality(); switch (len) { case 0: return emptyList(); case 1: return singletonList(map.getObject((base - 1) + bits.length())); default: List<T> elements = new ArrayList<T>(len); int i = bits.nextSetBit(0); do { int endOfRun = bits.nextClearBit(i + 1); do { elements.add(map.getObject(base + i++)); } while (i < endOfRun); i = bits.nextSetBit(i + 1); } while (i >= 0); return elements; } }
@Override public void invoke(Integer value) throws Exception { numElements++; if (duplicateChecker.get(value)) { throw new Exception("Received a duplicate: " + value); } duplicateChecker.set(value); if (numElements == numElementsTotal) { // validate if (duplicateChecker.cardinality() != numElementsTotal) { throw new Exception("Duplicate checker has wrong cardinality"); } else if (duplicateChecker.nextClearBit(0) != numElementsTotal) { throw new Exception("Received sparse sequence"); } else { throw new SuccessException(); } } }
/** * Begin a new transaction. * * @return the transaction */ public synchronized Transaction begin() { int transactionId; int status; if (!init) { throw DataUtils.newIllegalStateException( DataUtils.ERROR_TRANSACTION_ILLEGAL_STATE, "Not initialized"); } transactionId = openTransactions.nextClearBit(1); if (transactionId > maxTransactionId) { throw DataUtils.newIllegalStateException( DataUtils.ERROR_TOO_MANY_OPEN_TRANSACTIONS, "There are {0} open transactions", transactionId - 1); } openTransactions.set(transactionId); status = Transaction.STATUS_OPEN; return new Transaction(this, transactionId, status, null, 0); }
@Override public void flatMap(Tuple2<Integer, Integer> value, Collector<Integer> out) throws Exception { int partition = value.f0; int val = value.f1; BitSet bitSet = partitionsToValueCheck.get(partition); if (bitSet == null) { throw new RuntimeException("Got a record from an unknown partition"); } else { bitSet.set(val - partitionsToValuesCountAndStartOffset.get(partition).f1); } count++; LOG.info("Received message {}, total {} messages", value, count); // verify if we've seen everything if (count == finalCount) { for (Map.Entry<Integer, BitSet> partitionsToValueCheck : this.partitionsToValueCheck.entrySet()) { BitSet check = partitionsToValueCheck.getValue(); int expectedValueCount = partitionsToValuesCountAndStartOffset.get(partitionsToValueCheck.getKey()).f0; if (check.cardinality() != expectedValueCount) { throw new RuntimeException("Expected cardinality to be " + expectedValueCount + ", but was " + check.cardinality()); } else if (check.nextClearBit(0) != expectedValueCount) { throw new RuntimeException("Expected next clear bit to be " + expectedValueCount + ", but was " + check.cardinality()); } } // test has passed throw new SuccessException(); } }
@Override public void invoke(Tuple2<Long, String> value) throws Exception { String[] sp = value.f1.split("-"); int v = Integer.parseInt(sp[1]); assertEquals(value.f0 - 1000, (long) v); assertFalse("Received tuple twice", validator.get(v)); validator.set(v); elCnt++; if (elCnt == totalElements) { // check if everything in the bitset is set to true int nc; if ((nc = validator.nextClearBit(0)) != totalElements) { fail("The bitset was not set to 1 on all elements. Next clear:" + nc + " Set: " + validator); } throw new SuccessException(); } }
private void fetchAndValidateRows( List<Partition> partitions, BatchTransactionId txnID, BitSet seenRows) { for (Partition p : partitions) { BatchReadOnlyTransaction batchTxnOnEachWorker = client.batchReadOnlyTransaction(txnID); try (ResultSet result = batchTxnOnEachWorker.execute(p)) { // validate no duplicate rows; verify all columns read. validate(result, seenRows); } } // verify all rows were read from the database. assertThat(seenRows.nextClearBit(0)).isEqualTo(numRows); }
for (int ix = 0; (ix = _paramsSeenBig.nextClearBit(ix)) < len; ++ix) { _creatorParameters[ix] = _findMissing(props[ix]);
for (int ix = 0; (ix = _paramsSeenBig.nextClearBit(ix)) < len; ++ix) { _creatorParameters[ix] = _findMissing(props[ix]);