java.util.TreeMap#remove ( )源码实例Demo

下面列出了java.util.TreeMap#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ACManager   文件: RankCalculator.java
private boolean[] teatWaClear(TeamRanking ranking, int capacity) {
    List<PbStatus> list = ranking.getPbStatus();
    boolean[] ans = new boolean[list.size()];
    TreeMap<PbStatus, Integer> ac = new TreeMap<>();
    int waCnt = 0;
    for (int i = 0; i < list.size(); ++i) {
        if(list.get(i).isSolved()) {
            waCnt += list.get(i).getWaCount();
            if(list.get(i).getWaCount() == 0) //1A奖励
                waCnt -= 1;
            ac.put(list.get(i), i);
        }
    }
    while(ac.size() >= 2 && waCnt > ac.size() * capacity) {
        Map.Entry<PbStatus, Integer> entry = ac.lastEntry();
        ans[entry.getValue()] = true;
        waCnt -= entry.getKey().getWaCount();
        ac.remove(entry.getKey());
    }
    return ans;
}
 
源代码2 项目: Ngram-Graphs   文件: EntropyChunker.java
protected Integer[] splitPointsByDelimiterList(String sStr, SortedMap lDelimiters) {
    ArrayList alRes = new ArrayList();
    TreeMap lLocal = new TreeMap();
    lLocal.putAll(lDelimiters);
    
    // For every candidate delimiter
    while (lLocal.size() > 0) {
        Object oNext = lLocal.lastKey();
        // Get all split points
        int iNextSplit = 0;
        int iLastSplit = 0;
        while ((iNextSplit = sStr.indexOf((String)lDelimiters.get(oNext), iLastSplit)) > -1) {
            // TODO : Check
            alRes.add(new Integer(iNextSplit + ((String)lDelimiters.get(oNext)).length()));
            iLastSplit = iNextSplit + 1;
        }
        
        lLocal.remove(oNext);
    }
    Integer [] iaRes = new Integer[alRes.size()];
    alRes.toArray(iaRes);
    gr.demokritos.iit.jinsect.utils.bubbleSortArray(iaRes);
    
    return iaRes;
}
 
源代码3 项目: Ngram-Graphs   文件: EntropyChunker.java
protected Integer[] splitPointsByDelimiterList(String sStr, SortedMap lDelimiters) {
    ArrayList alRes = new ArrayList();
    TreeMap lLocal = new TreeMap();
    lLocal.putAll(lDelimiters);
    
    // For every candidate delimiter
    while (lLocal.size() > 0) {
        Object oNext = lLocal.lastKey();
        // Get all split points
        int iNextSplit = 0;
        int iLastSplit = 0;
        while ((iNextSplit = sStr.indexOf((String)lDelimiters.get(oNext), iLastSplit)) > -1) {
            // TODO : Check
            alRes.add(new Integer(iNextSplit + ((String)lDelimiters.get(oNext)).length()));
            iLastSplit = iNextSplit + 1;
        }
        
        lLocal.remove(oNext);
    }
    Integer [] iaRes = new Integer[alRes.size()];
    alRes.toArray(iaRes);
    gr.demokritos.iit.jinsect.utils.bubbleSortArray(iaRes);
    
    return iaRes;
}
 
源代码4 项目: jumbune   文件: MultiValueTreeMap.java
/**
 * Adds the value to the collection associated with the given key
 * @param reference
 * @param value
 */
public void add(K reference, V value){
	TreeMap<V, LinkedList<V>> innerMap;
	innerMap = get(reference);
	LinkedList<V> list;
	if(innerMap!=null){
		list = innerMap.get(value);
		if(list!=null){
			list.add(value);
		}else{
			list = new LinkedList<V>();
			innerMap.put(value, list);
			list.add(value);
		}
	}else {
		innerMap = new TreeMap<V, LinkedList<V>>();
		put(reference, innerMap);
		list = new LinkedList<V>();
		list.add(value);
		innerMap.put(value, list);
	}
	if (innerMap.size() > MAX_STORED_ELEMENTS){
		innerMap.remove(innerMap.lastKey());
	}
}
 
