public int compareTo(CurrencyUnit currency) { int compare = getNamespace().compareTo(currency.getNamespace()); if (compare == 0) { compare = getCurrencyCode().compareTo(currency.getCurrencyCode()); } if (compare == 0) { if (validFrom == null && currency.getValidFrom() != null) { compare = -1; } else if (validFrom != null && currency.getValidFrom() == null) { compare = 1; } else if (validFrom != null) { compare = validFrom.compareTo(currency.getValidFrom()); } } if (compare == 0) { if (validUntil == null && currency.getValidUntil() != null) { compare = -1; } else if (validUntil != null && currency.getValidUntil() == null) { compare = 1; } else if (validUntil != null) { compare = validUntil.compareTo(currency.getValidUntil()); } } return compare; }
/** {@inheritDoc} */ protected void render(User user, PageControl pc, HttpServletRequest request) { LocalizationService ls = LocalizationService.getInstance(); DataResult<SystemOverview> isdr = SystemManager.inactiveListSortbyCheckinTime(user, pc); String inactiveSystemCSSTable = null; if (!isdr.isEmpty()) { for (Iterator<SystemOverview> i = isdr.iterator(); i.hasNext(); ) { SystemOverview so = i.next(); StringBuilder buffer = new StringBuilder(); Long lastCheckin = so.getLastCheckinDaysAgo(); if (lastCheckin.compareTo(new Long(1)) < 0) { buffer.append(lastCheckin * 24); buffer.append(' '); buffer.append(ls.getMessage("filter-form.jspf.hours")); } else if (lastCheckin.compareTo(new Long(7)) < 0) { buffer.append(so.getLastCheckinDaysAgo().longValue()); buffer.append(' '); buffer.append(ls.getMessage("filter-form.jspf.days")); } else if (lastCheckin.compareTo(new Long(7)) >= 0) { buffer.append(lastCheckin.longValue() / 7); buffer.append(' '); buffer.append(ls.getMessage("filter-form.jspf.weeks")); } so.setLastCheckinString(buffer.toString()); } request.setAttribute(INACTIVE_SYSTEM_LIST, isdr); } else { inactiveSystemCSSTable = RendererHelper.makeEmptyTable( true, "inactivelist.jsp.header", "yourrhn.jsp.noinactivesystems"); request.setAttribute(INACTIVE_SYSTEMS_EMPTY, inactiveSystemCSSTable); } RendererHelper.setTableStyle(request, INACTIVE_SYSTEMS_CLASS); }
public int compareTo(BinnedCounter other) { int res = lowerBound.compareTo(other.lowerBound); if (res == 0) { return upperBound.compareTo(other.upperBound); } else { return res; } }
/** * Is this user current - is the current date after their start date and before their end date? * * @param user * @param week * @return */ protected boolean isCurrentUser(User user, Long week) { Long startWeek = DateHandler.getWeekNumber(parseDate(user.getStartDate(), "Jan 11, 2011")); Long endWeek = DateHandler.getWeekNumber(parseDate(user.getEndDate(), "Dec 31, 9999")); if (startWeek.compareTo(week) <= 0 && endWeek.compareTo(week) >= 0) { return true; } return false; }
/** * Compare two OpenPath files, with sorting taken into account * * @param fa First OpenPath * @param fb Second OpenPath * @return an int determined by comparing the two paths. Possible values are described in the * Comparable interface. * @see Comparable */ public static int compare(OpenPath fa, OpenPath fb) { try { if (fa == null && fb != null) return 1; if (fb == null && fa != null) return 0; if (fb == null || fa == null) return 0; if (Sorting.foldersFirst()) { if (fb.isDirectory() && !fa.isDirectory()) return 1; if (fa.isDirectory() && !fb.isDirectory()) return -1; } String a = fa.getName(); String b = fb.getName(); Long sa = fa.length(); Long sb = fb.length(); Long ma = fa.lastModified(); Long mb = fb.lastModified(); if (a == null && b != null) return 1; if (a == null || b == null) return 0; switch (Sorting.getType()) { case ALPHA_DESC: return b.toLowerCase().compareTo(a.toLowerCase()); case ALPHA: return a.toLowerCase().compareTo(b.toLowerCase()); case SIZE_DESC: if (sa == null && sb != null) return 1; if (sa == null || sb == null) return 0; return sa.compareTo(sb); case SIZE: if (sb == null && sa != null) return 1; if (sa == null || sb == null) return 0; return sb.compareTo(sa); case DATE_DESC: if (ma == null && mb != null) return 1; if (ma == null || mb == null) return 0; return ma.compareTo(mb); case DATE: if (mb == null && ma != null) return 1; if (ma == null || mb == null) return 0; return mb.compareTo(ma); case TYPE: String ea = a.substring(a.lastIndexOf(".") + 1, a.length()).toLowerCase(); String eb = b.substring(b.lastIndexOf(".") + 1, b.length()).toLowerCase(); return ea.compareTo(eb); case NONE: return 0; default: return a.toLowerCase().compareTo(b.toLowerCase()); } } catch (Exception e) { Logger.LogError("Unable to sort.", e); return 0; } }
private List<?> copyParamLocal(Param copyParam) { List<?> params = paramDao.getChildrenById(copyParam.getId()); Map<Long, Long> paramMapping = new HashMap<Long, Long>(); // 复制出来的新节点 与 被复制源节点 建立一一对应关系(ID 对 ID) for (int i = 0; i < params.size(); i++) { Param param = (Param) params.get(i); Long sourceParamId = param.getId(); paramDao.evict(param); param.setId(null); if (sourceParamId.compareTo(copyParam.getId()) == 0) { // 复制指定节点 if (ParamConstants.GROUP_PARAM_TYPE.equals(copyParam.getType())) { param.setName(ParamConstants.COPY_PREFIX_NAME + copyParam.getName()); } else if (ParamConstants.NORMAL_PARAM_TYPE.equals(copyParam.getType())) { param.setCode(ParamConstants.COPY_PREFIX_CODE + copyParam.getCode()); param.setName(ParamConstants.COPY_PREFIX_NAME + copyParam.getName()); } else { param.setText(ParamConstants.COPY_PREFIX_NAME + copyParam.getText()); } param.setSeqNo(paramDao.getNextSeqNo(copyParam.getParentId())); } // 复制指定节点的儿孙节点 else { param.setParentId(paramMapping.get(param.getParentId())); } paramDao.create(param); paramMapping.put(sourceParamId, param.getId()); } return params; }
public int compareTo(Object reference) { ServiceReference other = (ServiceReference) reference; Long id = (Long) getProperty(Constants.SERVICE_ID); Long otherId = (Long) other.getProperty(Constants.SERVICE_ID); if (id.equals(otherId)) { return 0; // same service } Object rankObj = getProperty(Constants.SERVICE_RANKING); Object otherRankObj = other.getProperty(Constants.SERVICE_RANKING); // If no rank, then spec says it defaults to zero. rankObj = (rankObj == null) ? new Integer(0) : rankObj; otherRankObj = (otherRankObj == null) ? new Integer(0) : otherRankObj; // If rank is not Integer, then spec says it defaults to zero. Integer rank = (rankObj instanceof Integer) ? (Integer) rankObj : new Integer(0); Integer otherRank = (otherRankObj instanceof Integer) ? (Integer) otherRankObj : new Integer(0); // Sort by rank in ascending order. if (rank.compareTo(otherRank) < 0) { return -1; // lower rank } else if (rank.compareTo(otherRank) > 0) { return 1; // higher rank } // If ranks are equal, then sort by service id in descending order. return (id.compareTo(otherId) < 0) ? 1 : -1; }
/** * TODO: investigate why duplicates here can appear. this method might be not necessary. Remove * Activities from list of Activities with Activity IDS matching ones we have already retrieved * (i.e .duplicates). */ private void removeDuplicates(ArrayList<ActivityItem> activityList) { if (activityList.size() == 0) { return; } int dupCount = 0; List<Long> actIdList = new ArrayList<Long>(); mDb.fetchActivitiesIds(actIdList, findFirstStatusUpdateTime(activityList)); for (int i = 0; i < activityList.size(); ) { boolean inc = true; Long id = activityList.get(i).activityId; if (id != null) { for (Long l : actIdList) { if (l.compareTo(id) == 0) { activityList.remove(i); inc = false; dupCount++; break; } } } if (inc) { i++; } } LogUtils.logD("ActivityEngine removeDuplicates. Count dups = " + dupCount); }
public int compare(Object o1, Object o2) { if (o1 == null && o2 == null) return 0; if (o1 == null) return 1; if (o2 == null) return -1; Long projectId1 = ((GenericValue) o1).getLong("project"); Long projectId2 = ((GenericValue) o2).getLong("project"); if (projectId1 == null && projectId2 == null) return 0; if (projectId1 == null) return 1; if (projectId2 == null) return -1; int projectComparison = projectId1.compareTo(projectId2); if (projectComparison != 0) { return projectComparison; } else { String componentName1 = ((GenericValue) o1).getString("name"); String componentName2 = ((GenericValue) o2).getString("name"); if (componentName1 == null && componentName2 == null) return 0; else if (componentName2 == null) return -1; else if (componentName1 == null) return 1; else return componentName1.compareToIgnoreCase(componentName2); } }
/** * Orders the child associations by ID. A smaller ID has a higher priority. This may change once * we introduce a changeable index against which to order. */ public int compareTo(ChildAssoc another) { if (this == another) { return 0; } int thisIndex = this.getIndex(); int anotherIndex = another.getIndex(); Long thisId = this.getId(); Long anotherId = another.getId(); if (thisId == null) // this ID has not been set, make this instance greater { return -1; } else if (anotherId == null) // other ID has not been set, make this instance lesser { return 1; } else if (thisIndex == anotherIndex) // use the explicit index { return thisId.compareTo(anotherId); } else // fallback on order of creation { return (thisIndex > anotherIndex) ? 1 : -1; // a lower index, make this instance lesser } }
public List<?> copyParam(Long paramId, Long toParamId) { Param copyParam = paramDao.getEntity(paramId); Param toParam = paramDao.getEntity(toParamId); Long copyParamId = copyParam.getId(); List<?> params = paramDao.getChildrenById(copyParamId); Map<Long, Long> paramMapping = new HashMap<Long, Long>(); // 复制出来的新节点 与 被复制源节点 建立一一对应关系(ID 对 ID) for (int i = 0; i < params.size(); i++) { Param param = (Param) params.get(i); Long sourceParamId = param.getId(); paramDao.evict(param); param.setId(null); if (sourceParamId.compareTo(copyParamId) == 0) { param.setParentId(toParam.getId()); param.setSeqNo(paramDao.getNextSeqNo(toParam.getId())); } else { param.setParentId(paramMapping.get(param.getParentId())); } // 如果目标根节点是停用状态,则所有新复制出来的节点也一律为停用状态 param.setDisabled(toParam.getDisabled()); judgeLegit(param, ParamConstants.EDIT_FLAG); paramDao.create(param); paramMapping.put(sourceParamId, param.getId()); } return params; }
public int compare(Object obj1, Object obj2) { ShoppingItem item1 = (ShoppingItem) obj1; ShoppingItem item2 = (ShoppingItem) obj2; Long categoryId1 = new Long(item1.getCategoryId()); Long categoryId2 = new Long(item2.getCategoryId()); int value = categoryId1.compareTo(categoryId2); if (value == 0) { if (item1.getMinQuantity() < item2.getMinQuantity()) { value = -1; } else if (item1.getMinQuantity() > item2.getMinQuantity()) { value = 1; } } if (value == 0) { value = item1.getName().toLowerCase().compareTo(item2.getName().toLowerCase()); } if (_ascending) { return value; } else { return -value; } }
private URL findResource(String resource) { ModuleWiring searchWiring = generation.getRevision().getWiring(); if (searchWiring != null) { if ((generation.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) { List<ModuleWire> hostWires = searchWiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE); searchWiring = null; Long lowestHost = Long.MAX_VALUE; if (hostWires != null) { // search for the host with the highest ID for (ModuleWire hostWire : hostWires) { Long hostID = hostWire.getProvider().getRevisions().getModule().getId(); if (hostID.compareTo(lowestHost) <= 0) { lowestHost = hostID; searchWiring = hostWire.getProviderWiring(); } } } } } if (searchWiring != null) { int lastSlash = resource.lastIndexOf('/'); String path = lastSlash > 0 ? resource.substring(0, lastSlash) : "/"; // $NON-NLS-1$ String fileName = lastSlash != -1 ? resource.substring(lastSlash + 1) : resource; List<URL> result = searchWiring.findEntries(path, fileName, 0); return (result == null || result.isEmpty()) ? null : result.get(0); } // search the raw bundle file for the generation return generation.getEntry(resource); }
@Override public int compare(String arg0, String arg1) { String dir = mPathStack.peek(); Long first = new File(dir + "/" + arg0).length(); Long second = new File(dir + "/" + arg1).length(); return first.compareTo(second); }
@Override public int compareTo(UniqueInteger o) { int result = value.compareTo(o.value); if (result == 0) { result = sequence.compareTo(o.sequence); } return result; }
public int compare(Summary summary1, Summary summary2) { Long duration1 = summary1.calculateAverageDuration(); Long duration2 = summary2.calculateAverageDuration(); // descending order return duration2.compareTo(duration1); }
private boolean notifyParameterListenersIfChanged( String parameter, Long newValue, Long oldValue) { if (oldValue == null || 0 != newValue.compareTo(oldValue)) { notifyParameterListeners(parameter); return true; } return false; }
@Override public int compare(String arg0, String arg1) { String dir = getCurrentUrl(); Long first = new File(dir + "/" + arg0).length(); Long second = new File(dir + "/" + arg1).length(); return first.compareTo(second); }
@Override public int compare(WritableComparable w1, WritableComparable w2) { // consider only the base part of the key Long t1 = ((LongWritable) w1).get() / KEY_EXTENSION_SCALE; Long t2 = ((LongWritable) w2).get() / KEY_EXTENSION_SCALE; int comp = t1.compareTo(t2); return comp; }
@Override public int compareTo(HighscoreEntry o) { // First, look at nofTurns int lastCmp = nofTurns.compareTo(o.nofTurns); // If nofTurns are equal, look at timestamp. Ensures that older entry gets // higher position than newer, in case of the same nofTurns return (lastCmp != 0 ? lastCmp : timestamp.compareTo(o.timestamp)); }
@Override public int compare(Object aObj, Object bObj) { if (aObj instanceof Long && bObj instanceof Long) { Long a = (Long) aObj; Long b = (Long) bObj; return a.compareTo(b); } return super.compare(aObj, bObj); }
@Override public int compareTo(Object t) { if (!(t instanceof Task)) { log.error("The object to compare is not Task"); throw new ObjectIsNotTaskException("The object to compare is not Task"); } Long anotherTaskTime = ((Task) t).date.getTime(); Long thisTime = this.date.getTime(); return thisTime.compareTo(anotherTaskTime); }
public static final boolean hasMatchingDominantSortAttribute( CommonFieldsBase odkLastEntity, CommonFieldsBase odkEntity, DataField dominantAttr) { boolean matchingDominantAttr = false; switch (dominantAttr.getDataType()) { case BINARY: throw new IllegalStateException("unexpected sort on binary field"); case LONG_STRING: throw new IllegalStateException("unexpected sort on long text field"); case URI: case STRING: { String a1 = odkLastEntity.getStringField(dominantAttr); String a2 = odkEntity.getStringField(dominantAttr); matchingDominantAttr = (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0); } break; case INTEGER: { Long a1 = odkLastEntity.getLongField(dominantAttr); Long a2 = odkEntity.getLongField(dominantAttr); matchingDominantAttr = (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0); } break; case DECIMAL: { BigDecimal a1 = odkLastEntity.getNumericField(dominantAttr); BigDecimal a2 = odkEntity.getNumericField(dominantAttr); matchingDominantAttr = (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0); } break; case BOOLEAN: { Boolean a1 = odkLastEntity.getBooleanField(dominantAttr); Boolean a2 = odkEntity.getBooleanField(dominantAttr); matchingDominantAttr = (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0); } break; case DATETIME: { Date a1 = odkLastEntity.getDateField(dominantAttr); Date a2 = odkEntity.getDateField(dominantAttr); matchingDominantAttr = (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0); } break; default: throw new IllegalStateException("unexpected data type"); } return matchingDominantAttr; }
private int checkLongs(Long s1, Long s2) { int i = 0; if (s1 != null && s2 != null) { i = s1.compareTo(s2); } else if (s2 != null) { i = -1; } else if (s1 != null) { i = 1; } return i; }
public boolean hasUserContributed(Long userId) { String queryStr = "select count(*) from versioncontributor where contributor_id = " + userId; Query query = em.createNativeQuery(queryStr); Long count = (Long) ((Vector) query.getSingleResult()).get(0); System.out.println("count is " + count + ", type " + count.getClass().getName()); if (count.compareTo(new Long(0)) > 0) { return true; } else { return false; } }
@Override public int compareTo(Event o) { // The newer one is the "greater" one Long timestamp = new Long(this.timestamp); int first = timestamp.compareTo(o.timestamp); if (first != 0) return first; int second = this.type.compareTo(o.type); if (second != 0) return second; return this.id.compareTo(o.id); }
/** * Update the information stored about the latest transaction seen from each initiator. Compute * the newest safe transaction id. */ public Long noteTransactionRecievedAndReturnLastSafeTxnId(Long txnId) { assert (txnId != null); if (debug.val) LOG.debug( String.format( "Partition %d :: noteTransactionRecievedAndReturnLastSeen(%d)", this.partitionId, txnId)); this.lastSeenTxnId = txnId; if (trace.val) { LOG.trace( String.format( "Partition %d :: SET lastSeenTxnId = %d", this.partitionId, this.lastSeenTxnId)); LOG.trace(String.format("Partition %d :: Attempting to acquire lock", this.partitionId)); } this.lock.lock(); try { if (this.lastTxnPopped.compareTo(txnId) > 0) { if (debug.val) LOG.warn( String.format( "Partition %d :: Txn ordering deadlock --> LastTxn:%d / NewTxn:%d", this.partitionId, this.lastTxnPopped, txnId)); return (this.lastTxnPopped); } // We always need to check whether this new txnId is less than our next safe txnID // If it is, then we know that we need to replace it. if (txnId.compareTo(this.lastSafeTxnId) < 0) { // 2013-01-15 // Instead of calling checkQueueState() here, we'll // just change the state real quickly. This should be ok because // then we'll immediately insert this new txn into the queue // and then update the queue state then. this.state = QueueState.BLOCKED_ORDERING; this.lastSafeTxnId = txnId; if (trace.val) LOG.trace( String.format( "Partition %d :: SET lastSafeTxnId = %d", this.partitionId, this.lastSafeTxnId)); // Since we know that we just replaced the last safeTxnId, we // need to check our queue state to update ourselves // this.checkQueueState(false); } } finally { if (trace.val) LOG.trace(String.format("Partition %d :: Releasing lock", this.partitionId)); this.lock.unlock(); } // SYNCH return (this.lastSafeTxnId); }
/** Default sorting behavior first by fileName and then by modificationDate */ public int compareTo(FileNameDate key) { try { int rv = 0; if (ignoreCase) { rv = name.compareToIgnoreCase(key.getName()); } else { rv = name.compareTo(key.getName()); } if (rv != 0) return rv; return modificationDate.compareTo(key.getModificationDate()); } catch (Exception ex) { return 1; } }
@Override public boolean checkEnrolmentDate(Grouping grouping, Calendar actualDate) { Long actualDateInMills = new Long(actualDate.getTimeInMillis()); Long enrolmentBeginDayInMills = null; Long enrolmentEndDayInMills = null; if (grouping.getEnrolmentBeginDay() != null) { enrolmentBeginDayInMills = new Long(grouping.getEnrolmentBeginDay().getTimeInMillis()); } if (grouping.getEnrolmentEndDay() != null) { enrolmentEndDayInMills = new Long(grouping.getEnrolmentEndDay().getTimeInMillis()); } if (enrolmentBeginDayInMills == null && enrolmentEndDayInMills == null) { return true; } if (enrolmentBeginDayInMills != null && enrolmentEndDayInMills == null) { if (actualDateInMills.compareTo(enrolmentBeginDayInMills) > 0) { return true; } } if (enrolmentBeginDayInMills == null && enrolmentEndDayInMills != null) { if (actualDateInMills.compareTo(enrolmentEndDayInMills) < 0) { return true; } } if (actualDateInMills.compareTo(enrolmentBeginDayInMills) > 0 && actualDateInMills.compareTo(enrolmentEndDayInMills) < 0) { return true; } return false; }
@Override public int compareTo(ProgramProp arg0) { // sort order is: -startYYYYMMDD, +programtypename, +group, +venue if (startYYYYMMDD != arg0.startYYYYMMDD) { Long start = new Long(startYYYYMMDD); Long arg0Start = new Long(arg0.startYYYYMMDD); return arg0Start.compareTo(start); } if (!programTypeProp.name.equals(arg0.programTypeProp.name)) return programTypeProp.name.compareTo(arg0.programTypeProp.name); if (!groupProp.name.equals(arg0.groupProp.name)) return groupProp.name.compareTo(arg0.groupProp.name); return venueProp.name.compareTo(arg0.venueProp.name); }