Java Code Examples for java.util.NavigableSet#size()
The following examples show how to use
java.util.NavigableSet#size() .
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: ConcurrentSkipListSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
void mutateSet(NavigableSet<Integer> set, int min, int max, BitSet bs) { int size = set.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (set.size() < size) { int element = min + rnd.nextInt(rangeSize); assertTrue(element >= min && element<= max); put(set, element, bs); } }
Example 2
Source File: ConcurrentSkipListSetTest.java From j2objc with Apache License 2.0 | 6 votes |
void mutateSet(NavigableSet<Integer> set, int min, int max, BitSet bs) { int size = set.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (set.size() < size) { int element = min + rnd.nextInt(rangeSize); assertTrue(element >= min && element <= max); put(set, element, bs); } }
Example 3
Source File: ResourceParallelCopier.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
private TreeMap<String, Integer> calculateGroupsToCopy(String folder, String[] includes, String[] excludes) throws IOException { NavigableSet<String> all = src.listResourcesRecursively(folder); if (all == null || all.isEmpty()) return null; int sizeBeforeFilter = all.size(); for (Iterator<String> it = all.iterator(); it.hasNext(); ) { String path = it.next(); if (!ResourceTool.matchFilter(path, includes, excludes)) { it.remove(); } } int sizeAfterFilter = all.size(); logger.info("{} resources (out of {}) to copy", sizeAfterFilter, sizeBeforeFilter); // returns a list of prefixes, each represents a group of resources TreeMap<String, Integer> groupCollector = new TreeMap<>(); divideGroups(all, "/", groupCollector); return groupCollector; }
Example 4
Source File: BlobStoreCompactor.java From ambry with Apache License 2.0 | 6 votes |
/** * Adds entries related to {@code entry} that are in the same {@code indexSegment} including {@code entry} * @param entries the list of {@link IndexEntry} to add to. * @param indexSegment the {@link IndexSegment} to fetch values from. * @param entry the {@link IndexEntry} that is under processing * @throws StoreException if there are problems using the index */ private void addAllEntriesForKeyInSegment(List<IndexEntry> entries, IndexSegment indexSegment, IndexEntry entry) throws StoreException { logger.trace("Fetching related entries of a blob with entry {} in index segment with start offset {} in {} " + "because they need to be retained", entry, indexSegment.getStartOffset(), storeId); NavigableSet<IndexValue> values = indexSegment.find(entry.getKey()); if (values.size() > 1) { // we are using a multivalued index segment. Any related values will be in this set values.forEach(valueFromSeg -> entries.add(new IndexEntry(entry.getKey(), valueFromSeg))); } else { // in a non multi valued segment, there can only be PUTs and DELETEs in the same segment entries.add(entry); if (entry.getValue().isFlagSet(IndexValue.Flags.Delete_Index)) { IndexValue putValue = getPutValueFromDeleteEntry(entry.getKey(), entry.getValue(), indexSegment); if (putValue != null) { entries.add(new IndexEntry(entry.getKey(), putValue)); } } } }
Example 5
Source File: BadQueryHistoryManager.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
public BadQueryHistory upsertEntryToProject(BadQueryEntry badQueryEntry, String project) throws IOException { if (StringUtils.isEmpty(project) || badQueryEntry.getAdj() == null || badQueryEntry.getSql() == null) throw new IllegalArgumentException(); BadQueryHistory badQueryHistory = getBadQueriesForProject(project); NavigableSet<BadQueryEntry> entries = badQueryHistory.getEntries(); entries.remove(badQueryEntry); // in case the entry already exists and this call means to update entries.add(badQueryEntry); int maxSize = kylinConfig.getBadQueryHistoryNum(); if (entries.size() > maxSize) { entries.pollFirst(); } getStore().checkAndPutResource(badQueryHistory.getResourcePath(), badQueryHistory, BAD_QUERY_INSTANCE_SERIALIZER); return badQueryHistory; }
Example 6
Source File: DictionaryManager.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
private DictionaryInfo checkDupByContent(DictionaryInfo dictInfo, Dictionary<String> dict) throws IOException { ResourceStore store = getStore(); NavigableSet<String> existings = store.listResources(dictInfo.getResourceDir()); if (existings == null) return null; logger.info("{} existing dictionaries of the same column", existings.size()); if (existings.size() > 100) { logger.warn("Too many dictionaries under {}, dict count: {}", dictInfo.getResourceDir(), existings.size()); } for (String existing : existings) { try { if (existing.endsWith(".dict")) { DictionaryInfo existingInfo = getDictionaryInfo(existing); if (existingInfo != null && dict.equals(existingInfo.getDictionaryObject())) { return existingInfo; } } } catch (Exception ex) { logger.error("Tolerate exception checking dup dictionary " + existing, ex); } } return null; }
Example 7
Source File: BTreeSet2Test.java From scava with Eclipse Public License 2.0 | 6 votes |
void mutateSet(NavigableSet<Integer> set, int min, int max, BitSet bs) { int size = set.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { int val = it.next(); bs.clear(val); it.remove(); } } // Add entries till we're back to original size while (set.size() < size) { int element = min + rnd.nextInt(rangeSize); assertTrue(element >= min && element<= max); put(set, element, bs); } }
Example 8
Source File: TreeSetTest.java From j2objc with Apache License 2.0 | 6 votes |
void mutateSet(NavigableSet<Integer> set, int min, int max) { int size = set.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(set, min - 5 + rnd.nextInt(rangeSize + 10)); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (set.size() < size) { int element = min + rnd.nextInt(rangeSize); assertTrue(element >= min && element <= max); put(set, element); } }
Example 9
Source File: DstClusterUtil.java From kylin with Apache License 2.0 | 6 votes |
private String checkDupDict(DictionaryInfo dictInfo) throws IOException { NavigableSet<String> existings = resourceStore.listResources(dictInfo.getResourceDir()); if (existings == null) return null; logger.info("{} existing dictionaries of the same column", existings.size()); if (existings.size() > 100) { logger.warn("Too many dictionaries under {}, dict count: {}", dictInfo.getResourceDir(), existings.size()); } for (String existing : existings) { DictionaryInfo existingInfo = getDictionaryInfo(existing); if (existingInfo != null && dictInfo.getDictionaryObject().equals(existingInfo.getDictionaryObject())) { return existing; } } return null; }
Example 10
Source File: TreeSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void mutateSubSet(NavigableSet<Integer> set, int min, int max) { int size = set.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(set, min - 5 + rnd.nextInt(rangeSize + 10)); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (set.size() < size) { int element = min - 5 + rnd.nextInt(rangeSize + 10); if (element >= min && element <= max) { put(set, element); } else { try { set.add(element); shouldThrow(); } catch (IllegalArgumentException success) {} } } }
Example 11
Source File: StoreScanner.java From hbase with Apache License 2.0 | 5 votes |
@VisibleForTesting StoreScanner(Scan scan, ScanInfo scanInfo, NavigableSet<byte[]> columns, List<? extends KeyValueScanner> scanners, ScanType scanType) throws IOException { // 0 is passed as readpoint because the test bypasses Store this(null, scan, scanInfo, columns != null ? columns.size() : 0, 0L, scan.getCacheBlocks(), scanType); if (scanType == ScanType.USER_SCAN) { this.matcher = UserScanQueryMatcher.create(scan, scanInfo, columns, oldestUnexpiredTS, now, null); } else { this.matcher = CompactionScanQueryMatcher.create(scanInfo, scanType, Long.MAX_VALUE, HConstants.OLDEST_TIMESTAMP, oldestUnexpiredTS, now, null, null, null); } seekAllScanner(scanInfo, scanners); }
Example 12
Source File: ExplicitColumnTracker.java From hbase with Apache License 2.0 | 5 votes |
/** * Default constructor. * @param columns columns specified user in query * @param minVersions minimum number of versions to keep * @param maxVersions maximum versions to return per column * @param oldestUnexpiredTS the oldest timestamp we are interested in, based on TTL */ public ExplicitColumnTracker(NavigableSet<byte[]> columns, int minVersions, int maxVersions, long oldestUnexpiredTS) { this.maxVersions = maxVersions; this.minVersions = minVersions; this.oldestStamp = oldestUnexpiredTS; this.columns = new ColumnCount[columns.size()]; int i = 0; for (byte[] column : columns) { this.columns[i++] = new ColumnCount(column); } reset(); }
Example 13
Source File: ConcurrentSkipListSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
void mutateSubSet(NavigableSet<Integer> set, int min, int max, BitSet bs) { int size = set.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (set.size() < size) { int element = min - 5 + rnd.nextInt(rangeSize + 10); if (element >= min && element<= max) { put(set, element, bs); } else { try { set.add(element); shouldThrow(); } catch (IllegalArgumentException success) {} } } }
Example 14
Source File: ConcurrentSkipListSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
void mutateSubSet(NavigableSet<Integer> set, int min, int max, BitSet bs) { int size = set.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (set.size() < size) { int element = min - 5 + rnd.nextInt(rangeSize + 10); if (element >= min && element<= max) { put(set, element, bs); } else { try { set.add(element); shouldThrow(); } catch (IllegalArgumentException success) {} } } }
Example 15
Source File: TopTipsView.java From iBeebo with GNU General Public License v3.0 | 5 votes |
public void handle(long id, long helperId) { if (disappear || id == 0L) { return; } NavigableSet<Long> tmp = ids.headSet(id, true); if (tmp.size() > 0) { tmp.clear(); setCount(); if (this.onChangeListener != null) { this.onChangeListener.onChange(ids.size()); } } if (type == Type.ALWAYS) { return; } if (helperId == 0L) { return; } if (ids.contains(helperId)) { setCount(); } else { setVisibility(View.INVISIBLE); } }
Example 16
Source File: TopTipsView.java From iBeebo with GNU General Public License v3.0 | 5 votes |
public void handle(long id, long helperId) { if (disappear || id == 0L) { return; } NavigableSet<Long> tmp = ids.headSet(id, true); if (tmp.size() > 0) { tmp.clear(); setCount(); if (this.onChangeListener != null) { this.onChangeListener.onChange(ids.size()); } } if (type == Type.ALWAYS) { return; } if (helperId == 0L) { return; } if (ids.contains(helperId)) { setCount(); } else { setVisibility(View.INVISIBLE); } }
Example 17
Source File: ProtobufUtil.java From hbase with Apache License 2.0 | 4 votes |
/** * Create a protocol buffer Get based on a client Get. * * @param get the client Get * @return a protocol buffer Get * @throws IOException */ public static ClientProtos.Get toGet( final Get get) throws IOException { ClientProtos.Get.Builder builder = ClientProtos.Get.newBuilder(); builder.setRow(UnsafeByteOperations.unsafeWrap(get.getRow())); builder.setCacheBlocks(get.getCacheBlocks()); builder.setMaxVersions(get.getMaxVersions()); if (get.getFilter() != null) { builder.setFilter(ProtobufUtil.toFilter(get.getFilter())); } get.getColumnFamilyTimeRange().forEach((cf, timeRange) -> { builder.addCfTimeRange(HBaseProtos.ColumnFamilyTimeRange.newBuilder() .setColumnFamily(UnsafeByteOperations.unsafeWrap(cf)) .setTimeRange(toTimeRange(timeRange)) .build()); }); builder.setTimeRange(ProtobufUtil.toTimeRange(get.getTimeRange())); Map<String, byte[]> attributes = get.getAttributesMap(); if (!attributes.isEmpty()) { NameBytesPair.Builder attributeBuilder = NameBytesPair.newBuilder(); for (Map.Entry<String, byte[]> attribute: attributes.entrySet()) { attributeBuilder.setName(attribute.getKey()); attributeBuilder.setValue(UnsafeByteOperations.unsafeWrap(attribute.getValue())); builder.addAttribute(attributeBuilder.build()); } } if (get.hasFamilies()) { Column.Builder columnBuilder = Column.newBuilder(); Map<byte[], NavigableSet<byte[]>> families = get.getFamilyMap(); for (Map.Entry<byte[], NavigableSet<byte[]>> family: families.entrySet()) { NavigableSet<byte[]> qualifiers = family.getValue(); columnBuilder.setFamily(UnsafeByteOperations.unsafeWrap(family.getKey())); columnBuilder.clearQualifier(); if (qualifiers != null && qualifiers.size() > 0) { for (byte[] qualifier: qualifiers) { columnBuilder.addQualifier(UnsafeByteOperations.unsafeWrap(qualifier)); } } builder.addColumn(columnBuilder.build()); } } if (get.getMaxResultsPerColumnFamily() >= 0) { builder.setStoreLimit(get.getMaxResultsPerColumnFamily()); } if (get.getRowOffsetPerColumnFamily() > 0) { builder.setStoreOffset(get.getRowOffsetPerColumnFamily()); } if (get.isCheckExistenceOnly()){ builder.setExistenceOnly(true); } if (get.getConsistency() != null && get.getConsistency() != Consistency.STRONG) { builder.setConsistency(toConsistency(get.getConsistency())); } Boolean loadColumnFamiliesOnDemand = get.getLoadColumnFamiliesOnDemandValue(); if (loadColumnFamiliesOnDemand != null) { builder.setLoadColumnFamiliesOnDemand(loadColumnFamiliesOnDemand); } return builder.build(); }
Example 18
Source File: ProducerParticipant.java From qpid-broker-j with Apache License 2.0 | 4 votes |
private int getPayloadSizeForResultIfConstantOrZeroOtherwise(NavigableSet<Integer> allPayloadSizes) { return allPayloadSizes.size() == 1 ? allPayloadSizes.first() : 0; }
Example 19
Source File: StoreScanner.java From hbase with Apache License 2.0 | 4 votes |
/** * Opens a scanner across memstore, snapshot, and all StoreFiles. Assumes we * are not in a compaction. * * @param store who we scan * @param scan the spec * @param columns which columns we are scanning * @throws IOException */ public StoreScanner(HStore store, ScanInfo scanInfo, Scan scan, NavigableSet<byte[]> columns, long readPt) throws IOException { this(store, scan, scanInfo, columns != null ? columns.size() : 0, readPt, scan.getCacheBlocks(), ScanType.USER_SCAN); if (columns != null && scan.isRaw()) { throw new DoNotRetryIOException("Cannot specify any column for a raw scan"); } matcher = UserScanQueryMatcher.create(scan, scanInfo, columns, oldestUnexpiredTS, now, store.getCoprocessorHost()); store.addChangedReaderObserver(this); List<KeyValueScanner> scanners = null; try { // Pass columns to try to filter out unnecessary StoreFiles. scanners = selectScannersFrom(store, store.getScanners(cacheBlocks, scanUsePread, false, matcher, scan.getStartRow(), scan.includeStartRow(), scan.getStopRow(), scan.includeStopRow(), this.readPt)); // Seek all scanners to the start of the Row (or if the exact matching row // key does not exist, then to the start of the next matching Row). // Always check bloom filter to optimize the top row seek for delete // family marker. seekScanners(scanners, matcher.getStartKey(), explicitColumnQuery && lazySeekEnabledGlobally, parallelSeekEnabled); // set storeLimit this.storeLimit = scan.getMaxResultsPerColumnFamily(); // set rowOffset this.storeOffset = scan.getRowOffsetPerColumnFamily(); addCurrentScanners(scanners); // Combine all seeked scanners with a heap resetKVHeap(scanners, comparator); } catch (IOException e) { clearAndClose(scanners); // remove us from the HStore#changedReaderObservers here or we'll have no chance to // and might cause memory leak store.deleteChangedReaderObserver(this); throw e; } }
Example 20
Source File: ListFlowFilesEndpointMerger.java From nifi with Apache License 2.0 | 4 votes |
@Override protected void mergeResponses(ListingRequestDTO clientDto, Map<NodeIdentifier, ListingRequestDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) { final Comparator<FlowFileSummaryDTO> comparator = new Comparator<FlowFileSummaryDTO>() { @Override public int compare(final FlowFileSummaryDTO dto1, final FlowFileSummaryDTO dto2) { int positionCompare = dto1.getPosition().compareTo(dto2.getPosition()); if (positionCompare != 0) { return positionCompare; } final String address1 = dto1.getClusterNodeAddress(); final String address2 = dto2.getClusterNodeAddress(); if (address1 == null && address2 == null) { return 0; } if (address1 == null) { return 1; } if (address2 == null) { return -1; } return address1.compareTo(address2); } }; final NavigableSet<FlowFileSummaryDTO> flowFileSummaries = new TreeSet<>(comparator); ListFlowFileState state = null; int numStepsCompleted = 0; int numStepsTotal = 0; int objectCount = 0; long byteCount = 0; boolean finished = true; for (final Map.Entry<NodeIdentifier, ListingRequestDTO> entry : dtoMap.entrySet()) { final NodeIdentifier nodeIdentifier = entry.getKey(); final String nodeAddress = nodeIdentifier.getApiAddress() + ":" + nodeIdentifier.getApiPort(); final ListingRequestDTO nodeRequest = entry.getValue(); numStepsTotal++; if (Boolean.TRUE.equals(nodeRequest.getFinished())) { numStepsCompleted++; } final QueueSizeDTO nodeQueueSize = nodeRequest.getQueueSize(); objectCount += nodeQueueSize.getObjectCount(); byteCount += nodeQueueSize.getByteCount(); if (!nodeRequest.getFinished()) { finished = false; } if (nodeRequest.getLastUpdated().after(clientDto.getLastUpdated())) { clientDto.setLastUpdated(nodeRequest.getLastUpdated()); } // Keep the state with the lowest ordinal value (the "least completed"). final ListFlowFileState nodeState = ListFlowFileState.valueOfDescription(nodeRequest.getState()); if (state == null || state.compareTo(nodeState) > 0) { state = nodeState; } if (nodeRequest.getFlowFileSummaries() != null) { for (final FlowFileSummaryDTO summaryDTO : nodeRequest.getFlowFileSummaries()) { if (summaryDTO.getClusterNodeId() == null || summaryDTO.getClusterNodeAddress() == null) { summaryDTO.setClusterNodeId(nodeIdentifier.getId()); summaryDTO.setClusterNodeAddress(nodeAddress); } flowFileSummaries.add(summaryDTO); // Keep the set from growing beyond our max if (flowFileSummaries.size() > clientDto.getMaxResults()) { flowFileSummaries.pollLast(); } } } if (nodeRequest.getFailureReason() != null) { clientDto.setFailureReason(nodeRequest.getFailureReason()); } } final List<FlowFileSummaryDTO> summaryDTOs = new ArrayList<>(flowFileSummaries); clientDto.setFlowFileSummaries(summaryDTOs); // depends on invariant if numStepsTotal is 0, so is numStepsCompleted, all steps being completed // would be 1 final int percentCompleted = (numStepsTotal == 0) ? 1 : numStepsCompleted / numStepsTotal; clientDto.setPercentCompleted(percentCompleted); clientDto.setFinished(finished); clientDto.getQueueSize().setByteCount(byteCount); clientDto.getQueueSize().setObjectCount(objectCount); }