java.util.TreeMap.ceilingKey()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中java.util.TreeMap.ceilingKey()方法的一些代码示例,展示了TreeMap.ceilingKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeMap.ceilingKey()方法的具体详情如下:
包路径:java.util.TreeMap
类名称:TreeMap
方法名:ceilingKey

TreeMap.ceilingKey介绍

暂无

代码示例

代码示例来源:origin: kevin-wayne/algs4

/**
 * Returns the smallest key in this symbol table greater than or equal to {@code key}.
 *
 * @param  key the key
 * @return the smallest key in this symbol table greater than or equal to {@code key}
 * @throws NoSuchElementException if there is no such key
 * @throws IllegalArgumentException if {@code key} is {@code null}
 */
public Key ceiling(Key key) {
  if (key == null) throw new IllegalArgumentException("argument to ceiling() is null");
  Key k = st.ceilingKey(key);
  if (k == null) throw new NoSuchElementException("all keys are less than " + key);
  return k;
}

代码示例来源:origin: Netflix/EVCache

public MemcachedNode getNodeForKey(long _hash) {
  long start = (log.isDebugEnabled()) ? System.nanoTime() : 0;
  try {
    Long hash = Long.valueOf(_hash);
    hash = ketamaNodes.ceilingKey(hash);
    if (hash == null) {
      hash = ketamaNodes.firstKey();
    }
    return ketamaNodes.get(hash);
  } finally {
    if (log.isDebugEnabled()) {
      final long end = System.nanoTime();
      log.debug("getNodeForKey : \t" + (end - start) / 1000);
    }
  }
}

代码示例来源:origin: Netflix/EVCache

public MemcachedNode getPrimary(String k) {
  if (partialStringHash.get()) {
    final int index = k.indexOf(hashDelimiter.get());
    if (index > 0) {
      k = k.substring(0, index);
    }
  }
  final long _hash = hashingAlgorithm.hash(k);
  Long hash = Long.valueOf(_hash);
  hash = ketamaNodes.ceilingKey(hash);
  if (hash == null) {
    hash = ketamaNodes.firstKey();
  }
  return ketamaNodes.get(hash);
}

代码示例来源:origin: stanfordnlp/CoreNLP

HeadPosition getSeparator(int nodeNum) {
 if (nodeNum >= stack.size()) {
  return null;
 }
 TreeShapedStack<Tree> stack = this.stack;
 for (int i = 0; i < nodeNum; ++i) {
  stack = stack.pop();
 }
 Tree node = stack.peek();
 int head = ShiftReduceUtils.headIndex(node);
 if (separators.get(head) != null) {
  return HeadPosition.HEAD;
 }
 int left = ShiftReduceUtils.leftIndex(node);
 Integer nextLeft = separators.floorKey(head);
 boolean hasLeft = (nextLeft != null && nextLeft >= left);
 int right = ShiftReduceUtils.rightIndex(node);
 Integer nextRight = separators.ceilingKey(head);
 boolean hasRight = (nextRight != null && nextRight <= right);
 if (hasLeft && hasRight) {
  return HeadPosition.BOTH;
 } else if (hasLeft) {
  return HeadPosition.LEFT;
 } else if (hasRight) {
  return HeadPosition.RIGHT;
 } else {
  return HeadPosition.NONE;
 }
}

代码示例来源:origin: guolindev/giffun

@Override
public Bitmap get(int width, int height, Bitmap.Config config) {
  final int size = Util.getBitmapByteSize(width, height, config);
  Key key = keyPool.get(size);
  Integer possibleSize = sortedSizes.ceilingKey(size);
  if (possibleSize != null && possibleSize != size && possibleSize <= size * MAX_SIZE_MULTIPLE) {
    keyPool.offer(key);
    key = keyPool.get(possibleSize);
  }
  // Do a get even if we know we don't have a bitmap so that the key moves to the front in the lru pool
  final Bitmap result = groupedMap.get(key);
  if (result != null) {
    result.reconfigure(width, height, config);
    decrementBitmapOfSize(possibleSize);
  }
  return result;
}

