List of usage examples for java.util NavigableMap pollFirstEntry
Map.Entry<K, V> pollFirstEntry();
From source file:in.java
public static void main(String[] args) { NavigableMap<Integer, String> map = new TreeMap<Integer, String>(); map.put(2, "two"); map.put(1, "one"); map.put(3, "three"); System.out.println("Original map: " + map + "\n"); Entry firstEntry = map.pollFirstEntry(); System.out.println("First entry: " + firstEntry); System.out.println("After polling the first entry: " + map + "\n"); Entry lastEntry = map.pollLastEntry(); System.out.println("Last entry:" + lastEntry); System.out.println("After polling last entry:" + map); }
From source file:NavigableMapDemo.java
public static void main(String[] args) { NavigableMap<Integer, String> map = new TreeMap<Integer, String>(); map.put(2, "two"); map.put(1, "one"); map.put(3, "three"); System.out.println("Original map: " + map + "\n"); Entry firstEntry = map.pollFirstEntry(); System.out.println("First entry: " + firstEntry); System.out.println("After polling the first entry: " + map + "\n"); Entry lastEntry = map.pollLastEntry(); System.out.println("Last entry:" + lastEntry); System.out.println("After polling last entry:" + map); }
From source file:Main.java
public static void main(String[] args) { NavigableMap<String, Integer> navigableMap = new TreeMap<String, Integer>(); String[] letters = { "a", "b", "c" }; int[] ints = { 3, 2, 1 }; for (int i = 0; i < letters.length; i++) { navigableMap.put(letters[i], ints[i]); }/* www.j a va 2 s . c om*/ System.out.println("Map = " + navigableMap); System.out.println("Poll first entry: " + navigableMap.pollFirstEntry()); }
From source file:fi.aalto.hacid.HAcidTxn.java
/** * Rebuilds the HAcidTxn that generated the transaction commit data at the * row given by the Get result.//w w w . j av a 2s . c om * * @param client * @param rowkey * @return */ static HAcidTxn restore(HAcidClient client, Result endTimestampResult) throws IOException { HAcidTxn restoredTxn = lightRestore(client, endTimestampResult); // Restore writes NavigableMap<byte[], byte[]> writeset = endTimestampResult.getFamilyMap(Schema.FAMILY_WRITESET); Entry<byte[], byte[]> writeEntry; while ((writeEntry = writeset.pollFirstEntry()) != null) { HAcidPut pput = HAcidPut.restore(Bytes.toString(writeEntry.getKey()), client.configuration_HBase, restoredTxn.start_ts); restoredTxn.writes.add(pput); } // Restore reads NavigableMap<byte[], byte[]> readset = endTimestampResult.getFamilyMap(Schema.FAMILY_READSET); Entry<byte[], byte[]> readEntry; while ((readEntry = readset.pollFirstEntry()) != null) { HAcidGet pget = HAcidGet.restore(Bytes.toString(readEntry.getKey()), client.configuration_HBase); restoredTxn.reads.add(pget); } return restoredTxn; }
From source file:com.ikon.servlet.admin.PropertyGroupsServlet.java
/** * Puts the parameterMap into the NavigableMap. The map is polled first twice to save action and label. Then the resulting * array values is saved as a linkedHashMap to save order. * @param request/*w ww .ja v a2s. co m*/ * @param response * @throws Exception */ private void writeToPropertyGroupsXML(HttpServletRequest request, HttpServletResponse response) throws Exception { //get values from form and sort it using navigableSet NavigableMap<String, String[]> propertyGroupMap = new TreeMap<String, String[]>(request.getParameterMap()); String action = propertyGroupMap.pollFirstEntry().getValue()[0]; String propertyGroupLabel = propertyGroupMap.pollFirstEntry().getValue()[0]; Map<String, String> propertyMap = new LinkedHashMap<String, String>(); for (String[] values : propertyGroupMap.values()) { propertyMap.put(values[0], values[1]); } XMLUtils xmlUtils = new XMLUtils(PROPERTY_GROUPS_XML); if (action.equals("register")) { xmlUtils.addPropertyGroup(propertyGroupLabel, propertyMap); } else if (action.equals("edit")) { xmlUtils.editPropertyGroup(propertyGroupLabel, propertyMap); } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testPollFirstEntry() { K[] keys = getSortedKeys();// w ww . ja v a 2 s.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.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 ww .j a va 2 s. c om*/ 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"); } }