List of usage examples for java.util TreeSet first
public E first()
From source file:org.jtrfp.trcl.obj.ExplosionSystem.java
private boolean isNewExplosionFeasible(final Vector3D loc, ExplosionType type) { final TreeSet<Explosion> proximalExplosions = new TreeSet<Explosion>(new Comparator<Explosion>() { @Override/*from w w w . j av a 2s. co m*/ public int compare(Explosion o1, Explosion o2) { return Misc.satCastInt(o1.getTimeOfLastReset() - o2.getTimeOfLastReset()); } }); for (int explosionTypeIndex = 0; explosionTypeIndex < allExplosions.length; explosionTypeIndex++) { Explosion[] explosionsOfThisType = allExplosions[explosionTypeIndex]; for (Explosion thisExplosion : explosionsOfThisType) { if (thisExplosion.isActive()) { final double distance = new Vector3D(thisExplosion.getPosition()).distance(loc); if (distance < 1000) return false; if (distance < OneShotBillboardEvent.PROXIMITY_TEST_DIST) proximalExplosions.add(thisExplosion); } // end if(isActive) } // end for(explosionsOfThisType) } // end for(explosions) if (proximalExplosions.size() + 1 > OneShotBillboardEvent.MAX_PROXIMAL_EVENTS) proximalExplosions.first().destroy();//Destroy oldest return true; }
From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java
public GerritChangeVO getLastUnverifiedChange() throws RepositoryException { log.debug("getLastUnverifiedChange()..."); Set<GerritChangeVO> changes = getGerritChangeInfo(); TreeSet<GerritChangeVO> treeSet = new TreeSet<GerritChangeVO>(new SortByUnVerifiedLastUpdate()); treeSet.addAll(changes);/*from w w w . j a v a2 s . co m*/ if ((treeSet.size() > 0) && (treeSet.first().getVerificationScore() == 0)) return treeSet.first(); return null; }
From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java
public GerritChangeVO getLastUnverifiedChange(String project) throws RepositoryException { log.debug(String.format("getLastUnverifiedChange(project=%s)...", project)); Set<GerritChangeVO> changes = getGerritChangeInfo(project); TreeSet<GerritChangeVO> treeSet = new TreeSet<GerritChangeVO>(new SortByUnVerifiedLastUpdate()); treeSet.addAll(changes);/*from w w w . ja va2 s . com*/ if ((treeSet.size() > 0) && (treeSet.first().getVerificationScore() == 0)) return treeSet.first(); return null; }
From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java
public GerritChangeVO getLastUnverifiedChange(String project, String branch) throws RepositoryException { log.debug(String.format("getLastUnverifiedChange(project=%s)...", project)); Set<GerritChangeVO> changes = getGerritChangeInfo(project, branch); TreeSet<GerritChangeVO> treeSet = new TreeSet<GerritChangeVO>(new SortByUnVerifiedLastUpdate()); treeSet.addAll(changes);//from w w w. j a v a2 s . c o m if ((treeSet.size() > 0) && (treeSet.first().getVerificationScore() == 0)) return treeSet.first(); return null; }
From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java
public GerritChangeVO getLastChange() throws RepositoryException { log.debug("getLastChange()..."); Set<GerritChangeVO> changes = getGerritChangeInfo(); TreeSet<GerritChangeVO> treeSet = new TreeSet<GerritChangeVO>(new SortByLastUpdate()); treeSet.addAll(changes);// w ww . j a v a 2 s. c om if (treeSet.size() > 0) return treeSet.first(); return null; }
From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java
public GerritChangeVO getLastChange(String project) throws RepositoryException { log.debug(String.format("getLastChange(project=%s)...", project)); Set<GerritChangeVO> changes = getGerritChangeInfo(project); TreeSet<GerritChangeVO> treeSet = new TreeSet<GerritChangeVO>(new SortByLastUpdate()); treeSet.addAll(changes);/*from w w w. j a v a 2 s .com*/ if (treeSet.size() > 0) return treeSet.first(); return null; }
From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java
public GerritChangeVO getLastChange(String project, String branch) throws RepositoryException { log.debug(String.format("getLastChange(project=%s)...", project)); Set<GerritChangeVO> changes = getGerritChangeInfo(project, branch); TreeSet<GerritChangeVO> treeSet = new TreeSet<GerritChangeVO>(new SortByLastUpdate()); treeSet.addAll(changes);/* w ww . ja v a 2 s .c o m*/ if (treeSet.size() > 0) return treeSet.first(); return null; }
From source file:ca.uhn.fhir.jpa.dao.dstu3.SearchParamExtractorDstu3.java
@Override public Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) {//w w w.j av a2s . c o m HashSet<ResourceIndexedSearchParamDate> retVal = new HashSet<ResourceIndexedSearchParamDate>(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); for (RuntimeSearchParam nextSpDef : def.getSearchParams()) { if (nextSpDef.getParamType() != RestSearchParameterTypeEnum.DATE) { continue; } String nextPath = nextSpDef.getPath(); if (isBlank(nextPath)) { continue; } boolean multiType = false; if (nextPath.endsWith("[x]")) { multiType = true; } for (Object nextObject : extractValues(nextPath, theResource)) { if (nextObject == null) { continue; } ResourceIndexedSearchParamDate nextEntity; if (nextObject instanceof BaseDateTimeType) { BaseDateTimeType nextValue = (BaseDateTimeType) nextObject; if (nextValue.isEmpty()) { continue; } nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), nextValue.getValue(), nextValue.getValue()); } else if (nextObject instanceof Period) { Period nextValue = (Period) nextObject; if (nextValue.isEmpty()) { continue; } nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), nextValue.getStart(), nextValue.getEnd()); } else if (nextObject instanceof Timing) { Timing nextValue = (Timing) nextObject; if (nextValue.isEmpty()) { continue; } TreeSet<Date> dates = new TreeSet<Date>(); for (DateTimeType nextEvent : nextValue.getEvent()) { if (nextEvent.getValue() != null) { dates.add(nextEvent.getValue()); } } if (dates.isEmpty()) { continue; } nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), dates.first(), dates.last()); } else if (nextObject instanceof StringType) { // CarePlan.activitydate can be a string continue; } else { if (!multiType) { throw new ConfigurationException("Search param " + nextSpDef.getName() + " is of unexpected datatype: " + nextObject.getClass()); } else { continue; } } if (nextEntity != null) { nextEntity.setResource(theEntity); retVal.add(nextEntity); } } } return retVal; }
From source file:org.apache.lens.cube.parse.CubeQueryContext.java
private String getClause() { if (clauseName == null) { TreeSet<String> ks = new TreeSet<String>(qb.getParseInfo().getClauseNames()); clauseName = ks.first(); }// ww w.ja v a 2s . c o m return clauseName; }
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 ww w. jav a2 s.c o 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); } }