List of usage examples for java.lang Long compareTo
public int compareTo(Long anotherLong)
From source file:org.apache.camel.util.ObjectHelper.java
/** * A helper method for comparing objects ordering in which it uses type coerce to coerce * types between the left and right values. This allows you to equal test eg String and Integer as * Camel will be able to coerce the types *///w ww . ja v a2s . c o m @SuppressWarnings("unchecked") public static int typeCoerceCompare(TypeConverter converter, Object leftValue, Object rightValue) { // if both values is numeric then compare using numeric Long leftNum = converter.convertTo(Long.class, leftValue); Long rightNum = converter.convertTo(Long.class, rightValue); if (leftNum != null && rightNum != null) { return leftNum.compareTo(rightNum); } // prefer to NOT coerce to String so use the type which is not String // for example if we are comparing String vs Integer then prefer to coerce to Integer // as all types can be converted to String which does not work well for comparison // as eg "10" < 6 would return true, where as 10 < 6 will return false. // if they are both String then it doesn't matter if (rightValue instanceof String && (!(leftValue instanceof String))) { // if right is String and left is not then flip order (remember to * -1 the result then) return typeCoerceCompare(converter, rightValue, leftValue) * -1; } // prefer to coerce to the right hand side at first if (rightValue instanceof Comparable) { Object value = converter.convertTo(rightValue.getClass(), leftValue); if (value != null) { return ((Comparable) rightValue).compareTo(value) * -1; } } // then fallback to the left hand side if (leftValue instanceof Comparable) { Object value = converter.convertTo(leftValue.getClass(), rightValue); if (value != null) { return ((Comparable) leftValue).compareTo(value); } } // use regular compare return compare(leftValue, rightValue); }
From source file:org.polymap.core.runtime.entity.EntityStateTracker.java
/** * * @param key/*from w w w . j a va2 s. c o m*/ * @param check The timestamp to check for the given entity. Null signals * that the tracked timestamp of the session is to be used. */ public boolean isConflicting(EntityHandle key, Long check) { check = check != null ? check : tracked.get(key); if (check == null) { throw new IllegalArgumentException("No timestamp given and no tracked timestamp."); } Long storedTs = stored.get(key); log.debug("key= " + key + ", timestamp= " + check); log.debug("CHECK: " + check + " -- " + storedTs); return storedTs != null && storedTs.compareTo(check) > 0; }
From source file:gemlite.core.internal.measurement.index.BigComparator.java
@Override public int compare(AbstractIndexStatItem o1, AbstractIndexStatItem o2) { Long timestamp1 = o1.getEnd(); Long timestamp2 = o2.getEnd(); return timestamp1.compareTo(timestamp2); }
From source file:org.kuali.kfs.module.cam.document.service.impl.AssetServiceImpl.java
/** * @see org.kuali.kfs.module.cam.document.service.AssetService#isCapitalAssetNumberDuplicate(java.lang.Long, java.lang.Long) *///from www .j a v a 2 s .c om public boolean isCapitalAssetNumberDuplicate(Long capitalAssetNumber1, Long capitalAssetNumber2) { if (capitalAssetNumber1 != null && capitalAssetNumber2 != null && capitalAssetNumber1.compareTo(capitalAssetNumber2) == 0) { return true; } return false; }
From source file:gemlite.core.internal.measurement.index.BigComparator.java
@Override public int compare(AbstractIndexStatItem o1, AbstractIndexStatItem o2) { Long cost1 = o1.getEnd() - o1.getStart(); Long cost2 = o2.getEnd() - o2.getStart(); return cost1.compareTo(cost2); }
From source file:monitoring.tools.GooglePlayAPI.java
protected void generateData(InputStream response, long date) throws MalformedURLException, JSONException, IOException { JSONObject data = new JSONObject(Utils.streamToString(response)); JSONArray reviews = data.getJSONArray("reviews"); if (data.has("tokenPagination")) { JSONArray next = getNextPage(data.getJSONObject("tokenPagination").getString("nextPageToken")); for (int i = 0; i < next.length(); ++i) { reviews.put(next.get(i));//from w w w . jav a 2 s .c o m } } List<MonitoringData> dataList = new ArrayList<>(); for (int i = 0; i < reviews.length(); ++i) { JSONObject obj = reviews.getJSONObject(i); //review time in milliseconds Long l = Utils.getDateTimeInMillis(obj); //Check if the review has already been reported; //if so, check if the last update was reported; //if it wasn't, check if the review datetime is later than the initMonitorization time //if so, report the review if (l.compareTo(stamp.getTime()) > 0) { Iterator<?> keys = obj.keys(); MonitoringData review = new MonitoringData(); while (keys.hasNext()) { String key = (String) keys.next(); if (key.equals("reviewId")) review.setReviewID(obj.getString("reviewId")); else if (key.equals("authorName")) review.setAuthorName(obj.getString("authorName")); else if (key.equals("comments")) { JSONObject userComment = obj.getJSONArray("comments").getJSONObject(0) .getJSONObject("userComment"); Iterator<?> keysComment = userComment.keys(); while (keysComment.hasNext()) { String keyComment = (String) keysComment.next(); if (keyComment.equals("text")) review.setReviewText(userComment.getString("text")); else if (keyComment.equals("starRating")) review.setStarRating(String.valueOf(userComment.getInt("starRating"))); else if (keyComment.equals("reviewerLanguage")) review.setReviewerLanguage(userComment.getString("reviewerLanguage")); else if (keyComment.equals("device")) review.setDevice(userComment.getString("device")); else if (keyComment.equals("appVersionName")) review.setAppVersion(userComment.getString("appVersionName")); } } } review.setTimeStamp(new Timestamp(l).toString()); dataList.add(review); } } String timeStamp = new Timestamp(date).toString(); //kafka.generateResponseKafka(dataList, timeStamp, id, confId, params.getKafkaTopic()); kafka.generateResponseIF(dataList, timeStamp, id, confId, params.getKafkaTopic()); logger.debug("Data sent to kafka endpoint"); ++id; }
From source file:org.nuxeo.ecm.spaces.impl.docwrapper.DocSpaceImpl.java
@SuppressWarnings("serial") public List<WebContentData> readWebContents() throws ClientException { Filter webContentFilter = new Filter() { public boolean accept(DocumentModel doc) { return doc.hasSchema(WEB_CONTENT_SCHEMA); }/*from www . j a v a 2 s.c o m*/ }; Sorter webContentSorter = new Sorter() { public int compare(DocumentModel doc1, DocumentModel doc2) { Long pos1; Long pos2; try { pos1 = (Long) doc1.getPropertyValue(WEB_CONTENT_POSITION_PROPERTY); pos2 = (Long) doc2.getPropertyValue(WEB_CONTENT_POSITION_PROPERTY); return pos1.compareTo(pos2); } catch (Exception e) { LOGGER.error(e, e); return 0; } } }; WebContentSaverService service; try { service = Framework.getService(WebContentSaverService.class); } catch (Exception e) { throw new ClientException("Unable to get Space Manager", e); } List<WebContentData> webContentsList = new ArrayList<WebContentData>(); for (DocumentModel unitDoc : session().getChildren(getDocument().getRef(), UNIT_DOCUMENT_TYPE)) { for (DocumentModel webContentDoc : session().getChildren(unitDoc.getRef(), null, webContentFilter, webContentSorter)) { try { webContentsList.add(service.read(webContentDoc, session())); } catch (Exception e) { throw new ClientException("Unable to get all web contents", e); } } } return webContentsList; }
From source file:org.hyperic.hq.product.RtPlugin.java
protected ParsedFile[] generateFileList(Properties alreadyParsedFiles, String logdir, String logmask) throws IOException { FilenameFilter filter = new GlobFilenameFilter(logmask.trim()); ArrayList removedFiles = new ArrayList(); Enumeration en = alreadyParsedFiles.keys(); while (en.hasMoreElements()) { String file = (String) en.nextElement(); File temp = new File(file); if (filter.accept(temp.getParentFile(), temp.getName())) { removedFiles.add(file);//from w ww . j a va 2 s . c o m } } File directory = new File(logdir); if (!directory.canRead()) { this.log.error("logDir (" + logdir + ") is not readable by the agent!"); } File[] flist = directory.listFiles(filter); ArrayList toParse = new ArrayList(); if (flist == null || flist.length == 0) { this.log.warn("No valid response time log files found. " + "logDir='" + logdir + "', logMask='" + logmask + "'"); return (ParsedFile[]) toParse.toArray(new ParsedFile[0]); } for (int i = 0; i < flist.length; i++) { Long len = new Long(flist[i].length()); String canonPath = flist[i].getCanonicalPath(); String value = alreadyParsedFiles.getProperty(canonPath); Long oldlen = (value == null) ? new Long(0) : Long.valueOf(value); // This file exists, remove it from the list of files // that have been removed. removedFiles.remove(canonPath); if (oldlen.compareTo(len) != 0) { this.log.debug("Adding " + canonPath + " to parse list " + "(offset=" + oldlen + ")"); toParse.add(new ParsedFile(canonPath, oldlen.longValue())); } } // Remove the files that were removed since the last time we parsed // the logs. The way this 'removed files' thing is implemented is // soo lame. Iterator it = removedFiles.iterator(); while (it.hasNext()) { String toRemove = (String) it.next(); this.log.debug("Removing " + toRemove + " from parse list"); this.log.debug(toRemove); alreadyParsedFiles.remove(toRemove); } return (ParsedFile[]) toParse.toArray(new ParsedFile[0]); }
From source file:org.hyperic.hq.measurement.server.session.AvailabilityDataDAO.java
/** * @return {@link Map} of {@link Integer} to ({@link TreeSet} of * {@link AvailabilityDataRLE}). * <p>/* w ww .j a v a 2s.c o m*/ * The {@link Map} key of {@link Integer} == {@link Measurement} * .getId(). * <p> * The {@link TreeSet}'s comparator sorts by * {@link AvailabilityDataRLE}.getStartime(). */ @SuppressWarnings("unchecked") Map<Integer, TreeSet<AvailabilityDataRLE>> getHistoricalAvailMap(Integer[] mids, final long after, final boolean descending) { if (mids.length <= 0) { return Collections.EMPTY_MAP; } final Comparator<AvailabilityDataRLE> comparator = new Comparator<AvailabilityDataRLE>() { public int compare(AvailabilityDataRLE lhs, AvailabilityDataRLE rhs) { Long lhsStart = new Long(lhs.getStartime()); Long rhsStart = new Long(rhs.getStartime()); if (descending) { return rhsStart.compareTo(lhsStart); } return lhsStart.compareTo(rhsStart); } }; StringBuilder sql = new StringBuilder().append("FROM AvailabilityDataRLE rle") .append(" WHERE rle.availabilityDataId.measurement in (:mids)"); if (after > 0) { sql.append(" AND rle.endtime >= :endtime"); } Query query = getSession().createQuery(sql.toString()).setParameterList("mids", mids, new IntegerType()); if (after > 0) { query.setLong("endtime", after); } List<AvailabilityDataRLE> list = query.list(); Map<Integer, TreeSet<AvailabilityDataRLE>> rtn = new HashMap<Integer, TreeSet<AvailabilityDataRLE>>( list.size()); TreeSet<AvailabilityDataRLE> tmp; for (AvailabilityDataRLE rle : list) { Integer mId = rle.getMeasurement().getId(); if (null == (tmp = rtn.get(mId))) { tmp = new TreeSet<AvailabilityDataRLE>(comparator); rtn.put(rle.getMeasurement().getId(), tmp); } tmp.add(rle); } for (int i = 0; i < mids.length; i++) { if (!rtn.containsKey(mids[i])) { rtn.put(mids[i], new TreeSet<AvailabilityDataRLE>(comparator)); } } return rtn; }
From source file:org.kuali.rice.krms.framework.engine.expression.DateComparisonOperator.java
@Override public int compare(Object lhs, Object rhs) { if (lhs == null && rhs == null) { return 0; } else if (lhs == null) { return -1; } else if (rhs == null) { return 1; }//w w w. jav a 2 s . co m Long lhsTime = ((Date) lhs).getTime(); Long rhsTime; if (rhs instanceof Date) { rhsTime = ((Date) rhs).getTime(); } else if (rhs instanceof String) { rhsTime = ((Date) coerce(lhs.getClass().getCanonicalName(), (String) rhs)).getTime(); } else { throw new IncompatibleTypeException("Expected Date or String rhs and therefore unable to compare lhs(" + lhs.getClass().getCanonicalName() + ") and rhs(" + rhs.getClass().getCanonicalName() + ")"); } return lhsTime.compareTo(rhsTime); }