Java Collections.frequency Examples

Java Collections.frequency - 30 examples found. These are the top rated real world Java examples of java.util.Collections.frequency extracted from open source projects. You can rate examples to help us improve the quality of examples.
  /**
   * Checks that actual number of instances with different statuses are equal to expected number of
   * instances with matching statuses.
   *
   * @param instancesResult kind of response from API which should contain information about
   *     instances
   *     <p>All parameters below reflect number of expected instances with some kind of status.
   * @param totalCount total number of instances.
   * @param missingCount number of running instances.
   * @param emptyCount number of suspended instance.
   * @param partialCount number of waiting instance.
   * @param availableCount number of killed instance.
   */
  private void validateResponse(
      FeedInstanceResult instancesResult,
      int totalCount,
      int missingCount,
      int emptyCount,
      int partialCount,
      int availableCount) {
    FeedInstanceResult.Instance[] instances = instancesResult.getInstances();
    LOGGER.info("instances: " + Arrays.toString(instances));
    Assert.assertNotNull(instances, "instances should be not null");
    Assert.assertEquals(instances.length, totalCount, "Total Instances");
    List<String> statuses = new ArrayList<>();
    for (FeedInstanceResult.Instance instance : instances) {
      Assert.assertNotNull(instance.getCluster());
      Assert.assertNotNull(instance.getInstance());
      Assert.assertNotNull(instance.getStatus());
      Assert.assertNotNull(instance.getUri());
      Assert.assertNotNull(instance.getCreationTime());
      Assert.assertNotNull(instance.getSize());
      final String status = instance.getStatus();
      LOGGER.info("status: " + status + ", instance: " + instance.getInstance());
      statuses.add(status);
    }

    Assert.assertEquals(
        Collections.frequency(statuses, "MISSING"), missingCount, "Missing Instances");
    Assert.assertEquals(Collections.frequency(statuses, "EMPTY"), emptyCount, "Empty Instances");
    Assert.assertEquals(
        Collections.frequency(statuses, "PARTIAL"), partialCount, "Partial Instances");
    Assert.assertEquals(
        Collections.frequency(statuses, "AVAILABLE"), availableCount, "Available Instances");
  }
Example #2
0
 /**
  * Derives the list of column names suitable for NATURAL JOIN. These are the columns that occur
  * exactly once on each side of the join.
  *
  * @param leftRowType Row type of left input to the join
  * @param rightRowType Row type of right input to the join
  * @return List of columns that occur once on each side
  */
 public static List<String> deriveNaturalJoinColumnList(
     RelDataType leftRowType, RelDataType rightRowType) {
   List<String> naturalColumnNames = new ArrayList<String>();
   final List<String> leftNames = leftRowType.getFieldNames();
   final List<String> rightNames = rightRowType.getFieldNames();
   for (String name : leftNames) {
     if ((Collections.frequency(leftNames, name) == 1)
         && (Collections.frequency(rightNames, name) == 1)) {
       naturalColumnNames.add(name);
     }
   }
   return naturalColumnNames;
 }
  public boolean updateCol(int col) {
    ArrayList<Integer> colList = new ArrayList();
    ArrayList<Integer> numsToUpdate = new ArrayList();
    ArrayList<Integer> possibleValuesForCol = new ArrayList();
    boolean updatedValue = false;
    for (int i = 0; i < 9; i++) {
      colList.add(i);
    }
    for (Integer rowID : colList) {

      if (this.cells[rowID][col].value == 0) {
        possibleValuesForCol.addAll(this.cells[rowID][col].possibleValues);
      }
    }
    for (int i = 1; i < 10; i++) {
      if (Collections.frequency(possibleValuesForCol, (Integer) i) == 1) {
        numsToUpdate.add(i);
      }
    }
    for (Integer num : numsToUpdate) {
      for (Integer rowID : colList) {
        if (this.cells[rowID][col].possibleValues.contains(num)) {
          this.cells[rowID][col].value = num;
          updatedValue = true;
        }
      }
    }
    return updatedValue;
  }
Example #4
0
 private void verifyTrapsAreUnique(Map<String, Tap> traps) {
   for (Tap tap : traps.values()) {
     if (Collections.frequency(traps.values(), tap) != 1)
       throw new PlannerException(
           "traps must be unique, cannot be reused on different branches: " + tap);
   }
 }
 private static void coll(
     Map<Integer, Integer> srcMap, List<Result> src, List<Result> dst, int count, int crt) {
   if (dst.size() == count) {
     if (results2.isEmpty() || sumResult(dst) < sumResult(results2)) {
       List<Integer> temp = new ArrayList<Integer>();
       for (Result r : dst) {
         temp.addAll(r.src);
       }
       for (Entry<Integer, Integer> entry : srcMap.entrySet()) {
         if (Collections.frequency(temp, entry.getKey()) > entry.getValue()) {
           return;
         }
       }
       System.out.println("rep " + sumResult(results2) + " with " + sumResult(src));
       results2 = dst;
       Collections.sort(results2);
     }
     return;
   }
   //        System.out.println(dst);
   for (Result r : src) {
     List<Result> temp = new ArrayList<Result>(dst);
     temp.add(r);
     List<Result> temp2 = new ArrayList<Result>(src);
     temp2.remove(r);
     coll(srcMap, temp2, temp, 3, sumResult(temp));
   }
 }
Example #6
0
 public static void main(String[] args) {
   ArrayList nums = new ArrayList();
   nums.add(2);
   nums.add(-5);
   nums.add(3);
   nums.add(0);
   // 输出:[2, -5, 3, 0]
   System.out.println(nums);
   // 输出最大元素,将输出3
   System.out.println(Collections.max(nums));
   // 输出最小元素,将输出-5
   System.out.println(Collections.min(nums));
   // 将nums中的0使用1来代替
   Collections.replaceAll(nums, 0, 1);
   // 输出:[2, -5, 3, 1]
   System.out.println(nums);
   // 判断-5 在List集合中出现的次数,返回1
   System.out.println(Collections.frequency(nums, -5));
   // 对nums集合排序
   Collections.sort(nums);
   // 输出:[-5, 1, 2, 3]
   System.out.println(nums);
   // 只有排序后的List集合才可用二分法查询,输出3
   System.out.println(Collections.binarySearch(nums, 3));
 }