@Override public int compare(ConnectPoint o1, ConnectPoint o2) { int compareId = ELEMENT_ID_COMPARATOR.compare(o1.elementId(), o2.elementId()); return (compareId != 0) ? compareId : Long.signum(o1.port().toLong() - o2.port().toLong()); }

@Override public int compare(Size lhs, Size rhs) { long lhArea = (long) lhs.getWidth() * lhs.getHeight(); long rhArea = (long) rhs.getWidth() * rhs.getHeight(); return (Long.signum(lhArea - rhArea)); }

public int compare(Declaration d1, Declaration d2) { if (equals(d1, d2)) return 0; SourcePosition p1 = d1.getPosition(); SourcePosition p2 = d2.getPosition(); if (p1 == null && p2 != null) return 1; else if (p1 != null && p2 == null) return -1; else if (p1 == null && p2 == null) return compareEqualPosition(d1, d2); else { assert p1 != null && p2 != null; int fileComp = p1.file().compareTo(p2.file()); if (fileComp == 0) { long diff = (long) p1.line() - (long) p2.line(); if (diff == 0) { diff = Long.signum((long) p1.column() - (long) p2.column()); if (diff != 0) return (int) diff; else { // declarations may be two // compiler-generated members with the // same source position return compareEqualPosition(d1, d2); } } else return (diff < 0) ? -1 : 1; } else return fileComp; } }

@Override public int compareTo(Entry other) { if (count == other.count) { return word.compareTo(other.word); } return Long.signum(count - other.count); }

/** * Compare two ExportDataSources for equivalence. This currently does not compare column names, * but it should once column add/drop is allowed. This comparison is performed to decide if a * datasource in a new catalog needs to be passed to a proccessor. */ @Override public int compareTo(ExportDataSource o) { int result; result = m_database.compareTo(o.m_database); if (result != 0) { return result; } result = m_tableName.compareTo(o.m_tableName); if (result != 0) { return result; } result = Long.signum(m_HSId - o.m_HSId); if (result != 0) { return result; } result = (m_partitionId - o.m_partitionId); if (result != 0) { return result; } // does not verify replicated / unreplicated. // does not verify column names / schema return 0; }

public Short roundDown(Short value, int decimalShift) { if (value == 0) return 0; if (decimalShift >= 0) return value; int shiftedValue = Math.abs(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue /= 10; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10; return (short) shiftedValue; }

/** * Sort packs according to the optimal lookup ordering. * * <p>This method tries to position packs in the order readers should examine them when looking * for objects by SHA-1. The default tries to sort packs with more recent modification dates * before older packs, and packs with fewer objects before packs with more objects. * * @param b the other pack. */ public int compareTo(DfsPackDescription b) { // Cluster by PackSource, pushing UNREACHABLE_GARBAGE to the end. PackSource as = getPackSource(); PackSource bs = b.getPackSource(); if (as != null && bs != null) { int cmp = as.category - bs.category; if (cmp != 0) return cmp; } // Newer packs should sort first. int cmp = Long.signum(b.getLastModified() - getLastModified()); if (cmp != 0) return cmp; // Break ties on smaller index. Readers may get lucky and find // the object they care about in the smaller index. This also pushes // big historical packs to the end of the list, due to more objects. return Long.signum(getObjectCount() - b.getObjectCount()); }

public Long roundDown(Long value, int decimalShift) { if (value == 0) return 0l; if (decimalShift >= 0) return value; long shiftedValue = Math.abs(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue /= 10l; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10l; return shiftedValue; }

private static boolean areAllPositiveNumbers(Long[] longs) { boolean result = true; for (long l : longs) { if (Long.signum(l) == -1) { result = false; break; } } return result; }

/** {@inheritDoc} */ public int compare(final InvocationModel o1, final InvocationModel o2) { int ret = Long.signum(o2.getMaximum() - o1.getMaximum()); if (ret == 0) { ret = Double.compare(o2.getAverageDouble(), o1.getAverageDouble()); if (ret == 0) { ret = o1.getMethodName().compareTo(o2.getMethodName()); } } return ret; }

public Short roundUp(Short value, int decimalShift) { if (value == 0) return 0; if (decimalShift >= 0) return value; int shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10; shiftedValueP5 += 5l; int shiftedValue = shiftedValueP5 / 10; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10; return (short) shiftedValue; }

public Long roundUp(Long value, int decimalShift) { if (value == 0) return 0l; if (decimalShift >= 0) return value; long shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10l; shiftedValueP5 += 5l; long shiftedValue = shiftedValueP5 / 10l; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10l; return shiftedValue; }

@Override public int compareTo(Object o) { DefaultElectionCredentials other = (DefaultElectionCredentials) o; if (this.latestTxId == other.latestTxId) { // Smaller id means higher priority if (this.currentWinner == other.currentWinner) { return Integer.signum(other.serverId - this.serverId); } else { return other.currentWinner ? -1 : 1; } } else { return Long.signum(this.latestTxId - other.latestTxId); } }

// Number public static final byte[] serializeNumber(long number) { int sign = Long.signum(number); byte[] ret = getNumberProperties(number); if (sign == -1) number *= -1; for (int i = ret.length - 1; i > 0; i--) { int shift = (ret.length - 1) - (i); ret[i] = (byte) (number >>> 8 * shift); } return ret; }

@Override public int compare(KeyValue o1, KeyValue o2) { int d; if ((d = Bytes.memcmp(o1.key(), o2.key())) != 0) { return d; } else if ((d = Bytes.memcmp(o1.family(), o2.family())) != 0) { return d; } else if ((d = Bytes.memcmp(o1.qualifier(), o2.qualifier())) != 0) { return d; } else if ((d = Long.signum(o2.timestamp() - o1.timestamp())) != 0) { return d; } else { d = Bytes.memcmp(o1.value(), o2.value()); } return d; }

public static byte[] serializeLong(byte[] inField, Long inLong) { long number = inLong; int sign = Long.signum(number); byte[] numberProps = getNumberProperties(number); byte[] bytes = getByteArrayFrame(inField, numberProps.length); bytes[inField.length] = numberProps[0]; if (sign == -1) number *= -1; for (int i = bytes.length - 1; i > inField.length; i--) { int shift = (bytes.length - 1) - (i); bytes[i] = (byte) (number >>> 8 * shift); } return bytes; }

@SuppressWarnings("cast") private int compareEqualPosition(Declaration d1, Declaration d2) { assert d1.getPosition() == d2.getPosition(); DeclPartialOrder dpo1 = new DeclPartialOrder(); DeclPartialOrder dpo2 = new DeclPartialOrder(); d1.accept(dpo1); d2.accept(dpo2); int difference = dpo1.getValue() - dpo2.getValue(); if (difference != 0) return difference; else { int result = d1.getSimpleName().compareTo(d2.getSimpleName()); if (result != 0) return result; return (int) (Long.signum((long) System.identityHashCode(d1) - (long) System.identityHashCode(d2))); } }

public int compareTo(PersistentMemberPattern o) { int result = compare(diskStoreID, o.diskStoreID); if (result != 0) { return result; } result = compare( host == null ? null : host.getCanonicalHostName(), o.host == null ? null : o.host.getCanonicalHostName()); if (result != 0) { return result; } result = compare(directory, o.directory); if (result != 0) { return result; } result = Long.signum(revokedTime - o.revokedTime); return result; }

public int getSignum() { return Long.signum(nanos); }

public int compareTo(Timestamp o) { int sign = Long.signum(getTime() - o.getTime()); return sign == 0 ? getNanos() - o.getNanos() : sign; }

@Override public int compare(Size lhs, Size rhs) { return Long.signum( (long) lhs.getWidth() * lhs.getHeight() - (long) rhs.getWidth() * rhs.getHeight()); }

@Override public int compare(Project proj1, Project proj2) { long date1 = proj1.getDateCreated(); long date2 = proj2.getDateCreated(); return Long.signum(date2 - date1); // descending }

public int compare(File o1, File o2) { long diff = getDbVerFromFilename(o1) - getDbVerFromFilename(o2); return Long.signum(diff); }

@Override public int compare(J first, J second) { return Long.signum(first.getTimeStamp() - second.getTimeStamp()); }

@Override public int compare(Size lhs, Size rhs) { // We cast here to ensure the multiplications won't overflow return Long.signum( (long) lhs.getWidth() * lhs.getHeight() - (long) rhs.getWidth() * rhs.getHeight()); }

@Override public int compare(WaveViewData arg0, WaveViewData arg1) { long time0 = computeCreatedTime(arg0); long time1 = computeCreatedTime(arg1); return Long.signum(time0 - time1); }

public int compare(MmsSmsNotificationInfo info1, MmsSmsNotificationInfo info2) { return Long.signum(info2.getTime() - info1.getTime()); }

@Override public int compare(Camera.Size lhs, Camera.Size rhs) { // We cast here to ensure the multiplications won't overflow return Long.signum((long) lhs.width * lhs.height - (long) rhs.width * rhs.height); }

private IntTh Csgn(String methodName, Thing[] args, Evaller evaller, Framelike frame, Syntax src) throws FisherException { checkNumberOfArgs(0, 0, methodName, args, evaller, frame, src); return IntTh.of(Long.signum(value)); }

@Override public int compare(WaveViewData arg0, WaveViewData arg1) { long lmt0 = computeLmt(arg0); long lmt1 = computeLmt(arg1); return Long.signum(lmt0 - lmt1); }