源代码5 项目: dremio-oss   文件: DremioORCRecordUtils.java
@Override
public ByteBuffer getBuffer(boolean direct, int length) {
  if (direct) {
    ArrowBuf buf = allocator.buffer(length);
    ByteBuffer retBuf = buf.nioBuffer(0, length);
    directBufMap.put(new ByteBufferWrapper(retBuf), buf);
    return retBuf;
  } else {
    TreeMap<DremioORCRecordUtils.ByteBufferAllocatorPool.Key, ByteBuffer> tree = getBufferTree();
    Map.Entry<DremioORCRecordUtils.ByteBufferAllocatorPool.Key, ByteBuffer> entry = tree.ceilingEntry(new DremioORCRecordUtils.ByteBufferAllocatorPool.Key(length, 0));
    if (entry == null) {
      return ByteBuffer.allocate(length);
    }
    tree.remove(entry.getKey());
    return entry.getValue();
  }
}
 
源代码6 项目: openjdk-jdk9   文件: TreeMapTest.java
/**
 * pollLastEntry returns entries in order
 */
public void testPollLastEntry() {
    TreeMap map = map5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(four, e.getKey());
    map.put(five, "E");
    e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(three, e.getKey());
    map.remove(two);
    e = map.pollLastEntry();
    assertEquals(one, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollLastEntry();
    assertNull(e);
}
 
源代码7 项目: j2objc   文件: TreeMapTest.java
/**
 * remove(null) throws NPE for nonempty map
 */
public void testRemove1_NullPointerException() {
    TreeMap c = new TreeMap();
    c.put("sadsdf", "asdads");
    try {
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码8 项目: java-technology-stack   文件: Solution.java
public V remove(K key){
    V ret = null;
    TreeMap<K, V> map = hashtable[hash(key)];
    if(map.containsKey(key)){
        ret = map.remove(key);
        size --;

        if(size < lowerTol * M && M / 2 >= initCapacity)
            resize(M / 2);
    }
    return ret;
}
 
源代码9 项目: chipster   文件: BackupRotation.java
/**
 * Remove last n files of the sorted map (i.e. keep the original files on disk).
 * 
 * @param filesToDelete
 * @param count
 */
private void removeLastItems(TreeMap<DateTime, File> filesToDelete, int count) {
	
	for (int i = 0; i < count; i++) {
		if (filesToDelete.isEmpty()) {
			break;
		}
		filesToDelete.remove(filesToDelete.lastKey());
	}
}
 
源代码10 项目: java-technology-stack   文件: Solution.java
public V remove(K key){
    V ret = null;
    TreeMap<K, V> map = hashtable[hash(key)];
    if(map.containsKey(key)){
        ret = map.remove(key);
        size --;
    }
    return ret;
}
 
源代码11 项目: qcloud-cos-sts-sdk   文件: Request.java
public static String send(TreeMap<String, Object> params, String secretId,
		String secretKey, String requestMethod, String requestHost, String stsHost,
		String requestPath) {
	if (!params.containsKey("SecretId"))
		params.put("SecretId", secretId);

	if (!params.containsKey("Nonce"))
		params.put("Nonce",
				new Random().nextInt(Integer.MAX_VALUE));

	if (!params.containsKey("Timestamp"))
		params.put("Timestamp", System.currentTimeMillis() / 1000);

	params.remove("Signature");
	String plainText = Sign.makeSignPlainText(params, requestMethod,
			stsHost, requestPath);

	String signatureMethod = "HmacSHA1";
	if(params.containsKey("SignatureMethod") && params.get("SignatureMethod").toString().equals("HmacSHA256"))
	{
		signatureMethod = "HmacSHA256";
	}

	try {
		params.put("Signature", Sign.sign(plainText, secretKey, signatureMethod));
	} catch (Exception e) {
		throw new IllegalStateException(e.getMessage(), e);
	}

	String url = "https://" + requestHost + requestPath;

	return sendRequest(url, params, requestMethod);
}
 
源代码12 项目: HuobiRobot   文件: HuobiService.java
/**
 * 获取账号详情
 * 
 * @param method
 * @return
 * @throws Exception
 */
public String getAccountInfo(String method) throws Exception {
	TreeMap<String, Object> paraMap = new TreeMap<String, Object>();
	paraMap.put("method", method);
	paraMap.put("created", getTimestamp());
	paraMap.put("access_key", huobiAccessKey);
	paraMap.put("secret_key", huobiSecretKey);
	String md5 = sign(paraMap);
	paraMap.remove("secret_key");
	paraMap.put("sign", md5);
	return post(paraMap, huobiApiUrl);
}
 
源代码13 项目: java-data-structure   文件: HashTable.java
public V remove(K key) {
    TreeMap<K, V> map = hashtable[hash(key)];
    V ret = null;
    if (map.containsKey(key)) {
        ret = map.remove(key);
        size--;

        // 缩容
        if (size <= lowerTol * M && capacityIndex - 1 >= 0)
            resize(capacity[--capacityIndex]);
    }

    return ret;
}
 
源代码14 项目: PoseidonX   文件: CollectionUtil.java
/**
 * <从事件排序集合中删除待删除事件,如果集合中有该事件,则删除。否则不删除>
 */
public static boolean removeEventByKey(Object sortKeys, IEvent event, TreeMap<Object, Object> sortedEvents)
{
    if (null == sortKeys || null == event || null == sortedEvents)
    {
        throw new RuntimeException();
    }
    
    Object obj = sortedEvents.get(sortKeys);
    if (null == obj)
    {
        return false;
    }
    else
    {
        if (obj instanceof List)
        {
            @SuppressWarnings("unchecked")
            List<IEvent> events = (List<IEvent>)obj;
            boolean result = events.remove(event);
            if (events.isEmpty())
            {
                sortedEvents.remove(sortKeys);
            }
            
            return result;
        }
        else if (obj.equals(event))
        {
            sortedEvents.remove(sortKeys);
            return true;
        }
    }
    
    return false;
}
 
源代码15 项目: hadoop   文件: ElasticByteBufferPool.java
@Override
public synchronized ByteBuffer getBuffer(boolean direct, int length) {
  TreeMap<Key, ByteBuffer> tree = getBufferTree(direct);
  Map.Entry<Key, ByteBuffer> entry =
      tree.ceilingEntry(new Key(length, 0));
  if (entry == null) {
    return direct ? ByteBuffer.allocateDirect(length) :
                    ByteBuffer.allocate(length);
  }
  tree.remove(entry.getKey());
  return entry.getValue();
}
 
源代码16 项目: HuobiRobot   文件: HuobiService.java
/**
 * 获取订单详情
 * 
 * @param coinType
 * @param id
 * @param method
 * @return
 * @throws Exception
 */
public String getOrderInfo(int coinType, long id, String method) throws Exception {
	TreeMap<String, Object> paraMap = new TreeMap<String, Object>();
	paraMap.put("method", method);
	paraMap.put("created", getTimestamp());
	paraMap.put("access_key", huobiAccessKey);
	paraMap.put("secret_key", huobiSecretKey);
	paraMap.put("coin_type", coinType);
	paraMap.put("id", id);
	String md5 = sign(paraMap);
	paraMap.remove("secret_key");
	paraMap.put("sign", md5);
	return post(paraMap, huobiApiUrl);
}
 
/**
 * Returns the gradient of this random variable with respect to all its leaf nodes.
 * The method calculated the map \( v \mapsto \frac{d u}{d v} \) where \( u \) denotes <code>this</code>.
 *
 * Performs a backward automatic differentiation.
 *
 * @return The gradient map.
 */
@Override
public Map<Long, RandomVariable> getGradient(final Set<Long> independentIDs) {

	// The map maintaining the derivatives id -> derivative
	final Map<Long, RandomVariable> derivatives = new HashMap<>();

	// Put derivative of this node w.r.t. itself
	derivatives.put(getID(), new RandomVariableFromDoubleArray(1.0));

	// The set maintaining the independents. Note: TreeMap is maintaining a sort on the keys.
	final TreeMap<Long, OperatorTreeNode> independents = new TreeMap<>();
	independents.put(getID(), getOperatorTreeNode());

	while(independents.size() > 0) {
		// Process node with the highest id in independents
		final Map.Entry<Long, OperatorTreeNode> independentEntry = independents.lastEntry();
		final Long id = independentEntry.getKey();
		final OperatorTreeNode independent = independentEntry.getValue();

		// Get arguments of this node and propagate derivative to arguments
		final List<OperatorTreeNode> arguments = independent.arguments;
		if(arguments != null && arguments.size() > 0) {
			independent.propagateDerivativesFromResultToArgument(derivatives);

			// Add all non constant arguments to the list of independents
			for(final OperatorTreeNode argument : arguments) {
				if(argument != null) {
					final Long argumentId = argument.id;
					independents.put(argumentId, argument);
				}
			}

			// Remove id from derivatives - keep only leaf nodes.
			derivatives.remove(id);
		}

		// Done with processing. Remove from map.
		independents.remove(id);
	}

	return derivatives;
}
 
源代码18 项目: mini2Dx   文件: LongTreeMapTest.java
private void remove(TreeMap<Long, String> treeMap, LongTreeMap<String> longTreeMap, long key) {
	treeMap.remove(key);
	longTreeMap.remove(key);
}
 
@Override
public Map<Long, RandomVariable> getGradient(final Set<Long> independentIDs) {

	// The map maintaining the derivatives id -> derivative
	final Map<Long, RandomVariable> derivatives = new HashMap<>();

	// Put derivative of this node w.r.t. itself
	derivatives.put(getID(), new RandomVariableFromDoubleArray(1.0));

	// The set maintaining the independents. Note: TreeMap is maintaining a sort on the keys.
	final TreeMap<Long, OperatorTreeNode> independents = new TreeMap<>();
	independents.put(getID(), getOperatorTreeNode());

	while(independents.size() > 0) {
		// Process node with the highest id in independents
		final Map.Entry<Long, OperatorTreeNode> independentEntry = independents.lastEntry();
		final Long id = independentEntry.getKey();
		final OperatorTreeNode independent = independentEntry.getValue();

		// Get arguments of this node and propagate derivative to arguments
		final List<OperatorTreeNode> arguments = independent.arguments;
		if(arguments != null && arguments.size() > 0) {
			independent.propagateDerivativesFromResultToArgument(derivatives);

			// Add all non constant arguments to the list of independents
			for(final OperatorTreeNode argument : arguments) {
				if(argument != null) {
					final Long argumentId = argument.id;
					independents.put(argumentId, argument);
				}
			}

			// Remove id from derivatives - keep only leaf nodes.
			derivatives.remove(id);
		}

		// Done with processing. Remove from map.
		independents.remove(id);
	}

	return derivatives;
}
 
源代码20 项目: android-Camera2Raw   文件: Camera2RawFragment.java
/**
 * If the given request has been completed, remove it from the queue of active requests and
 * send an {@link ImageSaver} with the results from this request to a background thread to
 * save a file.
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 *
 * @param requestId the ID of the {@link CaptureRequest} to handle.
 * @param builder   the {@link ImageSaver.ImageSaverBuilder} for this request.
 * @param queue     the queue to remove this request from, if completed.
 */
private void handleCompletionLocked(int requestId, ImageSaver.ImageSaverBuilder builder,
                                    TreeMap<Integer, ImageSaver.ImageSaverBuilder> queue) {
    if (builder == null) return;
    ImageSaver saver = builder.buildIfComplete();
    if (saver != null) {
        queue.remove(requestId);
        AsyncTask.THREAD_POOL_EXECUTOR.execute(saver);
    }
}