示例#1
0
 static int compare(FileVersion lhs, FileVersion rhs) {
   int cmp = Long.compare(lhs.txId, rhs.txId);
   if (cmp == 0) {
     cmp = Long.compare(lhs.minorVersion, rhs.minorVersion);
   }
   return cmp;
 }
  /** {@inheritDoc} */
  @Override
  public int compareTo(GridDhtPartitionFullMap o) {
    assert nodeId == null
            || (nodeOrder != o.nodeOrder && !nodeId.equals(o.nodeId))
            || (nodeOrder == o.nodeOrder && nodeId.equals(o.nodeId))
        : "Inconsistent node order and ID [id1="
            + nodeId
            + ", order1="
            + nodeOrder
            + ", id2="
            + o.nodeId
            + ", order2="
            + o.nodeOrder
            + ']';

    if (nodeId == null && o.nodeId != null) return -1;
    else if (nodeId != null && o.nodeId == null) return 1;
    else if (nodeId == null && o.nodeId == null) return 0;

    int res = Long.compare(nodeOrder, o.nodeOrder);

    if (res == 0) res = Long.compare(updateSeq, o.updateSeq);

    return res;
  }
 @Override
 public int compareTo(BuildPromotionStatus o) {
   if (buildId != o.buildId) {
     return Long.compare(buildId, o.buildId);
   }
   return Long.compare(created, o.created);
 }
  /** {@inheritDoc} */
  @Override
  public int compareTo(GridClockDeltaVersion o) {
    int res = Long.compare(topVer, o.topVer);

    if (res == 0) res = Long.compare(ver, o.ver);

    return res;
  }
示例#5
0
  public List<Pair> assignJobsNew(Queue<Integer> jobs, int numWorkers) {
    List<Pair> pairs = new LinkedList<>();

    PriorityQueue<JobThread> priorityQueue =
        new PriorityQueue<>((x, y) -> Long.compare(x.startTime, y.startTime));
    for (int i = 0; i < numWorkers; i++) {
      priorityQueue.add(new JobThread());
    }

    while (!jobs.isEmpty()) {
      int duration = jobs.poll();

      boolean check = true;
      while (check) {
        JobThread peek = priorityQueue.poll();
        if (peek.hasFreeTime()) {
          peek.duration = duration;
          pairs.add(new Pair(peek.workerId, peek.newStartTime()));
        } else {
          peek.tick();
        }

        if (priorityQueue.isEmpty()) {
          check = false;
        }
        priorityQueue.add(peek);
      }
    }
    return pairs;
  }
示例#6
0
 @Override
 public int compare(BytesRef left, BytesRef right) {
   // Make shallow copy in case decode changes the BytesRef:
   leftScratch.bytes = left.bytes;
   leftScratch.offset = left.offset;
   leftScratch.length = left.length;
   rightScratch.bytes = right.bytes;
   rightScratch.offset = right.offset;
   rightScratch.length = right.length;
   long leftCost = decode(leftScratch, input);
   long rightCost = decode(rightScratch, input);
   if (hasPayloads) {
     decodePayload(leftScratch, input);
     decodePayload(rightScratch, input);
   }
   if (hasContexts) {
     decodeContexts(leftScratch, input);
     decodeContexts(rightScratch, input);
   }
   int cmp = comparator.compare(leftScratch, rightScratch);
   if (cmp != 0) {
     return cmp;
   }
   return Long.compare(leftCost, rightCost);
 }
示例#7
0
 @Override
 public int compareTo(Object o) {
   if (o instanceof DateAxisGraphLabel) {
     return Long.compare(this.date, ((DateAxisGraphLabel) o).getDate());
   }
   return 0;
 }
public interface TransactionFactory {

  public static final long DUST_LIMIT = 2730;
  public static final long KB_FEE = 1000;
  public static final long MINIMUM_FEE = 5000;
  public static final long MAXIMUM_FEE = 1000000;

  public static Comparator<Coin> spendPreferenceOrder =
      (o1, o2) -> {
        // prefers aggregation
        return -Long.compare(o1.getOutput().getValue(), o2.getOutput().getValue());
      };

  ReadOnlyAccount getAccount();

  CoinBucket getSufficientSources(long amount, long fee) throws HyperLedgerException;

  TransactionProposal propose(Address receiver, long amount) throws HyperLedgerException;