代码示例来源:origin: matsim-org/matsim

@Override
public void requestNewTime(final int time) {
  Double ceil = timesteps.ceilingKey((double) time);
  if (ceil != null) {
    this.nextTime = ceil;
  } else if (!timesteps.isEmpty()) {
    this.nextTime = timesteps.lastKey();
  } else {
    this.nextTime = -1;
  }
  this.currentBuffer = null;
}

代码示例来源:origin: edu.princeton.cs/algs4

/**
 * Returns the smallest key in this symbol table greater than or equal to {@code key}.
 *
 * @param  key the key
 * @return the smallest key in this symbol table greater than or equal to {@code key}
 * @throws NoSuchElementException if there is no such key
 * @throws IllegalArgumentException if {@code key} is {@code null}
 */
public Key ceiling(Key key) {
  if (key == null) throw new IllegalArgumentException("called ceiling() with null key");
  Key k = st.ceilingKey(key);
  if (k == null) throw new NoSuchElementException("all keys are less than " + key);
  return k;
}

代码示例来源:origin: brianway/algorithms-learning

/**
 * Returns the smallest key in this symbol table greater than or equal to <tt>key</tt>.
 *
 * @param key the key
 * @return the smallest key in this symbol table greater than or equal to <tt>key</tt>
 * @throws NoSuchElementException if there is no such key
 * @throws NullPointerException   if <tt>key</tt> is <tt>null</tt>
 */
public Key ceiling(Key key) {
  if (key == null) throw new NullPointerException("called ceiling() with null key");
  Key k = st.ceilingKey(key);
  if (k == null) throw new NoSuchElementException("all keys are less than " + key);
  return k;
}

代码示例来源:origin: stackoverflow.com

TreeMap<Integer, Integer> treeMap = new TreeMap<>();
int key = RandomUtils.ranInt(treeMap.lastKey());
int value = treeMap.ceilingKey(key);

代码示例来源:origin: stackoverflow.com

public static boolean haveCommonKeys(TreeMap<String,?> map1, TreeMap<String,?> map2) {
  if(map1.isEmpty()) return false;
  for(String s=map1.firstKey(); s!=null; ) {
    String s2=map2.ceilingKey(s);
    if(s2==null) break;
    if(s2.equals(s)) return true;
    s=map1.ceilingKey(s2);
    if(s2.equals(s)) return true;
  }
  return false;
}

代码示例来源:origin: org.xerial.java/xerial-core

public T findBy(String prefix) {
  if (prefix == null)
    return null;
  String nextKey = holder.ceilingKey(prefix);
  if (nextKey == null)
    return null;
  SortedMap<String, T> tail = holder.tailMap(nextKey);
  for (String key : tail.keySet()) {
    if (key.startsWith(prefix)) {
      return tail.get(key);
    }
  }
  return null;
}

代码示例来源:origin: i-m-c/jenkins-inheritance-plugin

public Version getVersion(Long id) {
  if (id == null) { return null; }
  Version v = this.store.ceilingKey(new Version(id));
  if (v != null && v.id.equals(id)) {
    return v;
  } else {
    return null;
  }
}

代码示例来源:origin: hudson.plugins/project-inheritance

public Version getVersion(Long id) {
  if (id == null) { return null; }
  Version v = this.store.ceilingKey(new Version(id));
  if (v != null && v.id.equals(id)) {
    return v;
  } else {
    return null;
  }
}

代码示例来源:origin: Nepxion/Thunder

private T getNodeForKey(long hash) {
    final T rv;
    if (!ketamaNodes.containsKey(hash)) {
      // Java 1.6 adds a ceilingKey method, but I'm still stuck in 1.5
      // in a lot of places, so I'm doing this myself.
      /*SortedMap<Long, T> tailMap = ketamaNodes.tailMap(hash);
      if (tailMap.isEmpty()) {
        hash = ketamaNodes.firstKey();
      } else {
        hash = tailMap.firstKey();
      }*/
      
      Long newHash = ketamaNodes.ceilingKey(hash);  
      if (newHash == null) {
        hash = ketamaNodes.firstKey();
      } else {
        hash = newHash.longValue();
      }
    }
    rv = ketamaNodes.get(hash);
    return rv;
  }
}

