List of usage examples for java.util TreeSet size
public int size()
From source file:info.magnolia.cms.core.DefaultContentTest.java
@Test public void testNameFilteringWorksForBothBinaryAndNonBinaryProperties() throws Exception { String contentProperties = StringUtils.join(Arrays.asList("/somepage/mypage@type=mgnl:content", "/somepage/mypage/paragraphs@type=mgnl:contentNode", "/somepage/mypage/paragraphs/0@type=mgnl:contentNode", "/somepage/mypage/paragraphs/0@type=mgnl:contentNode", // 2 regular props "/somepage/mypage/paragraphs/0/attention=booyah", "/somepage/mypage/paragraphs/0/imaginary=date:2009-10-14T08:59:01.227-04:00", // 3 binaries "/somepage/mypage/paragraphs/0/attachment1@type=mgnl:resource", "/somepage/mypage/paragraphs/0/attachment1.fileName=hello", "/somepage/mypage/paragraphs/0/attachment1.extension=gif", // being a binary node, magnolia knows to store data as jcr:data w/o need to be explicitly told so "/somepage/mypage/paragraphs/0/attachment1=binary:X", "/somepage/mypage/paragraphs/0/attachment1.jcr\\:mimeType=image/gif", "/somepage/mypage/paragraphs/0/attachment1.jcr\\:lastModified=date:2009-10-14T08:59:01.227-04:00", "/somepage/mypage/paragraphs/0/attachment2@type=mgnl:resource", "/somepage/mypage/paragraphs/0/attachment2.fileName=test", "/somepage/mypage/paragraphs/0/attachment2.extension=jpeg", "/somepage/mypage/paragraphs/0/attachment2=binary:X", "/somepage/mypage/paragraphs/0/attachment2.jcr\\:mimeType=image/jpeg", "/somepage/mypage/paragraphs/0/attachment2.jcr\\:lastModified=date:2009-10-14T08:59:01.227-04:00", "/somepage/mypage/paragraphs/0/image3@type=mgnl:resource", "/somepage/mypage/paragraphs/0/image3.fileName=third", "/somepage/mypage/paragraphs/0/image3.extension=png", "/somepage/mypage/paragraphs/0/image3=binary:X", "/somepage/mypage/paragraphs/0/image3.jcr\\:mimeType=image/png", "/somepage/mypage/paragraphs/0/image3.jcr\\:lastModified=date:2009-10-14T08:59:01.227-04:00", // and more which should not match "/somepage/mypage/paragraphs/0/foo=bar", "/somepage/mypage/paragraphs/0/mybool=boolean:true", "/somepage/mypage/paragraphs/0/rand@type=mgnl:resource", "/somepage/mypage/paragraphs/0/rand.fileName=randdddd", "/somepage/mypage/paragraphs/0/rand.extension=png", "/somepage/mypage/paragraphs/0/rand=binary:X", "/somepage/mypage/paragraphs/0/rand.jcr\\:mimeType=image/png", "/somepage/mypage/paragraphs/0/rand.jcr\\:lastModified=date:2009-10-14T08:59:01.227-04:00"), "\n"); final HierarchyManager hm = MgnlContext.getHierarchyManager(RepositoryConstants.WEBSITE); new PropertiesImportExport().createContent(hm.getRoot(), IOUtils.toInputStream(contentProperties)); hm.save();/*w w w . ja v a 2 s.c om*/ final Content content = hm.getContent("/somepage/mypage/paragraphs/0"); final Collection<NodeData> props = content.getNodeDataCollection("att*|ima*"); assertEquals(5, props.size()); // sort by name final TreeSet<NodeData> sorted = new TreeSet<NodeData>(new Comparator<NodeData>() { @Override public int compare(NodeData o1, NodeData o2) { return o1.getName().compareTo(o2.getName()); } }); sorted.addAll(props); // sanity check - just recheck we still have 5 elements assertEquals(5, sorted.size()); final Iterator<NodeData> it = sorted.iterator(); final NodeData a = it.next(); final NodeData b = it.next(); final NodeData c = it.next(); final NodeData d = it.next(); final NodeData e = it.next(); assertEquals("attachment1", a.getName()); assertEquals(PropertyType.BINARY, a.getType()); assertEquals("attachment2", b.getName()); assertEquals(PropertyType.BINARY, b.getType()); assertEquals("image3", d.getName()); assertEquals(PropertyType.BINARY, d.getType()); assertEquals("image3", d.getName()); assertEquals(PropertyType.BINARY, d.getType()); assertEquals("attention", c.getName()); assertEquals(PropertyType.STRING, c.getType()); assertEquals("booyah", c.getString()); assertEquals("imaginary", e.getName()); assertEquals(PropertyType.DATE, e.getType()); assertEquals(true, e.getDate().before(Calendar.getInstance())); }
From source file:org.rhwlab.BHC.BHCTree.java
public Set<Nucleus> cutToMinimum(int minNucs, double minVolume, double maxProb) { double logProb = Math.log(maxProb); TreeSet<NucleusLogNode> cut = firstTreeCut(); while (true) { NucleusLogNode[] next = nextTreeCut(cut); if (cut.size() >= minNucs) { // are the next nuclei overlapping Nucleus nuc0 = next[0].getNucleus(time); Nucleus nuc1 = next[1].getNucleus(time); if (nuc0 == null || nuc1 == null || Nucleus.intersect(nuc0, nuc1)) { break; }/*from w w w .j a va 2 s . c o m*/ } if (next[0].getVolume() > minVolume) { cut.add(next[0]); } if (next[1].getVolume() > minVolume) { cut.add(next[1]); } if (next[0].getVolume() > minVolume || next[1].getVolume() > minVolume) { cut.remove(next[2]); } System.out.printf("logProb[0]=%f\n", next[0].getLogPosterior()); System.out.printf("logProb[1]=%f\n", next[1].getLogPosterior()); System.out.printf("logProb[2]=%f\n", next[2].getLogPosterior()); if (next[0].getLogPosterior() == 0.0 && next[1].getLogPosterior() == 0.0) { break; } } Set<Nucleus> ret = new TreeSet<>(); for (NucleusLogNode node : cut) { Nucleus nuc = node.getNucleus(time); nuc.setTime(time); ret.add(nuc); } return ret; }
From source file:org.wso2.andes.kernel.slot.SlotManager.java
/** * Record Slot's last message ID related to a particular queue * * @param queueName name of the queue which this message ID belongs to * @param lastMessageIdInTheSlot last message ID of the slot * @param startMessageIdInTheSlot start message ID of the slot * @param nodeId Node ID of the node that is sending the request. *//*from w w w.j a v a 2 s . c o m*/ public void updateMessageID(String queueName, String nodeId, long startMessageIdInTheSlot, long lastMessageIdInTheSlot) { // Read message Id set for slots from hazelcast TreeSet<Long> messageIdSet = new TreeSet<Long>(); TreeSetLongWrapper wrapper = slotIDMap.get(queueName); if (wrapper == null) { wrapper = new TreeSetLongWrapper(); wrapper.setLongTreeSet(messageIdSet); slotIDMap.putIfAbsent(queueName, wrapper); } messageIdSet = wrapper.getLongTreeSet(); String lockKey = queueName + SlotManager.class; synchronized (lockKey.intern()) { Long lastAssignedMessageId = queueToLastAssignedIDMap.get(queueName); // Check if input slot's start message ID is less than last assigned message ID if ((null != lastAssignedMessageId) && startMessageIdInTheSlot < lastAssignedMessageId) { if (log.isDebugEnabled()) { log.debug("Found overlapping slots during slot submit: " + startMessageIdInTheSlot + " to : " + lastMessageIdInTheSlot + ". Comparing to lastAssignedID : " + lastAssignedMessageId); } // Find overlapping slots TreeSet<Slot> overlappingSlots = getOverlappedAssignedSlots(queueName, startMessageIdInTheSlot, lastMessageIdInTheSlot); if (overlappingSlots.size() > 0) { if (log.isDebugEnabled()) { log.debug("Found " + overlappingSlots.size() + " overlapping slots."); } // Following means that we have a piece of the slot exceeding the earliest // assigned slot. breaking that piece and adding it as a new,unassigned slot. if (startMessageIdInTheSlot < overlappingSlots.first().getStartMessageId()) { Slot leftExtraSlot = new Slot(startMessageIdInTheSlot, overlappingSlots.first().getStartMessageId() - 1, queueName); if (log.isDebugEnabled()) { log.debug("LeftExtra Slot in overlapping slots : " + leftExtraSlot); } } // This means that we have a piece of the slot exceeding the latest assigned slot. // breaking that piece and adding it as a new,unassigned slot. if (lastMessageIdInTheSlot > overlappingSlots.last().getEndMessageId()) { Slot rightExtraSlot = new Slot(overlappingSlots.last().getEndMessageId() + 1, lastMessageIdInTheSlot, queueName); if (log.isDebugEnabled()) { log.debug("RightExtra in overlapping slot : " + rightExtraSlot); } //Update last message ID - expand ongoing slot to cater this leftover part. messageIdSet.add(lastMessageIdInTheSlot); wrapper.setLongTreeSet(messageIdSet); slotIDMap.set(queueName, wrapper); if (log.isDebugEnabled()) { log.debug(lastMessageIdInTheSlot + " added to slotIdMap " + "(RightExtraSlot). Current values in " + "map " + messageIdSet); } //record last published message id nodeToLastPublishedIDMap.set(nodeId, lastMessageIdInTheSlot); } } } else { /** * Update the slotIDMap only if the last assigned message ID is less than the new start message ID */ messageIdSet.add(lastMessageIdInTheSlot); wrapper.setLongTreeSet(messageIdSet); slotIDMap.set(queueName, wrapper); if (log.isDebugEnabled()) { log.debug("No overlapping slots found during slot submit " + startMessageIdInTheSlot + " to : " + lastMessageIdInTheSlot + ". Added msgID " + lastMessageIdInTheSlot + " to slotIDMap"); } //record last published message ID nodeToLastPublishedIDMap.set(nodeId, lastMessageIdInTheSlot); } } }
From source file:org.wso2.andes.kernel.slot.SlotManagerClusterMode.java
/** * Record Slot's last message ID related to a particular queue * * @param queueName name of the queue which this message ID belongs to * @param lastMessageIdInTheSlot last message ID of the slot * @param startMessageIdInTheSlot start message ID of the slot * @param nodeId Node ID of the node that is sending the request. * @param localSafeZone Local safe zone of the requesting node. *//*from w w w . jav a 2s .co m*/ public void updateMessageID(String queueName, String nodeId, long startMessageIdInTheSlot, long lastMessageIdInTheSlot, long localSafeZone) throws AndesException { //setting up first message id of the slot if (firstMessageId > startMessageIdInTheSlot || firstMessageId == -1) { firstMessageId = startMessageIdInTheSlot; } if (slotRecoveryScheduled.get()) { queuesToRecover.remove(queueName); } // Read message Id set for slots from store TreeSet<Long> messageIdSet; messageIdSet = slotAgent.getSlotBasedMessageIds(queueName); String lockKey = queueName + SlotManagerClusterMode.class; synchronized (lockKey.intern()) { //Get last assigned message id from database long lastAssignedMessageId = slotAgent.getQueueToLastAssignedId(queueName); // Check if input slot's start message ID is less than last assigned message ID if (startMessageIdInTheSlot < lastAssignedMessageId) { if (log.isDebugEnabled()) { log.debug("Found overlapping slots during slot submit: " + startMessageIdInTheSlot + " to : " + lastMessageIdInTheSlot + ". Comparing to lastAssignedID : " + lastAssignedMessageId); } // Find overlapping slots TreeSet<Slot> overlappingSlots = getOverlappedAssignedSlots(queueName, startMessageIdInTheSlot, lastMessageIdInTheSlot); if (!(overlappingSlots.isEmpty())) { if (log.isDebugEnabled()) { log.debug("Found " + overlappingSlots.size() + " overlapping slots."); } // Following means that we have a piece of the slot exceeding the earliest // assigned slot. breaking that piece and adding it as a new,unassigned slot. if (startMessageIdInTheSlot < overlappingSlots.first().getStartMessageId()) { Slot leftExtraSlot = new Slot(startMessageIdInTheSlot, overlappingSlots.first().getStartMessageId() - 1, queueName); if (log.isDebugEnabled()) { log.debug("Left Extra Slot in overlapping slots : " + leftExtraSlot); } } // This means that we have a piece of the slot exceeding the latest assigned slot. // breaking that piece and adding it as a new,unassigned slot. if (lastMessageIdInTheSlot > overlappingSlots.last().getEndMessageId()) { Slot rightExtraSlot = new Slot(overlappingSlots.last().getEndMessageId() + 1, lastMessageIdInTheSlot, queueName); if (log.isDebugEnabled()) { log.debug("RightExtra in overlapping slot : " + rightExtraSlot); } //Update last message ID - expand ongoing slot to cater this leftover part. slotAgent.addMessageId(queueName, lastMessageIdInTheSlot); if (log.isDebugEnabled()) { log.debug(lastMessageIdInTheSlot + " added to store " + "(RightExtraSlot). Current values in " + "store " + messageIdSet); } } } else { /* * The fact that the slot ended up in this condition means that, all previous slots within this * range have been already processed and deleted. This is a very rare scenario. */ if (log.isDebugEnabled()) { log.debug("A submit slot request has come from the past after deletion of any " + "possible overlapping slots. nodeId : " + nodeId + " StartMessageID : " + startMessageIdInTheSlot + " EndMessageID : " + lastMessageIdInTheSlot); } slotAgent.addMessageId(queueName, lastMessageIdInTheSlot); } } else { //Update the store only if the last assigned message ID is less than the new start message ID slotAgent.addMessageId(queueName, lastMessageIdInTheSlot); if (log.isDebugEnabled()) { log.debug("No overlapping slots found during slot submit " + startMessageIdInTheSlot + " to : " + lastMessageIdInTheSlot + ". Added msgID " + lastMessageIdInTheSlot + " to store"); } } //record local safe zone slotAgent.setLocalSafeZoneOfNode(nodeId, localSafeZone); } }
From source file:org.jtrfp.trcl.obj.SmokeSystem.java
private boolean isNewSmokeFeasible(final Vector3D loc, SmokeType type) { final TreeSet<Smoke> proximalSmokes = new TreeSet<Smoke>(new Comparator<Smoke>() { @Override//w w w .j ava2 s . c o m public int compare(Smoke o1, Smoke o2) { return Misc.satCastInt(o1.getTimeOfLastReset() - o2.getTimeOfLastReset()); } }); for (int smokeTypeIndex = 0; smokeTypeIndex < allSmokes.length; smokeTypeIndex++) { Smoke[] explosionsOfThisType = allSmokes[smokeTypeIndex]; for (Smoke thisSmoke : explosionsOfThisType) { if (thisSmoke.isActive()) { final double distance = new Vector3D(thisSmoke.getPosition()).distance(loc); if (distance < 1000) return false; if (distance < OneShotBillboardEvent.PROXIMITY_TEST_DIST) proximalSmokes.add(thisSmoke); } // end if(isActive) } // end for(explosionsOfThisType) } // end for(explosions) if (proximalSmokes.size() + 1 > OneShotBillboardEvent.MAX_PROXIMAL_EVENTS) proximalSmokes.first().destroy();// Destroy oldest return true; }
From source file:org.jcamp.parser.CommonSpectrumJCAMPReader.java
License:asdf
/** * gets ##XYPOINTS= content/*from w ww. j av a2s .co m*/ * * @return double[] * @param block JCAMPBlock * @param nPoints int number of data points (from ##NPOINTS=) * @exception JCAMPException The exception description. */ protected double[][] getXYPoints(JCAMPBlock block, int nPoints, double xFactor, double yFactor) throws JCAMPException { class XYPair implements Comparable<XYPair> { public double x; public double y; public XYPair(double x, double y) { this.x = x; this.y = y; } @Override public int compareTo(XYPair o) { XYPair p = o; if (this.x < p.x) { return -1; } if (this.x > p.x) { return 1; } return 0; } } ; JCAMPDataRecord ldrXYPoints = block.getDataRecord("XYPOINTS"); if (ldrXYPoints == null) { throw new JCAMPException("missing required label ##XYPOINTS="); } int i = 0; AFFNTokenizer tokenizer = new AFFNTokenizer(ldrXYPoints); TreeSet<XYPair> data = new TreeSet<XYPair>(); while (tokenizer.hasMoreGroups()) { AFFNGroup group = tokenizer.nextGroup(); data.add(new XYPair(xFactor * group.getValue(0), yFactor * group.getValue(1))); } if (data.size() != nPoints) { if (log.isErrorEnabled()) { log.error("bad ##NPOINTS= or duplicate X values"); } } double[][] xy = new double[2][data.size()]; for (Iterator<XYPair> it = data.iterator(); it.hasNext();) { XYPair p = it.next(); xy[0][i] = p.x; xy[1][i] = p.y; } return xy; }
From source file:net.certiv.authmgr.task.section.model.AnalyzeModel.java
private void analyzeWords(String category, String partition, HashMap<String, WordProbabilityPT> wordsMap) { // convert to sorted set WordProbPTComparator sorter = new WordProbPTComparator(); TreeSet<WordProbabilityPT> wordProbs = new TreeSet<WordProbabilityPT>(sorter); wordProbs.addAll(wordsMap.values()); // now accumulate and print statistics StringBuffer wordlist = new StringBuffer(); int k = 0;/*from w ww. ja v a 2 s . c o m*/ for (Iterator<WordProbabilityPT> it = wordProbs.iterator(); it.hasNext() && k < 20; k++) { WordProbabilityPT wp = it.next(); String word = wp.getWord(); double prob = wp.getProbability(); double count = wp.getMatchingCount(); BigDecimal probBD = new BigDecimal(prob).setScale(8, BigDecimal.ROUND_HALF_UP); String countStr = Util.rightAlign("" + count, 6); String wordAbbr = StringUtils.abbreviate(word, 13); wordlist.append(Util.leftAlign(wordAbbr, 14) + probBD + "/" + countStr + "| "); } Log.info(this, Util.leftAlign(partition + ":", 14) + Util.rightAlign("" + wordProbs.size(), 5) + " = " + wordlist.toString()); }
From source file:com.excilys.soja.server.handler.ServerHandler.java
/** * Handle SEND command/* www . ja v a 2 s .c om*/ * * @param sendFrame * @throws SocketException */ public void handleSend(Channel channel, Frame sendFrame) throws SocketException { String topic = sendFrame.getHeaderValue(HEADER_DESTINATION); synchronized (authentication) { if (!authentication.canSend(clientsSessionToken.get(channel), topic)) { sendError(channel, "Can't send message", "You're not allowed to send a message to the topic" + topic); return; } } // Retrieve subscribers for the given topic Set<Subscription> subscriptions = null; subscriptions = subscriptionManager.retrieveSubscriptionsByTopic(topic); if (subscriptions != null && subscriptions.size() > 0) { // Construct the MESSAGE frame MessageFrame messageFrame = new MessageFrame(topic, sendFrame.getBody(), null); // Add content-type if it was present on the SEND command String contentType = sendFrame.getHeaderValue(HEADER_CONTENT_TYPE); if (contentType != null) { messageFrame.setContentType(contentType); } // Add user keys if there was some on the SEND command Set<String> userKeys = sendFrame.getHeader().allKeys(SEND_USER_HEADERS_FILTER); for (String userKey : userKeys) { messageFrame.getHeader().put(userKey, sendFrame.getHeaderValue(userKey)); } // Create a set of subscription which will be used for ACKs requests TreeSet<Long> acks = new TreeSet<Long>(); // Send the message frame to each subscriber for (Subscription subscription : subscriptions) { // If an ack is needed for this client, add the subscription to the ACKs queue. if (subscription.getAckMode() != Ack.AUTO) { acks.add(subscription.getSubscriptionId()); } messageFrame.setHeaderValue(HEADER_SUBSCRIPTION, subscription.getSubscriptionId().toString()); sendFrame(subscription.getChannel(), messageFrame); } if (acks.size() > 0) { synchronized (waitingAcks) { String messageId = messageFrame.getMessageId(); waitingAcks.put(messageId, new AckWaiting(channel, acks, sendFrame)); } } else { sendReceiptIfRequested(channel, sendFrame); return; } } sendReceiptIfRequested(channel, sendFrame); }
From source file:org.eclipse.gyrex.admin.ui.http.internal.EditApplicationDialog.java
@Override protected Control createDialogArea(final Composite parent) { final Composite composite = (Composite) super.createDialogArea(parent); final GridData gd = (GridData) composite.getLayoutData(); gd.minimumHeight = convertVerticalDLUsToPixels(200); gd.minimumWidth = convertHorizontalDLUsToPixels(400); idField.setLabelText("Id"); contextPathField.setLabelText("Context"); providerField.setLabelText("Provider"); final IDialogFieldListener validateListener = new IDialogFieldListener() { @Override/* ww w . j a v a 2 s. c o m*/ public void dialogFieldChanged(final DialogField field) { validate(); } }; idField.setDialogFieldListener(validateListener); contextPathField.setDialogFieldListener(validateListener); providerField.setDialogFieldListener(validateListener); providerItemToIdMap.clear(); final TreeSet<String> providerItems = new TreeSet<String>(); final Collection<ApplicationProviderRegistration> providers = HttpActivator.getInstance() .getProviderRegistry().getRegisteredProviders().values(); for (final ApplicationProviderRegistration registration : providers) { final String label = HttpUiAdapter.getLabel(registration); providerItemToIdMap.put(label, registration.getProviderId()); providerItems.add(label); } providerField.setItems(providerItems.toArray(new String[providerItems.size()])); contextPathField.setContentProposalProcessor(new IContentProposalProvider() { /** serialVersionUID */ private static final long serialVersionUID = 1L; @Override public IContentProposal[] getProposals(final String contents, final int position) { final List<IContentProposal> resultList = new ArrayList<IContentProposal>(); final String patternString = StringUtils.trimToNull(StringUtils.substring(contents, 0, position)); final Collection<ContextDefinition> contexts = ContextActivator.getInstance() .getContextRegistryImpl().getDefinedContexts(); for (final ContextDefinition contextDefinition : contexts) { if ((null == patternString) || StringUtils.contains(contextDefinition.getPath().toString(), patternString)) { resultList.add(new ContentProposal(contextDefinition.getPath().toString(), contextDefinition.toString())); } } return resultList.toArray(new IContentProposal[resultList.size()]); } }); propertiesField.setLabelText("Properties"); mountsField.setLabelText("Mounts"); final Text warning = new Text(composite, SWT.WRAP | SWT.READ_ONLY); warning.setText( "Warning: this dialog is ugly. Please help us improve the UI. Any mockups and/or patches are very much appreciated!"); warning.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); LayoutUtil.doDefaultLayout(composite, new DialogField[] { new Separator(), idField, providerField, contextPathField, new Separator(), propertiesField, mountsField }, false); LayoutUtil.setHorizontalGrabbing(idField.getTextControl(null)); LayoutUtil.setHorizontalGrabbing(providerField.getComboControl(null)); LayoutUtil.setHorizontalGrabbing(contextPathField.getTextControl(null)); LayoutUtil.setHorizontalGrabbing(propertiesField.getListControl(null)); LayoutUtil.setHorizontalGrabbing(mountsField.getListControl(null)); if (null != applicationRegistration) { idField.setText(applicationRegistration.getApplicationId()); idField.setEnabled(false); contextPathField.setText(applicationRegistration.getContext().getContextPath().toString()); contextPathField.setEnabled(false); for (final Entry<String, String> e : providerItemToIdMap.entrySet()) { if (e.getValue().equals(applicationRegistration.getProviderId())) { providerField.selectItem(e.getKey()); } } providerField.setEnabled(false); applicationProperties.putAll(applicationRegistration.getInitProperties()); mountsField.setElements(applicationManager.getMounts(applicationRegistration.getApplicationId())); } refreshProperties(); final GridLayout masterLayout = (GridLayout) composite.getLayout(); masterLayout.marginWidth = 5; masterLayout.marginHeight = 5; LayoutUtil.setHorizontalSpan(warning, masterLayout.numColumns); return composite; }
From source file:org.apache.hadoop.hdfs.server.namenode.NamenodeFsck.java
private DatanodeInfo bestNode(DFSClient dfs, DatanodeInfo[] nodes, TreeSet<DatanodeInfo> deadNodes) throws IOException { if ((nodes == null) || (nodes.length - deadNodes.size() < 1)) { throw new IOException("No live nodes contain current block"); }//from w ww. j a v a 2 s .c om DatanodeInfo chosenNode; do { chosenNode = nodes[DFSUtil.getRandom().nextInt(nodes.length)]; } while (deadNodes.contains(chosenNode)); return chosenNode; }