List of usage examples for java.lang Long compareTo
public int compareTo(Long anotherLong)
From source file:org.kuali.kpme.core.accrualcategory.validation.AccrualCategoryValidation.java
boolean validateStartEndUnits(List<AccrualCategoryRuleBo> accrualCategoryRules, AccrualCategoryRuleBo newAccrualCategoryRule) { List<AccrualCategoryRuleBo> tempAccrualCategoryRules = new ArrayList<AccrualCategoryRuleBo>( accrualCategoryRules);/*from w w w .j av a2s . c om*/ //tempAccrualCategoryRules.add(newAccrualCategoryRule); boolean valid = true; if (accrualCategoryRules != null && accrualCategoryRules.size() > 0) { // the rules list has to be sorted by start field List<AccrualCategoryRuleBo> sortedAccrualCategoryRules = new ArrayList<AccrualCategoryRuleBo>( tempAccrualCategoryRules); Collections.sort(sortedAccrualCategoryRules, SENIORITY_ORDER); Long previousEndUnit = sortedAccrualCategoryRules.get(sortedAccrualCategoryRules.size() - 1).getEnd(); long decrementedNewRule = newAccrualCategoryRule.getStart(); if (previousEndUnit.compareTo(decrementedNewRule) != 0) { this.putFieldError("add.accrualCategoryRules.start", "error.accrualCategoryRule.startEnd"); valid = false; } } return valid; }
From source file:fr.aliasource.webmail.proxy.ActionRegistry.java
/** * A reference on the connected clients is needed to implement logout * /* ww w. j a va 2 s . com*/ * @param clients */ public void registerActions() { c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { String f = req.getParameter("folder"); int page = Integer.parseInt(req.getParameter("page")); int pageLength = Integer.parseInt(req.getParameter("pageLength")); long version = Long.parseLong(req.getParameter("version")); ConversationReferenceList convs = p.listConversations(new IMAPFolder(f), page, pageLength); long backendVersion = convs.getPage().getVersion(); if (backendVersion == version) { responder.sendNothingChanged(); } else { if (logger.isDebugEnabled()) { logger.debug("version mismatch: front: " + version + " back: " + backendVersion); } responder.sendConversationsPage(convs); } } public String getUriMapping() { return "/listConversations.do"; } }); c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { c.logout(p); } public String getUriMapping() { return "/logout.do"; } }); c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { String convId = req.getParameter("convId"); ConversationReference cr = p.findConversation(convId); if (cr != null) { responder.sendConversation(cr); } else { responder.sendError("conversation " + convId + " does not exist"); } } public String getUriMapping() { return "/findConversation.do"; } }); c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { IFolder f = new IMAPFolder(req.getParameter("folder")); String[] a = req.getParameter("messageIds").split(","); List<String> mList = Arrays.asList(a); List<MessageId> mids = new ArrayList<MessageId>(mList.size()); for (String s : mList) { mids.add(new MessageId(Integer.parseInt(s))); } responder.sendMessages(p.fetchMessages(f, mids, true)); } public String getUriMapping() { return "/fetchMessages.do"; } }); c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { String convId = req.getParameter("convId"); ConversationReference cr = p.findConversation(convId); Set<MessageId> allMess = cr.getMessageIds(); List<MessageId> unread = new LinkedList<MessageId>(); List<Long> read = new LinkedList<Long>(); Map<Long, MessageId> uidMap = new HashMap<Long, MessageId>(); for (Iterator<MessageId> it = allMess.iterator(); it.hasNext();) { MessageId m = it.next(); if (m.isRead() && it.hasNext()) { read.add(m.getImapId()); uidMap.put(m.getImapId(), m); } else { unread.add(m); } } logger.info("fetching " + unread.size() + " unread msgs and " + read.size() + " read msgs from " + convId); IMAPFolder f = new IMAPFolder(cr.getSourceFolder()); MailMessage[] toShow = p.fetchMessages(f, unread, true); // only fetch envelope for read messages IStoreConnection proto = p.getAccount().getStoreProtocol(); List<MailMessage> toSummarize = new ArrayList<MailMessage>(read.size()); try { proto.select(f.getName()); Collection<Envelope> enveloppes = proto.uidFetchEnvelopes(read); for (Envelope e : enveloppes) { toSummarize.add(getShortMailMessage(uidMap.get(e.getUid()), e)); } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { proto.destroy(); } // merge the 2 list List<MailMessage> all = new ArrayList<MailMessage>(toSummarize.size() + toShow.length); all.addAll(toSummarize); all.addAll(Arrays.asList(toShow)); Comparator<MailMessage> comp = new Comparator<MailMessage>() { @Override public int compare(MailMessage o1, MailMessage o2) { Long uid1 = o1.getUid(); Long uid2 = o2.getUid(); return uid1.compareTo(uid2); } }; Collections.sort(all, comp); responder.sendMessages(cr, all.toArray(new MailMessage[all.size()])); } private MailMessage getShortMailMessage(MessageId id, Envelope e) { MailMessage m = new MailMessage(); m.setCc(e.getCc()); m.setTo(e.getTo()); m.setSender(e.getFrom()); m.setUid(e.getUid()); m.setRead(true); m.setStarred(id.isStarred()); m.setAnswered(id.isAnswered()); m.setBody(null); m.setDate(e.getDate()); return m; } public String getUriMapping() { return "/fetchUnreadMessages.do"; } }); c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { IFolder f = new IMAPFolder(req.getParameter("folder")); Long uid = Long.parseLong(req.getParameter("uid")); InputStream ret = null; IStoreConnection con = p.getAccount().getStoreProtocol(); try { con.select(f.getName()); ret = con.uidFetchMessage(uid); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { con.destroy(); } responder.sendStream(ret); } public String getUriMapping() { return "/downloadEml.do"; } }); c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { String type = req.getParameter("type"); String query = req.getParameter("query"); int limit = Integer.parseInt(req.getParameter("limit")); responder.sendCompletions(p.getPossibleCompletions(type, query, limit)); } public String getUriMapping() { return "/completion.do"; } }); c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { IFolder dest = new IMAPFolder(req.getParameter("folder")); String xmlMessage = req.getParameter("message"); XmlMailMessageParser xmmp = new XmlMailMessageParser(); MailMessage mm = xmmp.parse(xmlMessage); SendParameters sp = SendParametersFactory.createFromParamsMap(req); logger.info(sp.toString()); responder.sendConversationIds(new String[] { p.store(dest, mm, sp) }); } public String getUriMapping() { return "/store.do"; } }); c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { if (req.getParameter("conversations") != null) { String[] ids = req.getParameter("conversations").split(","); Set<String> convIds = new HashSet<String>(); convIds.addAll(Arrays.asList(ids)); String set = req.getParameter("set"); String unset = req.getParameter("unset"); if (set != null) { p.setFlags(convIds, set); } else { p.unsetFlags(convIds, unset); } } else { String set = req.getParameter("set"); String unset = req.getParameter("unset"); String query = req.getParameter("query"); if (set != null) { p.setFlags(query, set); } else { p.unsetFlags(query, unset); } } } public String getUriMapping() { return "/flags.do"; } }); c.registerControlledAction(new AbstractControlledAction() { public void execute(IProxy p, IParameterSource req, IResponder responder) { String move = req.getParameter("move"); logger.info("move param value: " + move); boolean isMove = "true".equals(req.getParameter("move")); Set<String> ret = null; if (req.getParameter("conversations") != null) { String[] ids = req.getParameter("conversations").split(","); Set<String> convIds = new HashSet<String>(); convIds.addAll(Arrays.asList(ids)); IFolder dest = new IMAPFolder(req.getParameter("destination")); if (isMove) { ret = p.moveConversation(dest, convIds); } else { ret = p.copy(dest, convIds); } } else { IFolder dest = new IMAPFolder(req.getParameter("destination")); String query = req.getParameter("query"); if (isMove) { ret = p.moveConversation(query, dest); } else { ret = p.copy(query, dest); } } responder.sendConversationIds(ret.toArray(new String[ret.size()])); } public String getUriMapping() { return "/moveConversation.do"; } }); registerPluginActions(); }
From source file:org.structr.core.EntityContext.java
private static ArrayList<Node> sortNodes(final Iterable<Node> it) { ArrayList<Node> list = new ArrayList<Node>(); for (Node p : it) { list.add(p);/* w w w .ja v a2s .c o m*/ } Collections.sort(list, new Comparator<Node>() { @Override public int compare(Node o1, Node o2) { Long id1 = o1.getId(); Long id2 = o2.getId(); return id1.compareTo(id2); } }); return list; }
From source file:org.structr.core.EntityContext.java
private static ArrayList<Relationship> sortRelationships(final Iterable<Relationship> it) { ArrayList<Relationship> list = new ArrayList<Relationship>(); for (Relationship p : it) { list.add(p);/* w ww . j a v a2 s . co m*/ } Collections.sort(list, new Comparator<Relationship>() { @Override public int compare(Relationship o1, Relationship o2) { Long id1 = o1.getId(); Long id2 = o2.getId(); return id1.compareTo(id2); } }); return list; }
From source file:org.protempa.backend.dsb.relationaldb.EventResultProcessor.java
@Override public void process(ResultSet resultSet) throws SQLException { ResultCache<Event> results = getResults(); EntitySpec entitySpec = getEntitySpec(); String entitySpecName = entitySpec.getName(); //boolean hasRefs = entitySpec.getInboundRefSpecs().length > 0; String[] propIds = entitySpec.getPropositionIds(); ColumnSpec codeSpec = entitySpec.getCodeSpec(); if (codeSpec != null) { List<ColumnSpec> codeSpecL = codeSpec.asList(); codeSpec = codeSpecL.get(codeSpecL.size() - 1); }/* w w w . j a va 2 s .co m*/ Logger logger = SQLGenUtil.logger(); PropertySpec[] propertySpecs = entitySpec.getPropertySpecs(); Value[] propertyValues = new Value[propertySpecs.length]; int count = 0; ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); int[] columnTypes = new int[resultSetMetaData.getColumnCount()]; for (int i = 0; i < columnTypes.length; i++) { columnTypes[i] = resultSetMetaData.getColumnType(i + 1); } String[] uniqueIds = new String[entitySpec.getUniqueIdSpecs().length]; SourceSystem dsType = DataSourceBackendSourceSystem.getInstance(getDataSourceBackendId()); JDBCPositionFormat positionParser = entitySpec.getPositionParser(); while (resultSet.next()) { int i = 1; String keyId = resultSet.getString(i++); if (keyId == null) { logger.warning("A keyId is null. Skipping record."); continue; } i = readUniqueIds(uniqueIds, resultSet, i); if (Arrays.contains(uniqueIds, null)) { if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, "Unique ids contain null ({0}). Skipping record.", StringUtils.join(uniqueIds, ", ")); continue; } } UniqueId uniqueId = generateUniqueId(entitySpecName, uniqueIds); String propId = null; if (!isCasePresent()) { if (codeSpec == null) { assert propIds.length == 1 : "Don't know which proposition id to assign to"; propId = propIds[0]; } else { String code = resultSet.getString(i++); propId = sqlCodeToPropositionId(codeSpec, code); if (propId == null) { continue; } } } else { i++; } ColumnSpec finishTimeSpec = entitySpec.getFinishTimeSpec(); Granularity gran = entitySpec.getGranularity(); Interval interval = null; if (finishTimeSpec == null) { Long d = null; try { d = positionParser.toPosition(resultSet, i, columnTypes[i - 1]); i++; } catch (SQLException e) { logger.log(Level.WARNING, "Could not parse timestamp. Leaving the start time/timestamp unset.", e); } interval = intervalFactory.getInstance(d, gran); } else { Long start = null; try { start = positionParser.toPosition(resultSet, i, columnTypes[i - 1]); } catch (SQLException e) { logger.log(Level.WARNING, "Could not parse start time. Leaving the start time/timestamp unset.", e); } finally { i++; } Long finish = null; try { finish = positionParser.toPosition(resultSet, i, columnTypes[i - 1]); } catch (SQLException e) { logger.log(Level.WARNING, "Could not parse start time. Leaving the finish time unset.", e); } finally { i++; } if (finish != null && start != null && finish.compareTo(start) < 0) { logger.log(Level.WARNING, "Finish {0} is before start {1}: Leaving time unset", new Object[] { finish, start }); interval = intervalFactory.getInstance(null, gran, null, gran); } else { interval = intervalFactory.getInstance(start, gran, finish, gran); } } i = extractPropertyValues(resultSet, i, propertyValues, columnTypes); if (isCasePresent()) { propId = resultSet.getString(i++); } Event event = new Event(propId, uniqueId); event.setSourceSystem(dsType); event.setInterval(interval); for (int j = 0; j < propertySpecs.length; j++) { PropertySpec propertySpec = propertySpecs[j]; event.setProperty(propertySpec.getName(), propertyValues[j]); } logger.log(Level.FINEST, "Created event {0}", event); results.add(keyId, event); if (++count % FLUSH_SIZE == 0) { try { results.flush(this); } catch (IOException ex) { throw new QueryResultsCacheException("Flushing primitive parameters to cache failed", ex); } if (logger.isLoggable(Level.FINE)) { Logging.logCount(logger, Level.FINE, count, "Retrieved {0} record", "Retrieved {0} records"); } } } try { results.flush(this); } catch (IOException ex) { throw new QueryResultsCacheException("Flushing primitive parameters to cache failed", ex); } if (logger.isLoggable(Level.FINE)) { Logging.logCount(logger, Level.FINE, count, "Retrieved {0} record total", "Retrieved {0} records total"); } }
From source file:org.apache.hadoop.hbase.backup.BackupInfo.java
/** * We use only time stamps to compare objects during sort operation *///from w ww.j a v a 2 s . com @Override public int compareTo(BackupInfo o) { Long thisTS = Long.valueOf(this.getBackupId().substring(this.getBackupId().lastIndexOf("_") + 1)); Long otherTS = Long.valueOf(o.getBackupId().substring(o.getBackupId().lastIndexOf("_") + 1)); return thisTS.compareTo(otherTS); }
From source file:uk.ac.ebi.embl.api.entry.feature.Feature.java
public int compareTo(Feature o) { // The natural order of the features is the order in // which they should appear in the flat file. if (this.equals(o)) { return 0; }/*from www. j ava2 s . co m*/ String name = this.getName(); if (name == null) { name = ""; } String otherName = o.getName(); if (otherName == null) { otherName = ""; } // Source features go before other features. if (name.equals(Feature.SOURCE_FEATURE_NAME) && !otherName.equals(Feature.SOURCE_FEATURE_NAME)) { return -1; } if (otherName.equals(Feature.SOURCE_FEATURE_NAME) && !name.equals(Feature.SOURCE_FEATURE_NAME)) { return 1; } Long minPosition = this.getLocations().getMinPosition(); Long maxPosition = this.getLocations().getMaxPosition(); Long otherMinPosition = o.getLocations().getMinPosition(); Long otherMaxPosition = o.getLocations().getMaxPosition(); // Order features with smaller minimum positions first. if (!minPosition.equals(otherMinPosition)) { return minPosition.compareTo(otherMinPosition); } // Order exons smaller maximum positions first. else if ((name.equals(Feature.EXON_FEATURE_NAME)) && (otherName.equals(Feature.EXON_FEATURE_NAME))) { return maxPosition.compareTo(otherMaxPosition); // Smaller maximum position first. } // Order introns smallest maximum positions first. else if ((name.equals(Feature.INTRON_FEATURE_NAME)) && (otherName.equals(Feature.INTRON_FEATURE_NAME))) { return maxPosition.compareTo(otherMaxPosition); // Smaller maximum position first. } // Order largest maximum positions first. return otherMaxPosition.compareTo(maxPosition); }
From source file:org.chromium.chrome.browser.physicalweb.UrlManager.java
/** * Construct the UrlManager./* w w w . j ava 2 s . co m*/ * @param context An instance of android.content.Context */ @VisibleForTesting public UrlManager(Context context) { mContext = context; mNotificationManager = new NotificationManagerProxyImpl( (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)); mPwsClient = new PwsClientImpl(context); mObservers = new ObserverList<Listener>(); mNearbyUrls = new HashSet<>(); mUrlInfoMap = new HashMap<>(); mPwsResultMap = new HashMap<>(); mUrlsSortedByTimestamp = new PriorityQueue<String>(1, new Comparator<String>() { @Override public int compare(String url1, String url2) { Long scanTimestamp1 = Long.valueOf(mUrlInfoMap.get(url1).getScanTimestamp()); Long scanTimestamp2 = Long.valueOf(mUrlInfoMap.get(url2).getScanTimestamp()); return scanTimestamp1.compareTo(scanTimestamp2); } }); initSharedPreferences(); }
From source file:org.guvnor.m2repo.backend.server.M2MavenRepositoryServiceImplTest.java
@Test public void testListFilesWithSortOnLastModifiedDescending() throws Exception { deployArtifact(gavBackend1);//from w ww . j a va2 s . c o m //Wait a bit before deploying other file (to ensure different Last Modified times) Thread.sleep(2000); deployArtifact(gavBackend2); //Sort by Last Modified descending final PageResponse<JarListPageRow> response = assertFilesCount(null, null, JarListPageRequest.COLUMN_LAST_MODIFIED, false, 4); final List<JarListPageRow> files = response.getPageRowList(); final Long fileTime0 = files.get(0).getLastModified().getTime(); final Long fileTime2 = files.get(2).getLastModified().getTime(); assertTrue(fileTime0.compareTo(fileTime2) > 0); }
From source file:org.guvnor.m2repo.backend.server.M2MavenRepositoryServiceImplTest.java
@Test public void testListFilesWithSortOnLastModifiedAscending() throws Exception { deployArtifact(gavBackend1);/*from w w w . ja va2 s . c o m*/ //Wait a bit before deploying other file (to ensure different Last Modified times) Thread.sleep(2000); //This installs a JAR and a POM deployArtifact(gavBackend2); //Sort by Last Modified ascending final PageResponse<JarListPageRow> response = assertFilesCount(null, null, JarListPageRequest.COLUMN_LAST_MODIFIED, true, 4); final List<JarListPageRow> files = response.getPageRowList(); final Long fileTime0 = files.get(0).getLastModified().getTime(); final Long fileTime2 = files.get(2).getLastModified().getTime(); assertTrue(fileTime0.compareTo(fileTime2) < 0); }