public void add(final OIdentifiable identifiable) { if (identifiable == null) throw new NullPointerException("Impossible to add a null identifiable in a ridbag"); if (identifiable.getIdentity().isValid()) { Change counter = changes.get(identifiable); if (counter == null) changes.put(identifiable, new DiffChange(1)); else { if (counter.isUndefined()) { counter = getAbsoluteValue(identifiable); changes.put(identifiable, counter); } counter.increment(); } } else { final OModifiableInteger counter = newEntries.get(identifiable); if (counter == null) newEntries.put(identifiable, new OModifiableInteger(1)); else counter.increment(); } if (size >= 0) size++; if (this.owner != null) ORecordInternal.track(this.owner, identifiable); if (updateOwner) fireCollectionChangedEvent( new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>( OMultiValueChangeEvent.OChangeType.ADD, identifiable, identifiable, null, false)); }
protected void forwardToCoord(long seqno, Message msg) { if (is_coord) { forward(msg, seqno, false); return; } if (!running || flushing) { forward_table.put(seqno, msg); return; } if (!ack_mode) { forward_table.put(seqno, msg); forward(msg, seqno, false); return; } send_lock.lock(); try { forward_table.put(seqno, msg); while (running && !flushing) { ack_promise.reset(); forward(msg, seqno, true); if (!ack_mode || !running || flushing) break; Long ack = ack_promise.getResult(500); if ((Objects.equals(ack, seqno)) || !forward_table.containsKey(seqno)) break; } } finally { send_lock.unlock(); } }
public NavigableMap<Number640, Data> removeReturnData( Number640 from, Number640 to, PublicKey publicKey) { RangeLock<Number640>.Range lock = rangeLock.lock(from, to); try { Map<Number640, Data> tmp = backend.subMap(from, to); NavigableMap<Number640, Data> result = new TreeMap<Number640, Data>(); for (Number640 key : tmp.keySet()) { // fail fast, as soon as we want to remove 1 domain that we // cannot, abort if (!canClaimDomain(key.locationAndDomainKey(), publicKey)) { result.put(key, null); } else if (!canClaimEntry(key.locationAndDomainAndContentKey(), publicKey)) { result.put(key, null); } else { Data toRemove = backend.get(key); if (toRemove != null && (toRemove.publicKey() == null || toRemove.publicKey().equals(publicKey))) { backend.removeTimeout(key); Data removed = backend.remove(key, true); result.put(key, removed); } } } return result; } finally { lock.unlock(); } }
@Override protected SortedMap<String, Integer> makePopulatedMap() { NavigableMap<String, Integer> map = new SafeTreeMap<String, Integer>(); map.put("one", 1); map.put("two", 2); map.put("three", 3); return SerializableTester.reserialize(map); }
private NavigableMap<byte[], byte[]> recordMap(final Class<?> idType, final boolean principal) { String ownerString = SOME_PRINCIPAL + ":" + principal; NavigableMap<byte[], byte[]> recordMap = new TreeMap<byte[], byte[]>(Bytes.BYTES_COMPARATOR); recordMap.put(HBaseACLRepository.ACL_ID_TYPE_QUALIFIER, idType.getName().getBytes()); recordMap.put(HBaseACLRepository.ACL_TYPE_QUALIFIER, TYPE.getBytes()); recordMap.put(HBaseACLRepository.ACL_OWNER_QUALIFIER, ownerString.getBytes()); return recordMap; }
@Override protected NavigableMap<String, ZoneRules> provideVersions(String zoneId) { NavigableMap<String, ZoneRules> result = new TreeMap<>(); result.put("DynamicVersion1", BASE); if (count > 2) { result.put("DynamicVersion2", ALTERNATE); } return result; }
public void testStandardLastEntry() { NavigableMap<String, Integer> forwarding = new StandardLastEntryForwardingNavigableMap<String, Integer>( new SafeTreeMap<String, Integer>()); assertNull(forwarding.lastEntry()); forwarding.put("b", 2); assertEquals(immutableEntry("b", 2), forwarding.lastEntry()); forwarding.put("c", 3); assertEquals(immutableEntry("c", 3), forwarding.lastEntry()); forwarding.put("a", 1); assertEquals(immutableEntry("c", 3), forwarding.lastEntry()); forwarding.remove("c"); assertEquals(immutableEntry("b", 2), forwarding.lastEntry()); }
public void remove(OIdentifiable identifiable) { if (removeFromNewEntries(identifiable)) { if (size >= 0) size--; } else { final Change counter = changes.get(identifiable); if (counter == null) { // Not persistent keys can only be in changes or newEntries if (identifiable.getIdentity().isPersistent()) { changes.put(identifiable, new DiffChange(-1)); size = -1; } else // Return immediately to prevent firing of event return; } else { counter.decrement(); if (size >= 0) if (counter.isUndefined()) size = -1; else size--; } } if (this.owner != null) ORecordInternal.unTrack(this.owner, identifiable); if (updateOwner) fireCollectionChangedEvent( new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>( OMultiValueChangeEvent.OChangeType.REMOVE, identifiable, null, identifiable, false)); }
/** * Load all elements of this type from the TMC LocationCodeList. * * @param aDirectory the directioy where the location-list is stored. * @param aLocationTable the top-level class we are working for * @return all elements indexed by LocationCode * @throws IOException if we cannot read */ public static NavigableMap<Integer, TMCAdminArea> loadAll( final File aDirectory, final TMCLocationTable aLocationTable) throws IOException { NavigableMap<Integer, TMCAdminArea> retval = new TreeMap<Integer, TMCAdminArea>(new AdminAreaComparator()); File inFile = new File(aDirectory, "ADMINISTRATIVEAREA.DAT"); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile), "ISO8859-15")); in.readLine(); // header; String line = in.readLine(); while (line != null) { String[] split = (line + " ").split(";"); line = in.readLine(); int i = 0; TMCAdminArea point = new TMCAdminArea( Integer.parseInt(split[i++]), // CID; Integer.parseInt(split[i++]), // TABCD; Integer.parseInt(split[i++]), // LCD; split[i++].charAt(0), // CLASS; Integer.parseInt(split[i++]), // TCD; Integer.parseInt(split[i++]), // STCD; parseOptionalInteger(split[i++]), // NID; parseOptionalInteger(split[i++]), // POL_LCD; aLocationTable); retval.put(point.getLCD(), point); } return retval; }
/** * Creates (if not already existing) and returns the partition in which the instant,value should * be written. instant can be invalid (in case value only or no partitioning) value can be null * (in case * * @return a Partition */ public synchronized Partition createAndGetPartition(long instant, Object value) throws IOException { Partition partition; if (partitioningSpec.timeColumn != null) { if ((pcache == null) || (pcache.start > instant) || (pcache.getEnd() <= instant)) { Entry<Long, Interval> entry = intervals.floorEntry(instant); if ((entry != null) && (instant < entry.getValue().getEnd())) { pcache = entry.getValue(); } else { // no partition in this interval. PartitionInfo pinfo = partitioningSpec.timePartitioningSchema.getPartitionInfo(instant); pcache = new Interval(pinfo.partitionStart, pinfo.partitionEnd); intervals.put(pcache.start, pcache); } } } partition = pcache.get(value); if (partition == null) { if (partitioningSpec.timeColumn != null) { PartitionInfo pinfo = partitioningSpec.timePartitioningSchema.getPartitionInfo(instant); partition = createPartition(pinfo, value); } else { partition = createPartition(value); } pcache.add(value, partition); } return partition; }
/** * Create a snapshot of current map. * * @return a snapshot of current map. */ public NavigableMap<K, V> snapshot() { this.lock.writeLock().lock(); try { if (updates.isEmpty()) { return snapshot; } // put updates for merge to snapshot updatesToMerge = updates; updates = new ConcurrentHashMap<K, V>(); } finally { this.lock.writeLock().unlock(); } // merging the updates to snapshot for (Map.Entry<K, V> entry : updatesToMerge.entrySet()) { snapshot.put(entry.getKey(), entry.getValue()); } // clear updatesToMerge this.lock.writeLock().lock(); try { updatesToMerge = new ConcurrentHashMap<K, V>(); } finally { this.lock.writeLock().unlock(); } return snapshot; }
/** * @param catalogTracker * @param serverName * @return List of user regions installed on this server (does not include catalog regions). * @throws IOException */ public static NavigableMap<HRegionInfo, Result> getServerUserRegions( CatalogTracker catalogTracker, final ServerName serverName) throws IOException { final NavigableMap<HRegionInfo, Result> hris = new TreeMap<HRegionInfo, Result>(); // Fill the above hris map with entries from .META. that have the passed // servername. CollectingVisitor<Result> v = new CollectingVisitor<Result>() { @Override void add(Result r) { if (r == null || r.isEmpty()) return; ServerName sn = getServerNameFromCatalogResult(r); if (sn != null && sn.equals(serverName)) this.results.add(r); } }; fullScan(catalogTracker, v); List<Result> results = v.getResults(); if (results != null && !results.isEmpty()) { // Convert results to Map keyed by HRI for (Result r : results) { Pair<HRegionInfo, ServerName> p = parseCatalogResult(r); if (p != null && p.getFirst() != null) hris.put(p.getFirst(), r); } } return hris; }
public void testHandleToFileAndFileToHandle() { final PersistentEntityStoreImpl store = getEntityStore(); final PersistentStoreTransaction txn = getStoreTransaction(); store.getConfig().setMaxInPlaceBlobSize(0); // no in-lace blobs final int count = 1000; for (int i = 0; i < count; ++i) { txn.newEntity("E").setBlob("b", new ByteArrayInputStream("content".getBytes())); } Assert.assertTrue(txn.flush()); final FileSystemBlobVault blobVault = (FileSystemBlobVault) store.getBlobVault(); final NavigableMap<Long, File> handlesToFiles = new TreeMap<>(); for (final BackupStrategy.FileDescriptor fd : blobVault.getBackupStrategy().listFiles()) { final File file = fd.getFile(); if (file.isFile() && !file.getName().equals(FileSystemBlobVaultOld.VERSION_FILE)) { final long handle = blobVault.getBlobHandleByFile(file); Assert.assertFalse(handlesToFiles.containsKey(handle)); handlesToFiles.put(handle, file); Assert.assertEquals(file, blobVault.getBlobLocation(handle)); } } final long min = handlesToFiles.navigableKeySet().iterator().next(); Assert.assertEquals(0L, min); final long max = handlesToFiles.descendingKeySet().iterator().next(); Assert.assertEquals((long) (count - 1), max); }
@Test public void insertZeroDataPointsNothingBetween() { NavigableMap<TimeAxisKey, DiffStat> diffStats = new TreeMap<>(); YearMonthDay firstKey = new YearMonthDay((short) 2012, (byte) 1, (byte) 2); YearMonthDay secondKey = new YearMonthDay((short) 2012, (byte) 1, (byte) 3); diffStats.put(firstKey, new DiffStat(1, 1)); diffStats.put(secondKey, new DiffStat(2, 2)); // TODO fix hamcrest assertEquals(2, diffStats.size()); DiffStatGenerator.insertZeroDataPoints(diffStats); assertEquals(2, diffStats.size()); assertEquals(new DiffStat(1, 1), diffStats.get(firstKey)); assertEquals(new DiffStat(2, 2), diffStats.get(secondKey)); }
public static void addtoMinheap() { for (RankedDoc i : R) { lminheap.put(i.novelty, Integer.toString(i.DOC)); } lminheap = lminheap.descendingMap(); }
private NavigableMap<String, Integer> reduce(List<Result> list) { NavigableMap<String, Integer> reducedMap = new ConcurrentSkipListMap<String, Integer>(); Iterator<Result> iter = list.iterator(); while (iter.hasNext()) { Result result = iter.next(); if (reducedMap.containsKey(result.getWord())) { Integer value = (Integer) reducedMap.get(result.getWord()); value++; reducedMap.put(result.getWord(), value); } else { reducedMap.put(result.getWord(), Integer.valueOf(1)); } } return reducedMap; }
public PartitionManager(TableDefinition tableDefinition) { this.tableDefinition = tableDefinition; this.partitioningSpec = tableDefinition.getPartitioningSpec(); if (partitioningSpec.type == _type.NONE || partitioningSpec.type == _type.VALUE) { // pcache never changes in this case pcache = new Interval(TimeEncoding.MIN_INSTANT, TimeEncoding.MAX_INSTANT); intervals.put(TimeEncoding.MIN_INSTANT, pcache); } }
private void addParametersFromQueryString(String queryString) { if (queryString == null || queryString.length() == 0) { return; } final StringTokenizer params = new StringTokenizer(queryString, "&", false); while (params.hasMoreTokens()) { final String rawEntry = params.nextToken(); final int ndx = rawEntry.indexOf('='); if (ndx < 0) { final String key = decode(rawEntry); parameters.put(key, ""); } else { final String key = decode(rawEntry.substring(0, ndx)); final String value = decode(rawEntry.substring(ndx + 1)); parameters.put(key, value); } } }
public void testBackwardIteration() throws IOException { final int records = 10000; long seed = System.currentTimeMillis(); MersenneTwisterFast mersenneTwisterFast = new MersenneTwisterFast(1381162033616L); System.out.println("testBackwardIteration seed : " + seed); NavigableMap<OClusterPosition, byte[]> positionRecordMap = new TreeMap<OClusterPosition, byte[]>(); ORecordVersion recordVersion = OVersionFactory.instance().createVersion(); recordVersion.increment(); recordVersion.increment(); for (int i = 0; i < records; i++) { int recordSize = mersenneTwisterFast.nextInt(2 * OClusterPage.MAX_RECORD_SIZE) + 1; byte[] record = new byte[recordSize]; mersenneTwisterFast.nextBytes(record); final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(record, recordVersion, (byte) 2); positionRecordMap.put(physicalPosition.clusterPosition, record); } Iterator<OClusterPosition> positionIterator = positionRecordMap.keySet().iterator(); while (positionIterator.hasNext()) { OClusterPosition clusterPosition = positionIterator.next(); if (mersenneTwisterFast.nextBoolean()) { Assert.assertTrue(paginatedCluster.deleteRecord(clusterPosition)); positionIterator.remove(); } } OPhysicalPosition physicalPosition = new OPhysicalPosition(); physicalPosition.clusterPosition = OClusterPositionFactory.INSTANCE.valueOf(Long.MAX_VALUE); OPhysicalPosition[] positions = paginatedCluster.floorPositions(physicalPosition); Assert.assertTrue(positions.length > 0); positionIterator = positionRecordMap.descendingKeySet().iterator(); int counter = 0; while (positionIterator.hasNext()) { Assert.assertTrue(positions.length > 0); OClusterPosition testedPosition = positionIterator.next(); Assert.assertEquals(positions[positions.length - 1].clusterPosition, testedPosition); OPhysicalPosition positionToFind = positions[positions.length - 1]; positions = paginatedCluster.lowerPositions(positionToFind); counter++; } Assert.assertEquals(paginatedCluster.getEntries(), counter); Assert.assertEquals(paginatedCluster.getFirstPosition(), positionRecordMap.firstKey()); Assert.assertEquals(paginatedCluster.getLastPosition(), positionRecordMap.lastKey()); }
public IndexRateSource update(Collection<IndexRate> indexRates) { for (IndexRate indexRate : indexRates) { if (!data.containsKey(indexRate.indexId)) { data.put(indexRate.indexId, new ConcurrentSkipListMap<>()); } NavigableMap<LocalDate, IndexRate> dateMap = data.get(indexRate.indexId); dateMap.put(indexRate.date, indexRate); } return this; }
@Override public void remove() { if (currentRemoved) throw new IllegalStateException("Current element has already been removed"); if (currentValue == null) throw new IllegalStateException("Next method was not called for given iterator"); if (removeFromNewEntries(currentValue)) { if (size >= 0) size--; } else { Change counter = changedValues.get(currentValue); if (counter != null) { counter.decrement(); if (size >= 0) if (counter.isUndefined()) size = -1; else size--; } else { if (nextChange != null) { changedValues.put(currentValue, new DiffChange(-1)); changedValuesIterator = changedValues.tailMap(nextChange.getKey(), false).entrySet().iterator(); } else { changedValues.put(currentValue, new DiffChange(-1)); } size = -1; } } if (OSBTreeRidBag.this.owner != null) ORecordInternal.unTrack(OSBTreeRidBag.this.owner, currentValue); if (updateOwner) fireCollectionChangedEvent( new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>( OMultiValueChangeEvent.OChangeType.REMOVE, currentValue, null, currentValue, false)); currentRemoved = true; }
@Override public void put(Bitmap bitmap) { int size = Util.getBitmapByteSize(bitmap); Key key = keyPool.get(size, bitmap.getConfig()); groupedMap.put(key, bitmap); NavigableMap<Integer, Integer> sizes = getSizesForConfig(bitmap.getConfig()); Integer current = sizes.get(key.size); sizes.put(key.size, current == null ? 1 : current + 1); }
private void addFunction( List<IParameter> plist, List<AFunction> flist, NavigableMap<Integer, AFunction> fmap, AFunction function) { int psize = plist.size(); flist.add(function); fmap.put(psize, function); for (IParameter p : function.parameters) { plist.add(p); } }
public void constructCache(DefaultSolverScope solverScope) { cachedEntityMap = new TreeMap<Double, Object>(); ScoreDirector scoreDirector = solverScope.getScoreDirector(); double probabilityWeightOffset = 0L; for (Object value : childValueSelector) { double probabilityWeight = valueProbabilityWeightFactory.createProbabilityWeight(scoreDirector, value); cachedEntityMap.put(probabilityWeightOffset, value); probabilityWeightOffset += probabilityWeight; } probabilityWeightTotal = probabilityWeightOffset; }
String decode(Integer textLength, Double number) { String str = ""; NavigableMap<Double, Character> sortedMap = new TreeMap<>(); rangeTable.forEach((k, v) -> sortedMap.put(v.getLow(), k)); for (int i = 0; i < textLength; i++) { Character value = sortedMap.floorEntry(number).getValue(); str = str.concat(String.valueOf(value)); Range range = rangeTable.get(value); number = (number - range.getLow()) / (range.getHigh() - range.getLow()); } return str; }
public void constructCache(DefaultSolverScope solverScope) { cachedEntityMap = new TreeMap<Double, Object>(); ScoreDirector scoreDirector = solverScope.getScoreDirector(); double probabilityWeightOffset = 0L; // TODO Fail-faster if a non FromSolutionPropertyValueSelector is used for (Object value : childValueSelector) { double probabilityWeight = probabilityWeightFactory.createProbabilityWeight(scoreDirector, value); cachedEntityMap.put(probabilityWeightOffset, value); probabilityWeightOffset += probabilityWeight; } probabilityWeightTotal = probabilityWeightOffset; }
private NavigableMap<Number640, Data> getLatestInternalOrig(NavigableMap<Number640, Data> input) { // delete all predecessors NavigableMap<Number640, Data> result = new TreeMap<Number640, Data>(); while (!input.isEmpty()) { // first entry is a latest version Entry<Number640, Data> latest = input.lastEntry(); // store in results list result.put(latest.getKey(), latest.getValue()); // delete all predecessors of latest entry deletePredecessors(latest.getKey(), input); } return result; }
/** {@inheritDoc} */ @Override public KijiTableKeyValueDatabase putValue(String table, String key, byte[] value) throws IOException { NavigableMap<String, byte[]> keyValueMap; if (mMetaMap.containsKey(table)) { keyValueMap = mMetaMap.get(table); } else { keyValueMap = new TreeMap<String, byte[]>(); } keyValueMap.put(key, value); mMetaMap.put(table, keyValueMap); return this; }
private void addRequestEndPointUsingPath( ContextMeta context, ServiceMeta service, ServiceMethodMeta method, RequestMeta requestMeta, String path) { RequestMetaData metaData = new RequestMetaData(path, context, requestMeta, method, service); if (requestMeta.getCallType() == CallType.ADDRESS) { metaDataMap.put(path, metaData); } else { treeMap.put(path, metaData); } }
@Override protected ApacheLogEntry prefetch() throws Exception { while (sortedBuffer.size() < maxSortedBufferSize) { if (itEntry == null) { if (itFile.hasNext()) { itEntry = new ApacheLogEntryIterator(LogDirectory.open(itFile.next().getValue()), true); } else { break; } } if (!itEntry.hasNext()) { itEntry = null; continue; } ApacheLogEntry entry = itEntry.next(); if (low != null) { int d = entry.getDate().compareTo(low); if (d < 0 || (d == 0 && !lowInclusive)) { continue; } } sortedBuffer.put(entry.getDate(), entry); } if (!sortedBuffer.isEmpty()) { ApacheLogEntry entry = sortedBuffer.pollFirstEntry().getValue(); if (sanityCheckMonotonictyDate != null) { if (sanityCheckMonotonictyDate.compareTo(entry.getDate()) > 0) { throw new RuntimeException("Dates are not monoton"); } } sanityCheckMonotonictyDate = entry.getDate(); if (high != null) { int d = high.compareTo(entry.getDate()); if (d < 0 || (d == 0 && !highInclusive)) { return finish(); } } return entry; } return finish(); }