List of usage examples for com.google.common.primitives Longs compare
public static int compare(long a, long b)
From source file:net.sourceforge.vaticanfetcher.gui.ResultPanel.java
public ResultPanel(@NotNull Composite parent) { iconCache = new FileIconCache(parent); int treeStyle = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER; viewer = new VirtualTableViewer<ResultDocument>(parent, treeStyle) { @SuppressWarnings("unchecked") protected List<ResultDocument> getElements(Object rootElement) { return (List<ResultDocument>) rootElement; }/*from ww w . j a v a2s . c om*/ }; // Open result document on double-click Table table = viewer.getControl(); table.addMouseListener(new MouseAdapter() { public void mouseDoubleClick(MouseEvent e) { launchSelection(); } }); table.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (Util.isEnterKey(e.keyCode)) launchSelection(); else if (e.stateMask == SWT.MOD1 && e.keyCode == 'c') copyToClipboard(); } }); viewer.setSortingEnabled(true); initContextMenu(); table.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { evtSelection.fire(viewer.getSelection()); } }); viewer.addColumn(new VariableHeaderColumn<ResultDocument>(Msg.title.get(), Msg.subject.get()) { protected String getLabel(ResultDocument element) { return element.getTitle(); } protected Image getImage(ResultDocument element) { if (element.isEmail()) return Img.EMAIL.get(); return iconCache.getIcon(element.getFilename(), Img.FILE.get()); } protected int compare(ResultDocument e1, ResultDocument e2) { return compareAlphanum(e1.getTitle(), e2.getTitle()); } }); viewer.addColumn(new Column<ResultDocument>(Msg.score.get(), SWT.RIGHT) { protected String getLabel(ResultDocument element) { return String.valueOf(element.getScore()); } protected int compare(ResultDocument e1, ResultDocument e2) { return -1 * Float.compare(e1.getScore(), e2.getScore()); } }); viewer.addColumn(new Column<ResultDocument>(Msg.size.get(), SWT.RIGHT) { protected String getLabel(ResultDocument element) { return String.format("%,d KB", element.getSizeInKB()); } protected int compare(ResultDocument e1, ResultDocument e2) { return -1 * Longs.compare(e1.getSizeInKB(), e2.getSizeInKB()); } }); viewer.addColumn(new VariableHeaderColumn<ResultDocument>(Msg.filename.get(), Msg.sender.get()) { protected String getLabel(ResultDocument element) { if (element.isEmail()) return element.getSender(); return element.getFilename(); } protected int compare(ResultDocument e1, ResultDocument e2) { return compareAlphanum(getLabel(e1), getLabel(e2)); } }); viewer.addColumn(new Column<ResultDocument>(Msg.type.get()) { protected String getLabel(ResultDocument element) { return element.getType(); } protected int compare(ResultDocument e1, ResultDocument e2) { return compareAlphanum(e1.getType(), e2.getType()); } }); viewer.addColumn(new Column<ResultDocument>(Msg.path.get()) { protected String getLabel(ResultDocument element) { return element.getPath().getPath(); } protected int compare(ResultDocument e1, ResultDocument e2) { return compareAlphanum(getLabel(e1), getLabel(e2)); } }); viewer.addColumn(new VariableHeaderColumn<ResultDocument>(Msg.authors.get(), Msg.sender.get()) { protected String getLabel(ResultDocument element) { return element.getAuthors(); } protected int compare(ResultDocument e1, ResultDocument e2) { return compareAlphanum(e1.getAuthors(), e2.getAuthors()); } }); viewer.addColumn(new VariableHeaderColumn<ResultDocument>(Msg.last_modified.get(), Msg.send_date.get()) { protected String getLabel(ResultDocument element) { Date date = getDate(element); return date == null ? "" : dateFormat.format(date); } protected int compare(ResultDocument e1, ResultDocument e2) { Date date1 = getDate(e1); Date date2 = getDate(e2); if (date1 == null) // Place null dates before non-null dates return date2 == null ? 0 : -1; else if (date2 == null) return 1; return date1.compareTo(date2); } @Nullable private Date getDate(ResultDocument element) { if (element.isEmail()) return element.getDate(); return element.getLastModified(); } }); SettingsConf.ColumnWidths.ResultPanel.bind(table); SettingsConf.ColumnOrder.ResultPanelColumnOrder.bind(table); }
From source file:com.cinchapi.concourse.Timestamp.java
@Override public boolean equals(Object obj) { if (obj instanceof Timestamp && !isString()) { return Longs.compare(microseconds, ((Timestamp) obj).microseconds) == 0; }/*from w w w. j a v a 2 s .c om*/ // NOTE: By convention, two hollow timestamps are NEVER equal return false; }
From source file:org.apache.sling.tracer.internal.JSONRecording.java
@Override public int compareTo(@Nonnull JSONRecording o) { return Longs.compare(start, o.start); }
From source file:org.apache.druid.query.groupby.orderby.DefaultLimitSpec.java
private Ordering<Row> makeComparator(List<DimensionSpec> dimensions, List<AggregatorFactory> aggs, List<PostAggregator> postAggs, boolean sortByDimsFirst) { Ordering<Row> timeOrdering = new Ordering<Row>() { @Override/*from w ww . ja v a 2 s.c o m*/ public int compare(Row left, Row right) { return Longs.compare(left.getTimestampFromEpoch(), right.getTimestampFromEpoch()); } }; Map<String, DimensionSpec> dimensionsMap = Maps.newHashMap(); for (DimensionSpec spec : dimensions) { dimensionsMap.put(spec.getOutputName(), spec); } Map<String, AggregatorFactory> aggregatorsMap = Maps.newHashMap(); for (final AggregatorFactory agg : aggs) { aggregatorsMap.put(agg.getName(), agg); } Map<String, PostAggregator> postAggregatorsMap = Maps.newHashMap(); for (PostAggregator postAgg : postAggs) { postAggregatorsMap.put(postAgg.getName(), postAgg); } Ordering<Row> ordering = null; for (OrderByColumnSpec columnSpec : columns) { String columnName = columnSpec.getDimension(); Ordering<Row> nextOrdering = null; if (postAggregatorsMap.containsKey(columnName)) { nextOrdering = metricOrdering(columnName, postAggregatorsMap.get(columnName).getComparator()); } else if (aggregatorsMap.containsKey(columnName)) { nextOrdering = metricOrdering(columnName, aggregatorsMap.get(columnName).getComparator()); } else if (dimensionsMap.containsKey(columnName)) { nextOrdering = dimensionOrdering(columnName, columnSpec.getDimensionComparator()); } if (nextOrdering == null) { throw new ISE("Unknown column in order clause[%s]", columnSpec); } if (columnSpec.getDirection() == OrderByColumnSpec.Direction.DESCENDING) { nextOrdering = nextOrdering.reverse(); } ordering = ordering == null ? nextOrdering : ordering.compound(nextOrdering); } if (ordering != null) { ordering = sortByDimsFirst ? ordering.compound(timeOrdering) : timeOrdering.compound(ordering); } else { ordering = timeOrdering; } return ordering; }
From source file:org.jclouds.ecs.domain.Server.java
@Override public int compareTo(Server that) { return Longs.compare(id, that.getId()); }
From source file:org.bitcoinj.utils.Fiat.java
@Override public int compareTo(final Fiat other) { if (!this.currencyCode.equals(other.currencyCode)) return this.currencyCode.compareTo(other.currencyCode); return Longs.compare(this.value, other.value); }
From source file:org.lenskit.data.store.PackedEntityCollectionBuilder.java
private int compareIds(int k1, int k2) { return Longs.compare(idStore.getLong(k1), idStore.getLong(k2)); }
From source file:org.jclouds.ecs.domain.LoadBalancer.java
@Override public int compareTo(LoadBalancer o) { return Longs.compare(id, o.getId()); }
From source file:org.jclouds.gogrid.domain.Job.java
@Override public int compareTo(Job o) { if (createdOn != null && o.getCreatedOn() != null) return Longs.compare(createdOn.getTime(), o.getCreatedOn().getTime()); return Longs.compare(id, o.getId()); }
From source file:co.cask.cdap.internal.app.store.WorkflowDataset.java
private List<WorkflowDataset.WorkflowRunRecord> sort( List<WorkflowDataset.WorkflowRunRecord> workflowRunRecords) { Collections.sort(workflowRunRecords, new Comparator<WorkflowRunRecord>() { @Override/* w ww . ja v a 2s . c o m*/ public int compare(WorkflowDataset.WorkflowRunRecord o1, WorkflowDataset.WorkflowRunRecord o2) { return Longs.compare(o1.getTimeTaken(), o2.getTimeTaken()); } }); return workflowRunRecords; }