  TransactionProposal propose(Address receiver, long amount, PaymentOptions options)
      throws HyperLedgerException;

  TransactionProposal propose(PaymentOptions options, TransactionOutput... outputs)
      throws HyperLedgerException;

  TransactionProposal propose(PaymentOptions options, List<TransactionOutput> outputs)
      throws HyperLedgerException;
}
  @Override
  public int compare(ValueUpdate<T> arg0, ValueUpdate<T> arg1) {
    long firstValue = arg0.getTimeObserved().getTimeInMillis();
    long secondValue = arg1.getTimeObserved().getTimeInMillis();

    return Long.compare(firstValue, secondValue);
  }
示例#10
0
 @Test
 public void canCompareLong() {
   long value1 = 1120403456L;
   long value2 = 1149239296L;
   int cmpValue = Long.compare(value1, value2);
   doTest(value1, value2, Opcode.CMP_LONG, "J", cmpValue);
 }
示例#11
0
  @Override
  @Modifying
  @Transactional(isolation = Isolation.READ_UNCOMMITTED)
  public boolean clearArtifactBinary(final Artifact existing) {

    for (final Artifact lArtifact :
        localArtifactRepository.findByGridFsFileName(
            ((JpaArtifact) existing).getGridFsFileName())) {
      if (!lArtifact.getSoftwareModule().isDeleted()
          && Long.compare(
                  lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId())
              != 0) {
        return false;
      }
    }

    try {
      LOG.debug(
          "deleting artifact from repository {}", ((JpaArtifact) existing).getGridFsFileName());
      artifactRepository.deleteBySha1(((JpaArtifact) existing).getGridFsFileName());
      return true;
    } catch (final ArtifactStoreException e) {
      throw new ArtifactDeleteFailedException(e);
    }
  }
示例#12
0
 @Override
 public int compare(AgentEvent o1, AgentEvent o2) {
   int eventTimestampComparison = Long.compare(o2.eventTimestamp, o1.eventTimestamp);
   if (eventTimestampComparison == 0) {
     return o1.eventTypeCode - o2.eventTypeCode;
   }
   return eventTimestampComparison;
 }
    /** {@inheritDoc} */
    @Override
    public int compareTo(CancelMessageId m) {
      int res = Long.compare(reqId, m.reqId);

      if (res == 0) res = m.nodeId.compareTo(nodeId);

      return res;
    }
示例#14
0
 /** Test (Not really a test) that dumps the list of all Processes. */
 @Test
 public static void test4() {
   printf("    Parent     Child  Info%n");
   Stream<ProcessHandle> s = ProcessHandle.allProcesses();
   ProcessHandle[] processes = s.toArray(ProcessHandle[]::new);
   int len = processes.length;
   ProcessHandle[] parent = new ProcessHandle[len];
   Set<ProcessHandle> processesSet = Arrays.stream(processes).collect(Collectors.toSet());
   Integer[] sortindex = new Integer[len];
   for (int i = 0; i < len; i++) {
     sortindex[i] = i;
   }
   for (int i = 0; i < len; i++) {
     parent[sortindex[i]] = processes[sortindex[i]].parent().orElse(null);
   }
   Arrays.sort(
       sortindex,
       (i1, i2) -> {
         int cmp =
             Long.compare(
                 (parent[i1] == null ? 0L : parent[i1].getPid()),
                 (parent[i2] == null ? 0L : parent[i2].getPid()));
         if (cmp == 0) {
           cmp =
               Long.compare(
                   (processes[i1] == null ? 0L : processes[i1].getPid()),
                   (processes[i2] == null ? 0L : processes[i2].getPid()));
         }
         return cmp;
       });
   boolean fail = false;
   for (int i = 0; i < len; i++) {
     ProcessHandle p = processes[sortindex[i]];
     ProcessHandle p_parent = parent[sortindex[i]];
     ProcessHandle.Info info = p.info();
     String indent = "    ";
     if (p_parent != null) {
       if (!processesSet.contains(p_parent)) {
         fail = true;
         indent = "*** ";
       }
     }
     printf("%s %7s, %7s, %s%n", indent, p_parent, p, info);
   }
   Assert.assertFalse(fail, "Parents missing from all Processes");
 }
示例#15
0
 @SuppressWarnings({"unchecked"})
 public int compareTo(LongIntPair o) {
   int value = Long.compare(first, o.first);
   if (value != 0) {
     return value;
   }
   return Integer.compare(second, o.second);
 }
