下面列出了java.util.TreeMap#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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;
}
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;
}
/**
* 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());
}
}
@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();
}
}
/**
* 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);
}
/**
* 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) {}
}
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;
}
/**
* 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());
}
}
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;
}
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);
}
/**
* 获取账号详情
*
* @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);
}
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;
}
/**
* <从事件排序集合中删除待删除事件,如果集合中有该事件,则删除。否则不删除>
*/
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;
}
@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();
}
/**
* 获取订单详情
*
* @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;
}
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;
}
/**
* 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);
}
}