List of usage examples for org.apache.commons.lang ObjectUtils compare
public static <T extends Comparable<? super T>> int compare(T c1, T c2)
From source file:com.wrmsr.nativity.x86.App.java
public static void main(String[] args) throws Exception { logger.info("hi"); Document doc;// w ww.j av a 2s .co m try (InputStream is = App.class.getClassLoader().getResourceAsStream("x86reference.xml")) { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); doc = dBuilder.parse(is); } //optional, but recommended //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work doc.getDocumentElement().normalize(); List<Ref.Entry> entries = Lists.newArrayList(); Ref.Parsing.parseRoot(doc, entries); ByteTrie<Ref.Entry> trie = DisImpl.buildTrie(entries); System.out.println(trie.toDetailedString()); System.out.println(); System.out.println(); // Dis.run(trie); Ordering<Pair<Ref.Operand.Type, Ref.Operand.Address>> ord = Ordering.from((o1, o2) -> { int c = ObjectUtils.compare(o1.getLeft(), o2.getLeft()); if (c == 0) { c = ObjectUtils.compare(o1.getRight(), o2.getRight()); } return c; }); Set<Pair<Ref.Operand.Type, Ref.Operand.Address>> set = Sets.newHashSet(); for (Ref.Entry entry : entries) { for (Ref.Syntax syntax : entry.getSyntaxes()) { for (Ref.Operand operand : syntax.getOperands()) { set.add(new ImmutablePair<>(operand.type, operand.address)); } } } for (Pair<Ref.Operand.Type, Ref.Operand.Address> pair : ord.sortedCopy(set)) { System.out.println(pair); } System.out.println("\n"); DisImpl.run(trie); }
From source file:com.haulmont.yarg.formatters.impl.xlsx.CellReference.java
@Override public int compareTo(Object o) { if (o instanceof CellReference) { int rows = ObjectUtils.compare(row, ((CellReference) o).row); int columns = ObjectUtils.compare(column, ((CellReference) o).column); return rows != 0 ? rows : columns; } else {//from w w w .ja v a 2 s . c o m throw new IllegalArgumentException("Could not compare with " + o); } }
From source file:com.opengamma.core.marketdatasnapshot.VolatilitySurfaceKey.java
/** * Compares this key to another, by currency then name. * //from ww w . j av a2 s . co m * @param other the other key, not null * @return the comparison value */ @Override public int compareTo(VolatilitySurfaceKey other) { if (other == null) { throw new NullPointerException(); } int i = _target.compareTo(other.getTarget()); if (i != 0) { return i; } i = ObjectUtils.compare(_name, other._name); if (i != 0) { return i; } i = ObjectUtils.compare(_instrumentType, other._instrumentType); if (i != 0) { return i; } i = ObjectUtils.compare(_quoteType, other._quoteType); if (i != 0) { return i; } return ObjectUtils.compare(_quoteUnits, other._quoteUnits); }
From source file:module.siadap.domain.wrappers.SiadapYearWrapper.java
@Override public int compareTo(SiadapYearWrapper o) { if (o == null) return 1; return ObjectUtils.compare(year, o.getChosenYear()); }
From source file:com.opengamma.engine.depgraph.OrderedRunQueue.java
/** * Runnable task comparison. In runnable priority order (most preferable to run first): * <ul>// w w w . java2s . c o m * <li>PORTFOLIO_NODE</li> * <li>PRIMITIVE</li> * <li>SECURITY</li> * <li>TRADE</li> * <li>POSITION</li> * </ul> * Within a given computation target type, ordering is based on the unique identifier. The aim is to get tasks that will "complete" running sooner (i.e. the primitive and security level functions) * to reduce the live memory footprint during a graph build. Portfolio node targets are performed at a high priority so that if individual positions are also requested then the graph build for both * should run in parallel if the node function is a basic aggregation. Ordering the unique identifiers should group values on the same target to give better utilization of the computation target * resolver cache. * <p> * Note this sorts into reverse order so that the most preferable to run are at the end of the array. */ @Override public int compare(final ContextRunnable r1, final ContextRunnable r2) { if (r1 instanceof ResolveTask) { if (r2 instanceof ResolveTask) { final ResolveTask rt1 = (ResolveTask) r1; final ResolveTask rt2 = (ResolveTask) r2; final ComputationTargetReference ctr1 = rt1.getValueRequirement().getTargetReference(); final ComputationTargetReference ctr2 = rt2.getValueRequirement().getTargetReference(); final Integer p1 = s_priority.get(ctr1.getType()); final Integer p2 = s_priority.get(ctr2.getType()); if (p1.intValue() < p2.intValue()) { return 1; } else if (p1.intValue() > p2.intValue()) { return -1; } else { if (ctr1 instanceof ComputationTargetSpecification) { if (ctr2 instanceof ComputationTargetSpecification) { return ObjectUtils.compare(ctr2.getSpecification().getUniqueId(), ctr1.getSpecification().getUniqueId()); } else { // Do requirement -> specification resolution (r2) first return -1; } } else { if (ctr2 instanceof ComputationTargetRequirement) { return ctr2.getRequirement().getIdentifiers() .compareTo(ctr1.getRequirement().getIdentifiers()); } else { // Do requirement -> specification resolution (r1) first return 1; } } } } else { // Do non-ResolveTask (r2) first return -1; } } else { if (r2 instanceof ResolveTask) { // Do non-ResolveTask (r1) first return 1; } else { // Don't care return 0; } } }
From source file:com.haulmont.timesheets.gui.project.ProjectBrowse.java
protected void sortProjectRoles(List<ProjectRole> projectRoles) { Collections.sort(projectRoles, new Comparator<ProjectRole>() { private Map<ProjectRoleCode, Integer> order = ImmutableMap.<ProjectRoleCode, Integer>builder() .put(ProjectRoleCode.WORKER, 1).put(ProjectRoleCode.MANAGER, 2).put(ProjectRoleCode.APPROVER, 3) .put(ProjectRoleCode.OBSERVER, 4).build(); @Override/*from w w w. j av a 2 s . c o m*/ public int compare(ProjectRole o1, ProjectRole o2) { ProjectRoleCode code1 = o1.getCode(); ProjectRoleCode code2 = o2.getCode(); Integer order1 = order.get(code1); Integer order2 = order.get(code2); return ObjectUtils.compare(order1, order2); } }); }
From source file:com.opengamma.financial.analytics.ircurve.FixedIncomeStrip.java
@Override public int compareTo(final FixedIncomeStrip other) { int result = DateUtils.estimatedDuration(getEffectiveTenor().getPeriod()) .compareTo(DateUtils.estimatedDuration(other.getEffectiveTenor().getPeriod())); if (result != 0) { return result; }//from w w w . ja v a2 s. c o m if (_instrumentType == StripInstrumentType.SPREAD) { result = getStrip1().compareTo(other.getStrip1()); if (result != 0) { return result; } result = getStrip2().compareTo(other.getStrip2()); if (result != 0) { return result; } return getOperation().ordinal() - other.getOperation().ordinal(); } result = getInstrumentType().ordinal() - other.getInstrumentType().ordinal(); if (result != 0) { return result; } else if (getInstrumentType() == StripInstrumentType.FUTURE) { result = getNumberOfFuturesAfterTenor() - other.getNumberOfFuturesAfterTenor(); } else if (getInstrumentType() == StripInstrumentType.PERIODIC_ZERO_DEPOSIT) { result = getPeriodsPerYear() - other.getPeriodsPerYear(); } else if (getInstrumentType() == StripInstrumentType.SWAP || getInstrumentType() == StripInstrumentType.OIS_SWAP && getIndexType() != null) { result = ObjectUtils.compare(getResetTenor(), other.getResetTenor()); if (result != 0) { return result; } return ObjectUtils.compare(getIndexType(), other.getIndexType()); } else if (getInstrumentType() == StripInstrumentType.BASIS_SWAP) { result = getPayTenor().compareTo(other.getPayTenor()); if (result != 0) { return result; } result = ObjectUtils.compare(getReceiveTenor(), other.getReceiveTenor()); if (result != 0) { return result; } result = ObjectUtils.compare(getPayIndexType(), other.getPayIndexType()); if (result != 0) { return result; } result = ObjectUtils.compare(getReceiveIndexType(), other.getReceiveIndexType()); } return result; }
From source file:com.mirth.connect.server.controllers.DonkeyEngineController.java
private List<DashboardStatus> getDashboardStatuses(Collection<Channel> channels) { List<DashboardStatus> statuses = new ArrayList<DashboardStatus>(); Map<String, Integer> channelRevisions = null; try {//w ww.j av a 2 s .c o m channelRevisions = channelController.getChannelRevisions(); } catch (ControllerException e) { logger.error("Error retrieving channel revisions", e); } for (Channel channel : channels) { String channelId = channel.getChannelId(); com.mirth.connect.model.Channel channelModel = channelController.getDeployedChannelById(channelId); // Make sure the channel is actually still deployed if (channelModel != null) { Statistics stats = channelController.getStatistics(); Statistics lifetimeStats = channelController.getTotalStatistics(); DashboardStatus status = new DashboardStatus(); status.setStatusType(StatusType.CHANNEL); status.setChannelId(channelId); status.setName(channel.getName()); status.setState(channel.getCurrentState()); status.setDeployedDate(channel.getDeployDate()); int channelRevision = 0; // Just in case the channel no longer exists if (channelRevisions != null && channelRevisions.containsKey(channelId)) { channelRevision = channelRevisions.get(channelId); status.setDeployedRevisionDelta(channelRevision - channelModel.getRevision()); try { DeployedChannelInfo deployedChannelInfo = channelController .getDeployedChannelInfoById(channelId); if (deployedChannelInfo != null && deployedChannelInfo.getCodeTemplateRevisions() != null && !deployedChannelInfo.getCodeTemplateRevisions().equals( codeTemplateController.getCodeTemplateRevisionsForChannel(channelId))) { status.setCodeTemplatesChanged(true); } } catch (ControllerException e) { } } status.setStatistics(stats.getConnectorStats(channelId, null)); status.setLifetimeStatistics(lifetimeStats.getConnectorStats(channelId, null)); status.setTags(channelModel.getProperties().getTags()); DashboardStatus sourceStatus = new DashboardStatus(); sourceStatus.setStatusType(StatusType.SOURCE_CONNECTOR); sourceStatus.setChannelId(channelId); sourceStatus.setMetaDataId(0); sourceStatus.setName("Source"); sourceStatus.setState(channel.getSourceConnector().getCurrentState()); sourceStatus.setStatistics(stats.getConnectorStats(channelId, 0)); sourceStatus.setLifetimeStatistics(lifetimeStats.getConnectorStats(channelId, 0)); sourceStatus.setQueueEnabled(!channel.getSourceConnector().isRespondAfterProcessing()); sourceStatus.setQueued(new Long(channel.getSourceQueue().size())); status.setQueued(sourceStatus.getQueued()); status.getChildStatuses().add(sourceStatus); for (DestinationChainProvider chainProvider : channel.getDestinationChainProviders()) { for (Entry<Integer, DestinationConnector> connectorEntry : chainProvider .getDestinationConnectors().entrySet()) { Integer metaDataId = connectorEntry.getKey(); DestinationConnector connector = connectorEntry.getValue(); DashboardStatus destinationStatus = new DashboardStatus(); destinationStatus.setStatusType(StatusType.DESTINATION_CONNECTOR); destinationStatus.setChannelId(channelId); destinationStatus.setMetaDataId(metaDataId); destinationStatus.setName(connector.getDestinationName()); destinationStatus.setState(connector.getCurrentState()); destinationStatus.setStatistics(stats.getConnectorStats(channelId, metaDataId)); destinationStatus .setLifetimeStatistics(lifetimeStats.getConnectorStats(channelId, metaDataId)); destinationStatus.setQueueEnabled(connector.isQueueEnabled()); destinationStatus.setQueued(new Long(connector.getQueue().size())); status.setQueued(status.getQueued() + destinationStatus.getQueued()); status.getChildStatuses().add(destinationStatus); } } statuses.add(status); } } Collections.sort(statuses, new Comparator<DashboardStatus>() { public int compare(DashboardStatus o1, DashboardStatus o2) { Calendar c1 = o1.getDeployedDate(); Calendar c2 = o2.getDeployedDate(); return ObjectUtils.compare(c1, c2); } }); return statuses; }
From source file:org.apache.atlas.repository.store.bootstrap.AtlasTypeDefStoreInitializer.java
private static boolean isTypeUpdateApplicable(AtlasBaseTypeDef oldTypeDef, AtlasBaseTypeDef newTypeDef) { String oldTypeVersion = oldTypeDef.getTypeVersion(); String newTypeVersion = newTypeDef.getTypeVersion(); return ObjectUtils.compare(newTypeVersion, oldTypeVersion) > 0; }
From source file:org.batoo.jpa.core.impl.model.mapping.ListComparator.java
/** * {@inheritDoc}/*ww w . j a v a2 s .c om*/ * */ @Override public int compare(E o1, E o2) { int result = 0; try { for (int i = 0; i < this.comparables.size(); i++) { final ComparableMapping mapping = this.comparables.get(i); final Object v1 = mapping.getMapping().get(o1); final Object v2 = mapping.getMapping().get(o2); result = ObjectUtils.compare((Comparable<?>) v1, (Comparable<?>) v2); if (result == 0) { continue; } if (!mapping.isAscending()) { result = -result; } break; } return result; } finally { if (ListComparator.LOG.isDebugEnabled()) { ListComparator.LOG.debug("{0} {1} {2}", result < 0 ? o1 : o2, result == 0 ? "=" : "<", result < 0 ? o2 : o1); } } }