示例#16
0
  @Override
  public List<StockItem> getLast30Stock(String code) {
    List<StockItem> items = stockItemRepository.getLast30Items(code);

    List<StockItem> result = new ArrayList<>(items);
    Collections.sort(result, (o1, o2) -> Long.compare(o1.getUidPk(), o2.getUidPk()));

    return result;
  }
 @Override
 public int compareTo(ScoringResult other) {
   if (this.score > other.score) return -1;
   if (this.score < other.score) return 1;
   int comparingResult;
   if ((comparingResult = scoredWebResult.compareTo(other.scoredWebResult)) != 0)
     return comparingResult;
   return Long.compare(tagsHash, other.tagsHash);
 }
 @Override
 public List<Module> getMostRecentlyUsed() {
   List<ModuleUsage> used = dataStore.getUsages();
   used.sort((a, b) -> Long.compare(b.getLastSeen(), a.getLastSeen()));
   return used.stream()
       .map(u -> modulesMap.get(u.getModuleId()))
       .filter(m -> m != null)
       .collect(toList());
 }
示例#19
0
      public int compare(Object o1, Object o2) {
        String s1 = ((File) o1).getName();
        String s2 = ((File) o2).getName();

        long n1 = Long.parseLong(s1.substring(0, s1.indexOf("_")));
        long n2 = Long.parseLong(s2.substring(0, s2.indexOf("_")));

        return Long.compare(n1, n2);
      }
示例#20
0
  // This method is a hotspot, logic from RocksDbKeyValueServices.parseCellAndTs
  // is duplicated and tuned for perf.
  @Override
  public int compare(Slice a, Slice b) {
    byte[] adata = a.data();
    byte[] bdata = b.data();
    byte[] rowSizeBytes = new byte[2];
    rowSizeBytes[0] = adata[adata.length - 1];
    rowSizeBytes[1] = adata[adata.length - 2];
    int aRowSize = (int) EncodingUtils.decodeVarLong(rowSizeBytes);
    rowSizeBytes[0] = bdata[bdata.length - 1];
    rowSizeBytes[1] = bdata[bdata.length - 2];
    int bRowSize = (int) EncodingUtils.decodeVarLong(rowSizeBytes);

    int comp =
        UnsignedBytes.lexicographicalComparator()
            .compare(Arrays.copyOf(adata, aRowSize), Arrays.copyOf(bdata, bRowSize));
    if (comp != 0) {
      return comp;
    }

    int aColEnd = adata.length - 8 - EncodingUtils.sizeOfVarLong(aRowSize);
    int bColEnd = bdata.length - 8 - EncodingUtils.sizeOfVarLong(bRowSize);
    comp =
        UnsignedBytes.lexicographicalComparator()
            .compare(
                Arrays.copyOfRange(adata, aRowSize, aColEnd),
                Arrays.copyOfRange(bdata, bRowSize, bColEnd));
    if (comp != 0) {
      return comp;
    }

    long aTs =
        Longs.fromBytes(
            adata[aColEnd + 0],
            adata[aColEnd + 1],
            adata[aColEnd + 2],
            adata[aColEnd + 3],
            adata[aColEnd + 4],
            adata[aColEnd + 5],
            adata[aColEnd + 6],
            adata[aColEnd + 7]);
    long bTs =
        Longs.fromBytes(
            bdata[bColEnd + 0],
            bdata[bColEnd + 1],
            bdata[bColEnd + 2],
            bdata[bColEnd + 3],
            bdata[bColEnd + 4],
            bdata[bColEnd + 5],
            bdata[bColEnd + 6],
            bdata[bColEnd + 7]);

    // Note: Ordering is reversed, later timestamps come before eariler ones.
    return Long.compare(bTs, aTs);
  }
 private List<DirectInputFragment> validate(List<DirectInputFragment> fragments) {
   List<DirectInputFragment> results = new ArrayList<>(fragments);
   Collections.sort(results, (o1, o2) -> Long.compare(o1.getOffset(), o2.getOffset()));
   long expectedOffset = 0;
   for (DirectInputFragment fragment : results) {
     assertThat(fragment.getOffset(), is(expectedOffset));
     expectedOffset = fragment.getOffset() + fragment.getSize();
   }
   assertThat(offset, is(expectedOffset));
   return results;
 }
