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

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

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

TreeMap.headMap介绍

暂无

代码示例

代码示例来源:origin: commons-collections/commons-collections

/**
 * Return a view of the portion of this map whose keys are strictly
 * less than the specified key.
 *
 * @param key Key higher than any in the returned map
 * @return a head map
 */
public SortedMap headMap(Object key) {
  if (fast) {
    return (map.headMap(key));
  } else {
    synchronized (map) {
      return (map.headMap(key));
    }
  }
}

代码示例来源:origin: wildfly/wildfly

/**
 * Return a view of the portion of this map whose keys are strictly
 * less than the specified key.
 *
 * @param key Key higher than any in the returned map
 * @return a head map
 */
public SortedMap headMap(Object key) {
  if (fast) {
    return (map.headMap(key));
  } else {
    synchronized (map) {
      return (map.headMap(key));
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Splits the range set at the given timestamp (if it hasn't been split yet)
 */
private void splitAt(long t) {
  if (data.containsKey(t)) return; // already split at this timestamp
  SortedMap<Long, int[]> head = data.headMap(t);
  int v = head.isEmpty() ? 0 : data.get(head.lastKey())[0];
  data.put(t, new int[]{v});
}

代码示例来源:origin: alibaba/jstorm

public Object getPreviousState(long txid) {
  SortedMap<Long, Object> prevMap = _curr.headMap(txid);
  if(prevMap.isEmpty()) return null;
  else return prevMap.get(prevMap.lastKey());
}

代码示例来源:origin: apache/storm

public Object getPreviousState(long txid) {
  final SortedMap<Long, Object> prevMap = _curr.headMap(txid);
  Object state;
  if (prevMap.isEmpty()) {
    state = null;
  } else {
    state = prevMap.get(prevMap.lastKey());
  }
  LOG.debug("Getting previous [state = {}], [txid = {}]", state, txid);
  LOG.trace("[{}]", this);
  return state;
}

代码示例来源:origin: alibaba/jstorm

public void cleanupBefore(BigInteger txid) {
  Set<BigInteger> toDelete = new HashSet<>();
  toDelete.addAll(_curr.headMap(txid).keySet());
  for (BigInteger tx : toDelete) {
    _curr.remove(tx);
    _state.delete(txPath(tx));
  }
}

代码示例来源:origin: goldmansachs/gs-collections

public MutableSortedMap<K, V> headMap(K toKey)
{
  return SortedMapAdapter.adapt(this.treeMap.headMap(toKey));
}

代码示例来源:origin: eclipse/eclipse-collections

@Override
public MutableSortedMap<K, V> headMap(K toKey)
{
  return SortedMapAdapter.adapt(this.treeMap.headMap(toKey));
}

代码示例来源:origin: eclipse/eclipse-collections

@Override
public MutableSortedMap<K, V> headMap(K toKey)
{
  return SortedMapAdapter.adapt(this.treeMap.headMap(toKey));
}

代码示例来源:origin: apache/storm

private TreeMap<Long, Integer> getStoredCurrAttempts(long currTransaction, int maxBatches) {
  TreeMap<Long, Integer> ret = new TreeMap<Long, Integer>();
  for (TransactionalState state : _states) {
    Map<Object, Number> attempts = (Map) state.getData(CURRENT_ATTEMPTS);
    if (attempts == null) {
      attempts = new HashMap();
    }
    for (Entry<Object, Number> e : attempts.entrySet()) {
      // this is because json doesn't allow numbers as keys...
      // TODO: replace json with a better form of encoding
      Number txidObj;
      if (e.getKey() instanceof String) {
        txidObj = Long.parseLong((String) e.getKey());
      } else {
        txidObj = (Number) e.getKey();
      }
      long txid = ((Number) txidObj).longValue();
      int attemptId = ((Number) e.getValue()).intValue();
      Integer curr = ret.get(txid);
      if (curr == null || attemptId > curr) {
        ret.put(txid, attemptId);
      }
    }
  }
  ret.headMap(currTransaction).clear();
  ret.tailMap(currTransaction + maxBatches - 1).clear();
  return ret;
}

代码示例来源:origin: alibaba/mdrill

public void cleanupBefore(BigInteger txid) {
  SortedMap<BigInteger, Object> toDelete = _curr.headMap(txid);
  for(BigInteger tx: new HashSet<BigInteger>(toDelete.keySet())) {
    _curr.remove(tx);
    _state.delete(txPath(tx));
  }
}

代码示例来源:origin: apache/storm

public void cleanupBefore(long txid) {
  SortedMap<Long, Object> toDelete = _curr.headMap(txid);
  for (long tx : new HashSet<Long>(toDelete.keySet())) {
    _curr.remove(tx);
    try {
      _state.delete(txPath(tx));
    } catch (RuntimeException e) {
      // Ignore NoNodeExists exceptions because when sync() it may populate _curr with stale data since
      // zookeeper reads are eventually consistent.
      if (!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) {
        throw e;
      }
    }
  }
}

代码示例来源:origin: apache/usergrid

/**
 * Get all shards <= this one in descending order
 */
public Iterator<ShardEntryGroup> getShards( final Long maxShard ) {
  final Long firstKey = shards.floorKey( maxShard );
  return Collections.unmodifiableCollection( shards.headMap( firstKey, true ).descendingMap().values()).iterator();
}

代码示例来源:origin: apache/storm

public Object getState(long txid, StateInitializer init) {
  if (!_curr.containsKey(txid)) {
    SortedMap<Long, Object> prevMap = _curr.headMap(txid);
    SortedMap<Long, Object> afterMap = _curr.tailMap(txid);
    Long prev = null;
    if (!prevMap.isEmpty()) {
      prev = prevMap.lastKey();
    }
    Object data;
    if (afterMap.isEmpty()) {
      Object prevData;
      if (prev != null) {
        prevData = _curr.get(prev);
      } else {
        prevData = null;
      }
      data = init.init(txid, prevData);
    } else {
      data = null;
    }
    _curr.put(txid, data);
    _state.setData(txPath(txid), data);
  }
  Object state = _curr.get(txid);
  LOG.debug("Getting or initializing state. [txid = {}] => [state = {}]", txid, state);
  LOG.trace("[{}]", this);
  return state;
}

代码示例来源:origin: alibaba/jstorm

public void cleanupBefore(long txid) {
  SortedMap<Long, Object> toDelete = _curr.headMap(txid);
  for(long tx: new HashSet<>(toDelete.keySet())) {
    _curr.remove(tx);
    try {
      _state.delete(txPath(tx));
    } catch(RuntimeException e) {
      // Ignore NoNodeExists exceptions because when sync() it may populate _curr with stale data since
      // zookeeper reads are eventually consistent.
      if(!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) {
        throw e;
      }
    }
  }
}

代码示例来源:origin: alibaba/jstorm

public Object getState(long txid, StateInitializer init) {
  if(!_curr.containsKey(txid)) {
    SortedMap<Long, Object> prevMap = _curr.headMap(txid);
    SortedMap<Long, Object> afterMap = _curr.tailMap(txid);            
    
    Long prev = null;
    if(!prevMap.isEmpty()) prev = prevMap.lastKey();            
    
    Object data;
    if(afterMap.isEmpty()) {
      Object prevData;
      if(prev!=null) {
        prevData = _curr.get(prev);
      } else {
        prevData = null;
      }
      data = init.init(txid, prevData);
    } else {
      data = null;
    }
    _curr.put(txid, data);
    _state.setData(txPath(txid), data);
  }
  return _curr.get(txid);
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public int named(String name) {
  return instrumentedMethod.getStackSize()
      + exitType.getStackSize().getSize()
      + StackSize.of(namedTypes.headMap(name).values());
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public int named(String name) {
  return instrumentedMethod.getStackSize()
      + exitType.getStackSize().getSize()
      + StackSize.of(namedTypes.headMap(name).values());
}

代码示例来源:origin: apache/storm

@Override
public void execute(BatchInfo info, Tuple input) {
  // there won't be a BatchInfo for the success stream
  TransactionAttempt attempt = (TransactionAttempt) input.getValue(0);
  if (input.getSourceStreamId().equals(MasterBatchCoordinator.COMMIT_STREAM_ID)) {
    if (attempt.equals(_activeBatches.get(attempt.getTransactionId()))) {
      ((ICommitterTridentSpout.Emitter) _emitter).commit(attempt);
      _activeBatches.remove(attempt.getTransactionId());
    } else {
      throw new FailedException("Received commit for different transaction attempt");
    }
  } else if (input.getSourceStreamId().equals(MasterBatchCoordinator.SUCCESS_STREAM_ID)) {
    // valid to delete before what's been committed since 
    // those batches will never be accessed again
    _activeBatches.headMap(attempt.getTransactionId()).clear();
    _emitter.success(attempt);
  } else {
    _collector.setBatch(info.batchId);
    _emitter.emitBatch(attempt, input.getValue(1), _collector);
    _activeBatches.put(attempt.getTransactionId(), attempt);
  }
}

代码示例来源:origin: alibaba/jstorm

@Override
public void execute(BatchInfo info, Tuple input) {
  // there won't be a BatchInfo for the success stream
  TransactionAttempt attempt = (TransactionAttempt) input.getValue(0);
  if (input.getSourceStreamId().equals(MasterBatchCoordinator.COMMIT_STREAM_ID)) {
    if (attempt.equals(_activeBatches.get(attempt.getTransactionId()))) {
      ((ICommitterTridentSpout.Emitter) _emitter).commit(attempt);
      _activeBatches.remove(attempt.getTransactionId());
    } else {
      throw new FailedException("Received commit for different transaction attempt");
    }
  } else if (input.getSourceStreamId().equals(MasterBatchCoordinator.SUCCESS_STREAM_ID)) {
    // valid to delete before what's been committed since
    // those batches will never be accessed again
    _activeBatches.headMap(attempt.getTransactionId()).clear();
    _emitter.success(attempt);
  } else {
    _collector.setBatch(info.batchId);
    _emitter.emitBatch(attempt, input.getValue(1), _collector);
    _activeBatches.put(attempt.getTransactionId(), attempt);
  }
}

相关文章

微信公众号

最新文章

更多