代码示例来源:origin: stackoverflow.com

private static Double getClosest(TreeMap<Double, String> mySet, Double d) {
   if (mySet.ceilingKey(d) != null && mySet.floorKey(d) != null){
     if( Math.abs(d - mySet.ceilingKey(d)) < Math.abs(d - mySet.floorKey(d)) )
       return mySet.ceilingKey(d);
     else
       return mySet.floorKey(d);
   }
   else if (mySet.ceilingKey(d) == null && mySet.floorKey(d) != null) {
     return mySet.floorKey(d);
   } else if (mySet.ceilingKey(d) != null && mySet.floorKey(d) == null) {
     return mySet.ceilingKey(d);
   } else
     return null;
 }

代码示例来源:origin: stackoverflow.com

TreeMap<Integer, String> treeMap = new TreeMap<Integer, String>();
 treeMap.put(100, "MarshalLib100");
 treeMap.put(110, "MarshalLib110");
 treeMap.put(102, "MarshalLib102");
 treeMap.put(101, "MarshalLib101");
 treeMap.put(150, "MarshalLib150");
 System.out.println(treeMap.floorKey(102));
 System.out.println(treeMap.floorEntry(102)); 
 System.out.println(treeMap.ceilingKey(102));
 System.out.println(treeMap.ceilingEntry(102));

代码示例来源:origin: com.taobao.metamorphosis/metamorphosis-client

private String findConsumerByPartition(final TreeMap<Long, String> consumerMap, final String partition) {
  final Long hash = this.alg.hash(partition);
  Long target = hash;
  if (!consumerMap.containsKey(hash)) {
    target = consumerMap.ceilingKey(hash);
    // if (hash == null) {
    // target = consumerMap.floorKey(hash);
    // }
    // else {
    // final Long floor = consumerMap.floorKey(hash);
    // if (floor != null) {
    // target = Math.abs(hash - floor) > Math.abs(hash - target) ?
    // target : floor;
    // }
    // }
    if (target == null && !consumerMap.isEmpty()) {
      target = consumerMap.firstKey();
    }
  }
  final String targetConsumer = consumerMap.get(target);
  return targetConsumer;
}

代码示例来源:origin: gsvigruha/cosyan

@Override
public int read() throws IOException {
 if (act == null) {
  return -1;
 }
 if (pointerInAct < act.length) {
  return act[pointerInAct++] & 0xff;
 } else {
  Long next = map.ceilingKey(pointer + 1);
  if (next == null) {
   return -1;
  }
  seek(next);
  return read();
 }
}

代码示例来源:origin: MSGFPlus/msgfplus

public String getMatchingEntry(String name) {
  String key = this.header2ends.ceilingKey(name);
  if (key == null || !key.startsWith(name)) return null;
  int position = this.header2ends.get(key) - 1;
  Integer start = annotations.floorKey(position);   // always "_" at start
  Integer end = annotations.higherKey(position);    // exclusive
  if (start == null) start = 0;
  if (end == null) end = (int) this.getSize();
  while (!isValid(end - 1)) end--;     // ensure that the last character is valid (exclusive)
  return this.getSubsequence(start + 1, end);
}

代码示例来源:origin: mozilla-tw/Rocket

@Override
@Nullable
public Bitmap get(int width, int height, Bitmap.Config config) {
 final int size = Util.getBitmapByteSize(width, height, config);
 Key key = keyPool.get(size);
 Integer possibleSize = sortedSizes.ceilingKey(size);
 if (possibleSize != null && possibleSize != size && possibleSize <= size * MAX_SIZE_MULTIPLE) {
  keyPool.offer(key);
  key = keyPool.get(possibleSize);
 }
 // Do a get even if we know we don't have a bitmap so that the key moves to the front in the
 // lru pool
 final Bitmap result = groupedMap.get(key);
 if (result != null) {
  result.reconfigure(width, height, config);
  decrementBitmapOfSize(possibleSize);
 }
 return result;
}

相关文章