示例#22
0
    @Override
    public int compareTo(PrioritizedSplitRunner o) {
      int level = priorityLevel.get();

      int result = Ints.compare(level, o.priorityLevel.get());
      if (result != 0) {
        return result;
      }

      if (level < 4) {
        result = Long.compare(threadUsageNanos.get(), threadUsageNanos.get());
      } else {
        result = Long.compare(lastRun.get(), o.lastRun.get());
      }
      if (result != 0) {
        return result;
      }

      return Longs.compare(workerId, o.workerId);
    }
 void sendFiles(
     Store store,
     StoreFileMetaData[] files,
     Function<StoreFileMetaData, OutputStream> outputStreamFactory)
     throws Exception {
   store.incRef();
   try {
     ArrayUtil.timSort(
         files, (a, b) -> Long.compare(a.length(), b.length())); // send smallest first
     for (int i = 0; i < files.length; i++) {
       final StoreFileMetaData md = files[i];
       try (final IndexInput indexInput =
           store.directory().openInput(md.name(), IOContext.READONCE)) {
         // it's fine that we are only having the indexInput in the try/with block. The copy
         // methods handles
         // exceptions during close correctly and doesn't hide the original exception.
         Streams.copy(
             new InputStreamIndexInput(indexInput, md.length()), outputStreamFactory.apply(md));
       } catch (Exception e) {
         final IOException corruptIndexException;
         if ((corruptIndexException = ExceptionsHelper.unwrapCorruption(e)) != null) {
           if (store.checkIntegrityNoException(md)
               == false) { // we are corrupted on the primary -- fail!
             logger.warn("{} Corrupted file detected {} checksum mismatch", shardId, md);
             failEngine(corruptIndexException);
             throw corruptIndexException;
           } else { // corruption has happened on the way to replica
             RemoteTransportException exception =
                 new RemoteTransportException(
                     "File corruption occurred on recovery but " + "checksums are ok", null);
             exception.addSuppressed(e);
             logger.warn(
                 (org.apache.logging.log4j.util.Supplier<?>)
                     () ->
                         new ParameterizedMessage(
                             "{} Remote file corruption on node {}, recovering {}. local checksum OK",
                             shardId,
                             request.targetNode(),
                             md),
                 corruptIndexException);
             throw exception;
           }
         } else {
           throw e;
         }
       }
     }
   } finally {
     store.decRef();
   }
 }
示例#24
0
 protected static int compare(Object lvalue, Object rvalue) throws DapException {
   if (lvalue instanceof String && rvalue instanceof String)
     return ((String) lvalue).compareTo((String) rvalue);
   if (lvalue instanceof Boolean && rvalue instanceof Boolean)
     return compare((Boolean) lvalue ? 1 : 0, (Boolean) rvalue ? 1 : 0);
   if (lvalue instanceof Double
       || lvalue instanceof Float
       || rvalue instanceof Double
       || rvalue instanceof Float) {
     double d1 = ((Number) lvalue).doubleValue();
     double d2 = ((Number) lvalue).doubleValue();
     return Double.compare(d1, d2);
   } else {
     long l1 = ((Number) lvalue).longValue();
     long l2 = ((Number) rvalue).longValue();
     return Long.compare(l1, l2);
   }
 }
  // suffix array in O(n*log^2(n))
  public static Integer[] suffixArray(CharSequence s) {
    int n = s.length();
    Integer[] sa = new Integer[n];
    int[] rank = new int[n];
    for (int i = 0; i < n; i++) {
      sa[i] = i;
      rank[i] = s.charAt(i);
    }
    for (int len = 1; len < n; len *= 2) {
      long[] rank2 = new long[n];
      for (int i = 0; i < n; i++)
        rank2[i] = ((long) rank[i] << 32) + (i + len < n ? rank[i + len] + 1 : 0);

      Arrays.sort(sa, (a, b) -> Long.compare(rank2[a], rank2[b]));

      for (int i = 0; i < n; i++)
        rank[sa[i]] = i > 0 && rank2[sa[i - 1]] == rank2[sa[i]] ? rank[sa[i - 1]] : i;
    }
    return sa;
  }
