List of usage examples for java.util NavigableMap size
int size();
From source file:com.opengamma.analytics.financial.greeks.MixedOrderUnderlying.java
public MixedOrderUnderlying(final NavigableMap<Integer, UnderlyingType> underlyings) { Validate.notNull(underlyings, "underlyings"); if (underlyings.size() < 2) { throw new IllegalArgumentException("Must have at least two underlying types to have mixed order"); }/*from ww w . j a v a 2s . c o m*/ _orders = new ArrayList<>(); _underlyings = new ArrayList<>(); int totalOrder = 0; UnderlyingType underlying; for (final Entry<Integer, UnderlyingType> entry : underlyings.entrySet()) { final int key = entry.getKey(); if (key < 1) { throw new IllegalArgumentException("Order must be at least one to have mixed order"); } underlying = entry.getValue(); _orders.add(new NthOrderUnderlying(key, underlying)); _underlyings.add(underlying); totalOrder += key; } _totalOrder = totalOrder; }
From source file:edu.indiana.soic.ts.crunch.CrunchDataReader.java
public PTable<String, String> extractText(PTable<ImmutableBytesWritable, Result> tableContent) { return tableContent.parallelDo("Read data", new DoFn<Pair<ImmutableBytesWritable, Result>, Pair<String, String>>() { @Override// w ww.j a v a2 s. c o m public void process(Pair<ImmutableBytesWritable, Result> row, Emitter<Pair<String, String>> emitter) { SimpleRegression regression; NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> map = row.second() .getMap(); System.out.println(map.size()); for (Map.Entry<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> columnFamilyMap : map .entrySet()) { regression = new SimpleRegression(); int count = 1; for (Map.Entry<byte[], NavigableMap<Long, byte[]>> entryVersion : columnFamilyMap .getValue().entrySet()) { for (Map.Entry<Long, byte[]> entry : entryVersion.getValue().entrySet()) { String rowKey = Bytes.toString(row.second().getRow()); String column = Bytes.toString(entryVersion.getKey()); byte[] val = entry.getValue(); String valOfColumn = new String(val); System.out.println("RowKey : " + rowKey + " Column Key : " + column + " Column Val : " + valOfColumn); if (!valOfColumn.isEmpty()) { String[] priceAndCap = valOfColumn.split("_"); if (priceAndCap.length > 1) { String pr = priceAndCap[0]; if (pr != null && !pr.equals("null")) { double price = Double.valueOf(pr); if (price < 0) { price = price - 2 * price; } System.out.println("Price : " + price + " count : " + count); regression.addData(count, price); } } } } count++; } // displays intercept of regression line System.out.println("Intercept : " + regression.getIntercept()); // displays slope of regression line System.out.println("Slope : " + regression.getSlope()); // displays slope standard error System.out.println("Slope STD Error : " + regression.getSlopeStdErr()); emitter.emit(new Pair<String, String>(String.valueOf(regression.getIntercept()), String.valueOf(regression.getSlope()))); } } }, Writables.tableOf(Writables.strings(), Writables.strings())); }
From source file:com.alibaba.wasp.meta.TestFMetaStore.java
@Test public void testEntityGroup() throws MetaException, DeserializationException { FTable User = FMetaTestUtil.User;//w ww. ja va 2s .c o m String tableName = User.getTableName(); restoreAndInitFMETA(); fMetaService.createTable(FMetaTestUtil.User); List<EntityGroupInfo> egis = getEntityGroup(tableName); // add EntityGroup fMetaService.addEntityGroup(egis); for (int i = 0; i < egis.size(); i++) { fMetaService.updateEntityGroupLocation(egis.get(i), egLocations[i]); } for (int i = 0; i < egis.size(); i++) { // getEntityGroupLocation ServerName sn = fMetaService.getEntityGroupLocation(egis.get(i)); assertEquals(sn.compareTo(egLocations[i]), 0); } for (int i = 0; i < egis.size(); i++) { // getEntityGroupsAndLocations Pair<EntityGroupInfo, ServerName> pair = fMetaService .getEntityGroupAndLocation(egis.get(i).getEntityGroupName()); assertEquals(pair.getFirst().compareTo(egis.get(i)), 0); assertEquals(pair.getSecond().compareTo(egLocations[i]), 0); } Set<String> disabledTables = new HashSet<String>(); // fullScan Map<EntityGroupInfo, ServerName> entityGroups = fMetaService.fullScan(disabledTables, false); assertEquals(entityGroups.size(), egis.size()); for (int i = 0; i < egis.size(); i++) { ServerName sn = entityGroups.get(egis.get(i)); assertEquals(sn.compareTo(egLocations[i]), 0); } // getOfflineSplitParents Map<EntityGroupInfo, Result> offlineSplitParents = fMetaService.getOfflineSplitParents(); assertEquals(offlineSplitParents.size(), 0); // getServerUserEntityGroups NavigableMap<EntityGroupInfo, Result> egR = fMetaService.getServerUserEntityGroups(egLocations[0]); assertEquals(1, egR.size()); { Result r = egR.get(egis.get(0)); byte[] infoValue = r.getValue(FConstants.CATALOG_FAMILY, FConstants.EGINFO); byte[] locationValue = r.getValue(FConstants.CATALOG_FAMILY, FConstants.EGLOCATION); EntityGroupInfo key = EntityGroupInfo.parseFromOrNull(infoValue); ServerName value = ServerName.convert(locationValue); assertEquals(key.compareTo(egis.get(0)), 0); assertEquals(value.compareTo(egLocations[0]), 0); } // getTableEntityGroupsAndLocations List<Pair<EntityGroupInfo, ServerName>> entityGroupInfos = fMetaService .getTableEntityGroupsAndLocations(Bytes.toBytes(tableName), false); entityGroups = new TreeMap<EntityGroupInfo, ServerName>(); for (Pair<EntityGroupInfo, ServerName> pair : entityGroupInfos) { entityGroups.put(pair.getFirst(), pair.getSecond()); } for (int i = 0; i < egis.size(); i++) { ServerName sn = entityGroups.get(egis.get(i)); assertEquals(sn.compareTo(egLocations[i]), 0); } fMetaService.dropTable(FMetaTestUtil.User.getTableName()); }
From source file:com.eucalyptus.tests.awssdk.S3ListMpuTests.java
@Test public void keyMarker() throws Exception { testInfo(this.getClass().getSimpleName() + " - keyMarker"); try {//www .jav a 2s . c o m int numKeys = 3 + random.nextInt(3); // 3-5 keys int numUploads = 3 + random.nextInt(3); // 3-5 uploads print("Number of keys: " + numKeys); print("Number of uploads per key: " + numUploads); // Generate some mpus TreeMap<String, List<String>> keyUploadIdMap = initiateMpusForMultipleKeys(s3ClientA, accountA, numKeys, numUploads, new String()); // Starting with every key in the ascending order, list the mpus using that key as the key marker and verify that the results. for (String keyMarker : keyUploadIdMap.keySet()) { // Compute what the sorted mpus should look like NavigableMap<String, List<String>> tailMap = keyUploadIdMap.tailMap(keyMarker, false); // List mpus using the key marker and verify MultipartUploadListing listing = listMpu(s3ClientA, accountA, bucketName, keyMarker, null, null, null, null, false); assertTrue( "Expected " + (tailMap.size() * numUploads) + " mpu listings, but got " + listing.getMultipartUploads().size(), (tailMap.size() * numUploads) == listing.getMultipartUploads().size()); Iterator<MultipartUpload> mpuIterator = listing.getMultipartUploads().iterator(); for (Entry<String, List<String>> tailMapEntry : tailMap.entrySet()) { for (String uploadId : tailMapEntry.getValue()) { MultipartUpload mpu = mpuIterator.next(); assertTrue("Expected key to be " + tailMapEntry.getKey() + ", but got " + mpu.getKey(), mpu.getKey().equals(tailMapEntry.getKey())); assertTrue("Expected upload ID to be " + uploadId + ", but got " + mpu.getUploadId(), mpu.getUploadId().equals(uploadId)); verifyCommonElements(mpu); } } assertTrue("Expected mpu iterator to be empty", !mpuIterator.hasNext()); } } catch (AmazonServiceException ase) { printException(ase); assertThat(false, "Failed to run keyMarker"); } }
From source file:com.eucalyptus.tests.awssdk.S3ListMpuTests.java
@Test public void keyMarkerUploadIdMarker() throws Exception { testInfo(this.getClass().getSimpleName() + " - keyMarkerUploadIdMarker"); try {/* ww w . j a v a 2s . co m*/ int numKeys = 3 + random.nextInt(3); // 3-5 keys int numUploads = 3 + random.nextInt(3); // 3-5 uploads print("Number of keys: " + numKeys); print("Number of uploads per key: " + numUploads); // Generate some mpus TreeMap<String, List<String>> keyUploadIdMap = initiateMpusForMultipleKeys(s3ClientA, accountA, numKeys, numUploads, new String()); // Starting with every key and upload ID in the ascending order, list the mpus using the pair and verify that the results. for (Map.Entry<String, List<String>> mapEntry : keyUploadIdMap.entrySet()) { // Compute what the sorted mpus should look like NavigableMap<String, List<String>> tailMap = keyUploadIdMap.tailMap(mapEntry.getKey(), false); for (int i = 0; i < numUploads; i++) { // Compute what the sorted uploadIds should look like this key List<String> tailList = mapEntry.getValue().subList(i + 1, numUploads); // List mpus using the key marker and upload ID marker and verify MultipartUploadListing listing = listMpu(s3ClientA, accountA, bucketName, mapEntry.getKey(), mapEntry.getValue().get(i), null, null, null, false); assertTrue( "Expected " + ((tailMap.size() * numUploads) + (numUploads - i - 1)) + " mpu listings, but got " + listing.getMultipartUploads().size(), ((tailMap.size() * numUploads) + (numUploads - i - 1)) == listing.getMultipartUploads() .size()); Iterator<MultipartUpload> mpuIterator = listing.getMultipartUploads().iterator(); for (String uploadId : tailList) { MultipartUpload mpu = mpuIterator.next(); assertTrue("Expected key to be " + mapEntry.getKey() + ", but got " + mpu.getKey(), mpu.getKey().equals(mapEntry.getKey())); assertTrue("Expected upload ID to be " + uploadId + ", but got " + mpu.getUploadId(), mpu.getUploadId().equals(uploadId)); verifyCommonElements(mpu); } for (Entry<String, List<String>> tailMapEntry : tailMap.entrySet()) { for (String uploadId : tailMapEntry.getValue()) { MultipartUpload mpu = mpuIterator.next(); assertTrue("Expected key to be " + tailMapEntry.getKey() + ", but got " + mpu.getKey(), mpu.getKey().equals(tailMapEntry.getKey())); assertTrue("Expected upload ID to be " + uploadId + ", but got " + mpu.getUploadId(), mpu.getUploadId().equals(uploadId)); verifyCommonElements(mpu); } } assertTrue("Expected mpu iterator to be empty", !mpuIterator.hasNext()); } } } catch (AmazonServiceException ase) { printException(ase); assertThat(false, "Failed to run keyMarkerUploadIdMarker"); } }
From source file:com.alibaba.wasp.master.handler.ServerShutdownHandler.java
@Override public void process() throws IOException { final ServerName serverName = this.serverName; try {// w w w . ja va 2 s . c om NavigableMap<EntityGroupInfo, Result> egis = null; while (!this.server.isStopped()) { try { egis = FMetaReader.getServerUserEntityGroups(server.getConfiguration(), this.serverName); break; } catch (IOException ioe) { LOG.info("Received exception accessing META during server shutdown of " + serverName + ", retrying META read", ioe); } } if (this.server.isStopped()) { throw new IOException("Server is stopped"); } // Clean out anything in entityGroups in transition. Being conservative // and // doing after log splitting. Could do some states before -- OPENING? // OFFLINE? -- and then others after like CLOSING that depend on log // splitting. List<EntityGroupState> entityGroupsInTransition = assignmentManager.processServerShutdown(serverName); LOG.info("Reassigning " + ((egis == null) ? 0 : egis.size()) + " entityGroup(s) that " + (serverName == null ? "null" : serverName) + " was carrying (skipping " + entityGroupsInTransition.size() + " entityGroup(s) that are already in transition)"); // Iterate entityGroups that were on this server and assign them if (egis != null) { EntityGroupStates entityGroupStates = assignmentManager.getEntityGroupStates(); List<EntityGroupInfo> toAssignEntityGroups = new ArrayList<EntityGroupInfo>(); for (Map.Entry<EntityGroupInfo, Result> e : egis.entrySet()) { EntityGroupInfo egi = e.getKey(); EntityGroupState egit = entityGroupStates.getEntityGroupTransitionState(egi); if (processDeadEntityGroup(egi, e.getValue(), assignmentManager, server)) { ServerName addressFromAM = entityGroupStates.getFServerOfEntityGroup(egi); if (addressFromAM != null && !addressFromAM.equals(this.serverName)) { // If this entityGroup is in transition on the dead server, it // must be // opening or pending_open, which is covered by // AM#processServerShutdown LOG.debug("Skip assigning entityGroup " + egi.getEntityGroupNameAsString() + " because it has been opened in " + addressFromAM.getServerName()); continue; } if (egit != null) { if (!egit.isOnServer(serverName) || egit.isClosed() || egit.isOpened() || egit.isSplit()) { // Skip entityGroups that are in transition on other server, // or in state closed/opened/split LOG.info("Skip assigning entityGroup " + egit); continue; } try { // clean zk node LOG.info("Reassigning entityGroup with eg = " + egit + " and deleting zk node if exists"); ZKAssign.deleteNodeFailSilent(server.getZooKeeper(), egi); } catch (KeeperException ke) { this.server.abort("Unexpected ZK exception deleting unassigned node " + egi, ke); return; } } toAssignEntityGroups.add(egi); } else if (egit != null) { if (egit.isSplitting() || egit.isSplit()) { // This will happen when the FServer went down and the call back // for // the SPLIITING or SPLIT // has not yet happened for node Deleted event. In that case if // the EntityGroup was actually // split // but the FServer had gone down before completing the split // process // then will not try to // assign the parent EntityGroup again. In that case we should // make the // EntityGroup offline and // also delete the EntityGroup from EGIT. assignmentManager.entityGroupOffline(egi); } else if ((egit.isClosing() || egit.isPendingClose()) && assignmentManager.getZKTable() .isDisablingOrDisabledTable(egi.getTableNameAsString())) { // If the table was partially disabled and the FServer went down, // we // should clear the EGIT // and remove the node for the EntityGroup. // The egit that we use may be stale in case the table was in // DISABLING state // but though we did assign we will not be clearing the znode in // CLOSING state. // Doing this will have no harm. See HBASE-5927 assignmentManager.deleteClosingOrClosedNode(egi); assignmentManager.entityGroupOffline(egi); } else { LOG.warn("THIS SHOULD NOT HAPPEN: unexpected entityGroup in transition " + egit + " not to be assigned by SSH of server " + serverName); } } } try { assignmentManager.assign(toAssignEntityGroups); } catch (InterruptedException ie) { LOG.error("Caught " + ie + " during round-robin assignment"); throw new IOException(ie); } } } finally { this.deadServers.finish(serverName); } LOG.info("Finished processing of shutdown of " + serverName); }
From source file:com.mirth.connect.server.controllers.DonkeyMessageController.java
private List<MessageSearchResult> searchMessages(MessageFilter filter, String channelId, int offset, int limit) { long startTime = System.currentTimeMillis(); FilterOptions filterOptions = new FilterOptions(filter, channelId); long maxMessageId = filterOptions.getMaxMessageId(); long minMessageId = filterOptions.getMinMessageId(); Long localChannelId = ChannelController.getInstance().getLocalChannelId(channelId); Map<String, Object> params = getBasicParameters(filter, localChannelId); try {/*from w w w . j ava2s . c o m*/ NavigableMap<Long, MessageSearchResult> messages = new TreeMap<Long, MessageSearchResult>(); SqlSession session = SqlConfig.getSqlSessionManager(); int offsetRemaining = offset; /* * If the limit is greater than the default batch size, use the limit, but cap it at * 50000. */ long batchSize = Math.min(Math.max(limit, 500), 50000); long totalSearched = 0; while (messages.size() < limit && maxMessageId >= minMessageId) { /* * Slowly increase the batch size in case all the necessary results are found early * on. */ if (totalSearched >= 100000 && batchSize < 50000) { batchSize = 50000; } else if (totalSearched >= 10000 && batchSize < 10000) { batchSize = 10000; } else if (totalSearched >= 1000 && batchSize < 1000) { batchSize = 1000; } /* * Search in descending order so that messages will be found from the greatest to * lowest message id */ long currentMinMessageId = Math.max(maxMessageId - batchSize + 1, minMessageId); params.put("maxMessageId", maxMessageId); params.put("minMessageId", currentMinMessageId); maxMessageId -= batchSize; totalSearched += batchSize; Map<Long, MessageSearchResult> foundMessages = searchAll(session, params, filter, localChannelId, false, filterOptions); if (!foundMessages.isEmpty()) { /* * Skip results until there is no offset remaining. This is required when * viewing results beyond the first page */ if (offsetRemaining >= foundMessages.size()) { offsetRemaining -= foundMessages.size(); } else if (offsetRemaining == 0) { messages.putAll(foundMessages); } else { NavigableMap<Long, MessageSearchResult> orderedMessages = new TreeMap<Long, MessageSearchResult>( foundMessages); while (offsetRemaining-- > 0) { orderedMessages.pollLastEntry(); } messages.putAll(orderedMessages); } } } // Remove results beyond the limit requested while (messages.size() > limit) { messages.pollFirstEntry(); } List<MessageSearchResult> results = new ArrayList<MessageSearchResult>(messages.size()); /* * Now that we have the message and metadata ids that should be returned as the result, * we need to retrieve the message data for those. */ if (!messages.isEmpty()) { Iterator<Long> iterator = messages.descendingKeySet().iterator(); while (iterator.hasNext()) { Map<String, Object> messageParams = new HashMap<String, Object>(); messageParams.put("localChannelId", localChannelId); ListRangeIterator listRangeIterator = new ListRangeIterator(iterator, ListRangeIterator.DEFAULT_LIST_LIMIT, false, null); while (listRangeIterator.hasNext()) { ListRangeItem item = listRangeIterator.next(); List<Long> list = item.getList(); Long startRange = item.getStartRange(); Long endRange = item.getEndRange(); if (list != null || (startRange != null && endRange != null)) { if (list != null) { messageParams.remove("minMessageId"); messageParams.remove("maxMessageId"); messageParams.put("includeMessageList", StringUtils.join(list, ",")); } else { messageParams.remove("includeMessageList"); messageParams.put("minMessageId", endRange); messageParams.put("maxMessageId", startRange); } // Get the current batch of results List<MessageSearchResult> currentResults = session .selectList("Message.selectMessagesById", messageParams); // Add the metadata ids to each result for (MessageSearchResult currentResult : currentResults) { currentResult.setMetaDataIdSet( messages.get(currentResult.getMessageId()).getMetaDataIdSet()); } // Add the current batch to the final list of results results.addAll(currentResults); } } } } return results; } finally { long endTime = System.currentTimeMillis(); logger.debug("Search executed in " + (endTime - startTime) + "ms"); } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testPollLastEntry() { K[] keys = getSortedKeys();//from ww w . java2 s. c o m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); assertNull(map.pollLastEntry()); assertEquals(0, map.size()); map.put(keys[0], values[0]); assertEquals(keys[0], map.pollLastEntry().getKey()); assertEquals(0, map.size()); map.put(keys[0], values[0]); map.put(keys[1], values[1]); assertEquals(keys[1], map.pollLastEntry().getKey()); assertEquals(1, map.size()); Entry<K, V> entry = map.pollLastEntry(); verifyEntry(entry); assertEquals(keys[0], entry.getKey()); assertEquals(0, map.size()); assertNull(map.pollLastEntry()); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testPollFirstEntry() { K[] keys = getSortedKeys();// w w w .ja v a2s . c o m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); assertNull(map.pollFirstEntry()); assertEquals(0, map.size()); map.put(keys[0], values[0]); assertEquals(keys[0], map.pollFirstEntry().getKey()); assertEquals(0, map.size()); map.put(keys[0], values[0]); map.put(keys[1], values[1]); assertEquals(keys[0], map.pollFirstEntry().getKey()); assertEquals(1, map.size()); Entry<K, V> entry = map.pollFirstEntry(); verifyEntry(entry); assertEquals(keys[1], entry.getKey()); assertEquals(0, map.size()); assertNull(map.pollFirstEntry()); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
/** * Test method for 'java.util.SortedMap.headMap(Object)' and * 'java.util.NavigableMap.headMap(Object, boolean)'. * * @see java.util.SortedMap#headMap(Object) * @see java.util.NavigableMap#headMap(Object, boolean) *//* w w w.ja v a 2 s . c om*/ public void testHeadMap_entries_size() { // test with no entries K[] keys = getSortedKeys(); assertEquals(0, createNavigableMap().headMap(keys[0]).size()); NavigableMap<K, V> exclusiveHeadMap = createNavigableMap().headMap(keys[0], false); assertEquals(0, exclusiveHeadMap.size()); assertNull(exclusiveHeadMap.firstEntry()); assertNull(exclusiveHeadMap.lastEntry()); try { assertNull(exclusiveHeadMap.firstKey()); fail(); } catch (NoSuchElementException e) { // expected outcome } try { assertNull(exclusiveHeadMap.lastKey()); fail(); } catch (NoSuchElementException e) { // expected outcome } NavigableMap<K, V> inclusiveHeadMap = createNavigableMap().headMap(keys[0], true); assertEquals(0, inclusiveHeadMap.size()); assertNull(inclusiveHeadMap.firstEntry()); assertNull(inclusiveHeadMap.lastEntry()); try { assertNull(inclusiveHeadMap.firstKey()); fail(); } catch (NoSuchElementException e) { // expected outcome } try { assertNull(inclusiveHeadMap.lastKey()); fail(); } catch (NoSuchElementException e) { // expected outcome } }