List of usage examples for java.util TreeMap values
public Collection<V> values()
From source file:org.eclipse.gyrex.cloud.internal.queue.ZooKeeperQueue.java
@Override public List<IMessage> receiveMessages(final int maxNumberOfMessages, final Map<String, ?> properties) throws IllegalArgumentException, IllegalStateException, SecurityException { /*/*from w ww . j a v a 2s . co m*/ * We want to get the node with the smallest sequence number. But * other clients may remove and add nodes concurrently. Thus, we * need to further check if the node can be returned. It might be * gone by the time we check. If that happens we just continue with * the next node. */ if (maxNumberOfMessages <= 0) { throw new IllegalArgumentException("maxNumberOfMessages must be greate than zero"); } final List<IMessage> messages = new ArrayList<IMessage>(maxNumberOfMessages); try { // get timeout final long receiveMessageTimeout = getReceiveMessageTimeout(properties); // iterate over all children final TreeMap<Long, String> queueChildren = readQueueChildren(null); for (final String childName : queueChildren.values()) { if (childName != null) { // read message final Message message = readQueueMessage(childName); // check if we have a valid message if ((message == null) || message.isHidden()) { continue; } // try to receive the message if (!message.receive(receiveMessageTimeout, false)) { continue; } // message received messages.add(message); // stop if enough if (messages.size() >= maxNumberOfMessages) { return messages; } } } } catch (final Exception e) { if (e instanceof KeeperException.NoNodeException) { throw new IllegalStateException(String.format("queue '%s' does not exist", id)); } throw new QueueOperationFailedException(id, "RECEIVE_MESSAGES", e); } return messages; }
From source file:com.earnstone.index.ShardedIndex.java
protected void saveShardsCache(TreeMap<T, T> map) { byte[] raw = getBytesForDataList(new ArrayList<T>(map.values())); Mutator<byte[]> mutator = HFactory.createMutator(keyspace, BytesArraySerializer.get()); mutator.insert(baseIndexKey, columnFamily, HFactory.createColumn(getShardColumnName(), raw, getColumnNameSerializer(), BytesArraySerializer.get())); }
From source file:com.sfs.whichdoctor.dao.VoteDAOImpl.java
/** * This method loads the eligible votes for a particular group of people It * is built on top of the items functionality, the significant difference * being only one vote can be cast by each person in the group. * * @param groupGUID the group guid/* w w w .jav a 2s .c o m*/ * * @return the tree map< integer, integer> * * @throws WhichDoctorDaoException the which doctor dao exception */ public final TreeMap<Integer, Integer> loadEligible(final int groupGUID) throws WhichDoctorDaoException { if (groupGUID == 0) { throw new WhichDoctorDaoException("Sorry a group guid greater than 0 is required"); } TreeMap<Integer, Integer> eligibleVotes = new TreeMap<Integer, Integer>(); /* * Load the group with its items to build a map of which members are * allowed to vote */ try { BuilderBean loadDetails = new BuilderBean(); loadDetails.setParameter("ITEMS", true); GroupBean group = this.groupDAO.loadGUID(groupGUID, loadDetails); TreeMap<String, ItemBean> items = group.getItems(); if (items != null) { for (ItemBean item : items.values()) { int voterId = PersonBean.getVoteNumber(item.getObject2GUID(), group.getYear()); eligibleVotes.put(voterId, voterId); } } } catch (Exception e) { dataLogger.error("Error loading group: " + e.getMessage()); } return eligibleVotes; }
From source file:util.ExpiringObjectPool.java
/** * Sweep through each queue looking and marking expired objects. * Since we are using TreeMap, if we don't find expired objects in * a queue, we break out of the loop, as the objects are in sorted * ascending order of entry date./*w ww .j a va 2 s . c o m*/ */ private synchronized void sweep() { if (disablePool) return; if (objectMap == null) return; Iterator iter = objectMap.values().iterator(); while (iter.hasNext()) { long ctime = System.currentTimeMillis(); TreeMap beanMap = (TreeMap) iter.next(); Iterator iter1 = beanMap.values().iterator(); while (iter1.hasNext()) { Stringifier bean = (Stringifier) iter1.next(); if (((Boolean) bean.getObject(POOL)).booleanValue()) { long age = ((Long) bean.getObject(AGE)).longValue(); if (((ctime - age) / MSEC) > expiryInSecs) { bean.setObject(POOL, new Boolean(false)); StringBuffer sb = new StringBuffer("Expiring bean "); sb.append(bean.getClass().getName()); sb.append(" ("); sb.append(bean.hashCode()); sb.append(")"); sb.append(bean.toString()); logger.info(sb.toString()); } else break; } } } }
From source file:com.alkacon.opencms.counter.CmsCounterDialog.java
/** * This function compares the list from the dialog with the list from the database and * update the list from the database with the values from the dialog.<p> * /* w ww. j ava 2 s .c o m*/ * @param counterList the list from the dialog * * @throws Exception if an Exception occurred. */ private void updateCounterValues(SortedMap counterList) throws Exception { if (m_manager == null) { m_manager = getCounterManager(); } // get the counters from the database TreeMap map = m_manager.getCounters(); Iterator iteratork = map.keySet().iterator(); Iterator iterator = map.values().iterator(); // for each entry check if its changed or deleted int o_value; int new_value; String o_key; while (iterator.hasNext() && iteratork.hasNext()) { o_value = getIntValue(iterator.next()); o_key = (String) iteratork.next(); if (counterList.containsKey(o_key)) { // the value exits new_value = getIntValue(counterList.get(o_key)); if (o_value != new_value) { if ((o_value < new_value) || (o_value > new_value && m_overwrite)) { m_manager.setCounter(o_key, new_value); } counterList.remove(o_key); } else { counterList.remove(o_key); } } else { // the value is deleted m_manager.deleteCounter(o_key); } } // now the new values is adding to the database if (!counterList.isEmpty()) { iteratork = counterList.keySet().iterator(); iterator = counterList.values().iterator(); while (iterator.hasNext() && iteratork.hasNext()) { o_value = getIntValue(iterator.next()); o_key = (String) iteratork.next(); m_manager.setCounter(o_key, o_value); } } }
From source file:org.eclipse.gyrex.cloud.internal.queue.ZooKeeperQueue.java
/** * Returns the ordered list of messages. * <p>/*from w w w. jav a2s . c o m*/ * Note, this represents a snapshot of the queue at the time of invoking the * method. * </p> * * @return ordered list of messages */ public List<Message> getMessages() { try { final TreeMap<Long, String> queueChildren = readQueueChildren(null); final List<Message> messages = new ArrayList<Message>(queueChildren.size()); for (final String messageId : queueChildren.values()) { final Message message = readQueueMessage(messageId); if (null != message) { messages.add(message); } } return messages; } catch (final NoNodeException e) { // don't fail just return null return Collections.emptyList(); } catch (final Exception e) { throw new QueueOperationFailedException(id, "READ_MESSAGES", e); } }
From source file:org.openmicroscopy.shoola.agents.measurement.view.ObjectManager.java
/** Rebuilds Tree */ void rebuildTable() { TreeMap<Long, ROI> roiList = model.getROI(); Iterator<ROI> iterator = roiList.values().iterator(); ROI roi;/*from ww w . j a v a2 s .c o m*/ TreeMap<Coord3D, ROIShape> shapeList; Iterator<ROIShape> shapeIterator; objectsTable.clear(); while (iterator.hasNext()) { roi = iterator.next(); shapeList = roi.getShapes(); shapeIterator = shapeList.values().iterator(); while (shapeIterator.hasNext()) objectsTable.addROIShape(shapeIterator.next()); } objectsTable.collapseAll(); }
From source file:com.celements.menu.MenuService.java
public List<BaseObject> getMenuHeaders() { LOGGER.trace("getMenuHeaders_internal start"); TreeMap<Integer, BaseObject> menuHeadersMap = new TreeMap<Integer, BaseObject>(); addMenuHeaders(menuHeadersMap);/*from w w w . jav a 2 s. c om*/ getContext().setDatabase("celements2web"); addMenuHeaders(menuHeadersMap); getContext().setDatabase(getContext().getOriginalDatabase()); ArrayList<BaseObject> resultList = new ArrayList<BaseObject>(); resultList.addAll(menuHeadersMap.values()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("getMenuHeaders_internal returning: " + Arrays.deepToString(resultList.toArray())); } LOGGER.debug("getMenuHeaders_internal end"); return resultList; }
From source file:de.vandermeer.skb.interfaces.application.App_CliParser.java
/** * Prints usage information for the CLI parser including all CLI options. * @param width the console columns or width of each output line * @return list of lines with usage information *//* w w w . j av a 2 s .c o m*/ default ArrayList<StrBuilder> usage(int width) { TreeMap<String, ApoBaseC> map = CliOptionList.sortedMap(this.getAllOptions(), this.numberShort(), this.numberLong()); Map<String, String> helpMap = new LinkedHashMap<>(); int length = 0; STGroupFile stg = new STGroupFile("de/vandermeer/skb/interfaces/application/help.stg"); for (Object option : map.values()) { ST sto = stg.getInstanceOf("option"); String description = null; if (ClassUtils.isAssignable(option.getClass(), Apo_SimpleC.class)) { sto.add("cliShort", ((Apo_SimpleC) option).getCliShort()); sto.add("cliLong", ((Apo_SimpleC) option).getCliLong()); description = ((Apo_SimpleC) option).getDescription(); } if (ClassUtils.isAssignable(option.getClass(), Apo_TypedC.class)) { sto.add("cliShort", ((Apo_TypedC<?>) option).getCliShort()); sto.add("cliLong", ((Apo_TypedC<?>) option).getCliLong()); sto.add("argName", ((Apo_TypedC<?>) option).getCliArgumentName()); sto.add("argOptional", ((Apo_TypedC<?>) option).cliArgIsOptional()); description = ((Apo_TypedC<?>) option).getDescription(); } String line = sto.render(); if (line.length() > length) { length = line.length(); } helpMap.put(line, description); } length += 4; ArrayList<StrBuilder> ret = new ArrayList<>(); for (Entry<String, String> entry : helpMap.entrySet()) { StrBuilder argLine = new StrBuilder(); argLine.append(entry.getKey()).appendPadding(length - argLine.length(), ' '); StrBuilder padLine = new StrBuilder(); padLine.appendPadding(length, ' '); Collection<StrBuilder> text = Text_To_FormattedText.left(entry.getValue(), width - length); int i = 0; for (StrBuilder b : text) { if (i == 0) { b.insert(0, argLine); } else { b.insert(0, padLine); } ret.add(b); i++; } } return ret; }
From source file:tor.Consensus.java
/** * Return the routers with all of the supplied flags and the specified exitPort, optionally excluding bad exits. * See https://consensus-health.torproject.org for a list of known flags. * * @param flags the desired flags (case-sensitive) * @param exitPort the desired exit port in the router's exit policy (or 0 to ignore exit policies) * @param excludeBadExits exclude routers with the BadExit flags (these are considered unreliable for some purposes) * @return a random router with the specified flags *///from ww w. j av a 2 s .c o m public OnionRouter getRandomORWithFlag(String[] flags, int exitPort, Boolean excludeBadExits) { TreeMap<String, OnionRouter> map = getORsWithFlag(flags, excludeBadExits); OnionRouter ors[] = map.values().toArray(new OnionRouter[map.size()]); boolean acceptsExitPort = false; int idx = TorCrypto.rnd.nextInt(ors.length); // ignore exitPort 0 if (exitPort != 0) { // iterate through the routers until we find one that accepts the desired exitPort do { idx = TorCrypto.rnd.nextInt(ors.length); acceptsExitPort = ors[idx].acceptsIPv4ExitPort(exitPort); } while (!acceptsExitPort); } return ors[idx]; }