예제 #1
0
 @CollectionSize.Require(SEVERAL)
 public void testFloor() {
   resetWithHole();
   assertEquals(a, navigableMap.floorEntry(a.getKey()));
   assertEquals(a.getKey(), navigableMap.floorKey(a.getKey()));
   assertEquals(a, navigableMap.floorEntry(b.getKey()));
   assertEquals(a.getKey(), navigableMap.floorKey(b.getKey()));
   assertEquals(c, navigableMap.floorEntry(c.getKey()));
   assertEquals(c.getKey(), navigableMap.floorKey(c.getKey()));
 }
예제 #2
0
 @Override
 public double partialDeriv(int parameter, double... position) throws IndexOutOfBoundsException {
   Integer count = functionMap.floorKey(parameter);
   if (count == null) {
     throw new IndexOutOfBoundsException(
         "There are not enough parameters in the composite function");
   }
   return functionMap.get(count).partialDeriv(parameter - count, position);
 }
예제 #3
0
 @CollectionSize.Require(ZERO)
 public void testEmptyMapNearby() {
   assertNull(navigableMap.lowerEntry(samples.e0.getKey()));
   assertNull(navigableMap.lowerKey(samples.e0.getKey()));
   assertNull(navigableMap.floorEntry(samples.e0.getKey()));
   assertNull(navigableMap.floorKey(samples.e0.getKey()));
   assertNull(navigableMap.ceilingEntry(samples.e0.getKey()));
   assertNull(navigableMap.ceilingKey(samples.e0.getKey()));
   assertNull(navigableMap.higherEntry(samples.e0.getKey()));
   assertNull(navigableMap.higherKey(samples.e0.getKey()));
 }
예제 #4
0
 @CollectionSize.Require(ONE)
 public void testSingletonMapNearby() {
   assertNull(navigableMap.lowerEntry(samples.e0.getKey()));
   assertNull(navigableMap.lowerKey(samples.e0.getKey()));
   assertEquals(a, navigableMap.floorEntry(samples.e0.getKey()));
   assertEquals(a.getKey(), navigableMap.floorKey(samples.e0.getKey()));
   assertEquals(a, navigableMap.ceilingEntry(samples.e0.getKey()));
   assertEquals(a.getKey(), navigableMap.ceilingKey(samples.e0.getKey()));
   assertNull(navigableMap.higherEntry(samples.e0.getKey()));
   assertNull(navigableMap.higherKey(samples.e0.getKey()));
 }
예제 #5
0
  public static void main(String[] args) {
    LinkedHashMap<Integer, String> hashmap = new LinkedHashMap<Integer, String>();

    hashmap.put(1, "apple");
    hashmap.put(2, "lemon");
    hashmap.put(3, "orange");
    hashmap.put(4, "banana");
    hashmap.put(5, "litchi");
    hashmap.put(6, "mango");
    hashmap.put(7, "papaya");

    System.out.println(hashmap);

    System.out.println(valuesBetween(2, 5, hashmap));

    //        // note insertion order lost
    //        Map map1 = new HashMap<>();
    //        //for (int i = 1; i < 15; i++) {
    //        for (int i = 14; i > 0; i--) {
    //            map1.put(String.format("%04d", i), "");
    //            System.out.println(String.format("%04d:", i) + map1);
    //        }
    //
    //        map1 = new LinkedHashMap<>();
    //        //for (int i = 1; i < 15; i++) {
    //        for (int i = 14; i > 0; i--) {
    //            map1.put(String.format("%04d", i), "");
    //            System.out.println(String.format("%04d:", i) + map1);
    //        }

    Map<String, String> myMap = new HashMap<>();
    myMap.put("A", "1");
    myMap.put("B", "1");
    myMap.put("C", "1");
    System.out.println(myMap);

    myMap = new LinkedHashMap<>();
    myMap.put("A", "1");
    myMap.put("C", "1");
    myMap.put("B", "1");

    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();

    map.put(0, "Kid");
    map.put(11, "Teens");
    map.put(20, "Twenties");
    map.put(30, "Thirties");
    map.put(40, "Forties");
    map.put(50, "Senior");
    map.put(100, "OMG OMG OMG!");

    System.out.println(map.get(map.floorKey(13)));
    System.out.println(map.get(map.higherKey(20)));
  }
예제 #6
0
파일: OCPAgent.java 프로젝트: ccbon/ocp
 public Id getNodeId(Address address) throws Exception {
   if (nodeMap.size() == 0) {
     throw new Exception("nodeMap is not populated.");
   }
   LOG.info("nodeMap=" + nodeMap);
   Id nodeId = nodeMap.floorKey(address);
   if (nodeId == null) {
     nodeId = nodeMap.lastKey();
   }
   // if (nodeId == null) {
   // throw new Exception("nodeMap is not populated at all");
   // }
   return nodeId;
 }
예제 #7
0
 @Override
 public void postTxCommit() {
   if (scanStartRow != null) {
     if (!consumingEntries.isEmpty()) {
       // Start row can be updated to the largest rowKey in the consumingEntries (now is consumed)
       // that is smaller than or equal to scanStartRow
       byte[] floorKey = consumingEntries.floorKey(scanStartRow);
       if (floorKey != null) {
         startRow = floorKey;
       }
     } else {
       // If the dequeue has empty result, startRow can advance to scanStartRow
       startRow = Arrays.copyOf(scanStartRow, scanStartRow.length);
     }
   }
 }
예제 #8
0
  /**
   * lowInclusive and highInclusive are ignored if the respective bound in null (unbounded).
   *
   * @param low
   * @param lowInclusive
   * @param high
   * @param highInclusive
   * @return
   */
  public RangeApacheLogEntryIterator getIterator(
      Date low, Date high, boolean lowInclusive, boolean highInclusive) {
    NavigableMap<Date, File> subMap = dateToFile;

    Date adjustedLow = low == null ? null : dateToFile.floorKey(low);
    Date adjustedHigh = high == null ? null : dateToFile.ceilingKey(high);

    // lower bound
    if (adjustedLow != null) {
      subMap = subMap.tailMap(adjustedLow, true);
    }

    // upperbound
    if (adjustedHigh != null) {
      subMap = subMap.headMap(adjustedHigh, true);
    }

    logger.debug(
        "Adjust: Creating an iterator from "
            + adjustedLow
            + " until "
            + adjustedHigh
            + "; spanning "
            + subMap.size()
            + " files.");
    logger.debug(
        "Creating an iterator from "
            + low
            + " until "
            + high
            + "; spanning "
            + subMap.size()
            + " files.");

    return new RangeApacheLogEntryIterator(
        subMap.entrySet().iterator(), low, lowInclusive, high, highInclusive);
  }