Java Code Examples for java.util.TreeMap#remove()

The following examples show how to use java.util.TreeMap#remove() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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;
}
 
Example 2
Source Project: Ngram-Graphs   File: EntropyChunker.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source Project: Ngram-Graphs   File: EntropyChunker.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
/**
 * 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());
	}
}
 
Example 5
Source Project: dremio-oss   File: DremioORCRecordUtils.java    License: Apache License 2.0 6 votes vote down vote up
@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();
  }
}
 
Example 6
/**
 * 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);
}
 
Example 7
Source Project: j2objc   File: TreeMapTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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) {}
}
 
Example 8
Source Project: java-technology-stack   File: Solution.java    License: MIT License 5 votes vote down vote up
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;
}
 
Example 9
Source Project: chipster   File: BackupRotation.java    License: MIT License 5 votes vote down vote up
/**
 * 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());
	}
}
 
Example 10
Source Project: java-technology-stack   File: Solution.java    License: MIT License 5 votes vote down vote up
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;
}
 
Example 11
Source Project: qcloud-cos-sts-sdk   File: Request.java    License: MIT License 5 votes vote down vote up
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);
}
 
Example 12
Source Project: HuobiRobot   File: HuobiService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取账号详情
 * 
 * @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);
}
 
Example 13
Source Project: java-data-structure   File: HashTable.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source Project: PoseidonX   File: CollectionUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <从事件排序集合中删除待删除事件,如果集合中有该事件,则删除。否则不删除>
 */
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;
}
 
Example 15
Source Project: hadoop   File: ElasticByteBufferPool.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 16
Source Project: HuobiRobot   File: HuobiService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取订单详情
 * 
 * @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);
}
 
Example 17
/**
 * 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;
}
 
Example 18
Source Project: mini2Dx   File: LongTreeMapTest.java    License: Apache License 2.0 4 votes vote down vote up
private void remove(TreeMap<Long, String> treeMap, LongTreeMap<String> longTreeMap, long key) {
	treeMap.remove(key);
	longTreeMap.remove(key);
}
 
Example 19
@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;
}
 
Example 20
/**
 * 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);
    }
}