示例#26
0
 @Override
 public int compareTo(DataValue dv2) {
   NumericValue other = dv2.getAsNumeric();
   NumericType mutual = getMutualType(this, other);
   switch (mutual) {
     case BIG_DECIMAL:
       return this.getAsBigDecimal().compareTo(other.getAsBigDecimal());
     case BIG_INTEGER:
       return this.getAsBigInteger().compareTo(other.getAsBigInteger());
     case DOUBLE:
       return Double.compare(this.getAsDouble(), other.getAsDouble());
     case FLOAT:
       return Float.compare(this.getAsFloat(), other.getAsFloat());
     case INT:
       return Integer.compare(this.getAsInt(), other.getAsInt());
     case LONG:
       return Long.compare(this.getAsLong(), other.getAsLong());
     default:
       throw new UnsupportedOperationException();
   }
 }
  /** Borrowed from TimSort.binarySort(), but modified to sort two column dataset. */
  private static void binarySort(int[] position, long[] value) {
    final int count = position.length;
    for (int start = 1; start < count; start++) {
      final int pivotPosition = position[start];
      final long pivotValue = value[start];

      int left = 0;
      int right = start;

      while (left < right) {
        int mid = (left + right) >>> 1;

        final long lhs = pivotValue;
        final long rhs = value[mid];
        final int compare = Long.compare(lhs, rhs);
        if (compare > 0) {
          right = mid;
        } else {
          left = mid + 1;
        }
      }

      int n = start - left;
      switch (n) {
        case 2:
          position[left + 2] = position[left + 1];
          value[left + 2] = value[left + 1];
        case 1:
          position[left + 1] = position[left];
          value[left + 1] = value[left];
          break;
        default:
          System.arraycopy(position, left, position, left + 1, n);
          System.arraycopy(value, left, value, left + 1, n);
      }

      position[left] = pivotPosition;
      value[left] = pivotValue;
    }
  }
示例#28
0
 // result is sorted by number of incoming and outcoming ways
 public List<E> getStationsSorted() {
   List<E> stations = getStations();
   stations.sort(
       (s1, s2) -> {
         Long countFirst =
             arcs.stream()
                 .filter(
                     n -> {
                       return n.getEnd().equals(s1) || n.getStart().equals(s1);
                     })
                 .count();
         Long countSecond =
             arcs.stream()
                 .filter(
                     n -> {
                       return n.getEnd().equals(s2) || n.getStart().equals(s2);
                     })
                 .count();
         return Long.compare(countFirst, countSecond);
       });
   return stations;
 }
示例#29
0
  @Override
  public void stencilsExecute(final R2SceneStencilsConsumerType c) {
    c.onStart();

    /**
     * Sort the instances by their array object instances, to allow for rendering with the fewest
     * number of array object binds.
     */
    this.instances_sorted.clear();
    for (final long i_id : this.instances.keySet()) {
      final R2InstanceSingleType i = this.instances.get(i_id);
      this.instances_sorted.add(i);
    }

    this.instances_sorted.sort(
        (a, b) -> {
          final JCGLArrayObjectUsableType ao = a.getArrayObject();
          final JCGLArrayObjectUsableType bo = b.getArrayObject();
          final int ac = Integer.compare(ao.getGLName(), bo.getGLName());
          if (ac == 0) {
            return Long.compare(a.getInstanceID(), b.getInstanceID());
          }
          return ac;
        });

    int current_array = -1;
    for (int index = 0; index < this.instances_sorted.size(); ++index) {
      final R2InstanceSingleType i = this.instances_sorted.get(index);
      final JCGLArrayObjectUsableType array_object = i.getArrayObject();
      final int next_array = array_object.getGLName();
      if (next_array != current_array) {
        c.onInstanceSingleStartArray(i);
      }
      current_array = next_array;
      c.onInstanceSingle(i);
    }

    c.onFinish();
  }
    @SuppressWarnings("rawtypes")
    @Override
    public int compareTo(Delayed other) {
      // Since getDelay may return different values for each call,
      // this check is required to correctly implement Comparable
      if (other == this) {
        return 0;
      }

      // If we are considering other sponge tasks, we can order by
      // their internal tasks
      if (other instanceof SpongeTaskFuture) {
        ScheduledTask otherTask = ((SpongeTaskFuture) other).task;
        return ComparisonChain.start()
            .compare(this.task.nextExecutionTimestamp(), otherTask.nextExecutionTimestamp())
            .compare(this.task.getUniqueId(), otherTask.getUniqueId())
            .result();
      }

      return Long.compare(
          this.getDelay(TimeUnit.NANOSECONDS), other.getDelay(TimeUnit.NANOSECONDS));
    }