本文整理汇总了Java中java.util.LinkedHashMap.remove方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedHashMap.remove方法的具体用法?Java LinkedHashMap.remove怎么用?Java LinkedHashMap.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.LinkedHashMap
的用法示例。
在下文中一共展示了LinkedHashMap.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public static void main(String[] args) {
//create LinkedHashMap object
LinkedHashMap lHashMap = new LinkedHashMap();
//add key value pairs to LinkedHashMap
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
/*
To remove a key value pair from LinkedHashMap use
Object remove(Object key) method of LinkedHashMap class.
It returns either the value mapped with the key previously or null if no value
was mapped.
*/
Object obj = lHashMap.remove("2");
System.out.println(obj + " Removed from LinkedHashMap");
}
示例2: main
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public static void main(String[] args) {
//create LinkedHashMap object
LinkedHashMap lHashMap = new LinkedHashMap();
/*
To get the size of LinkedHashMap use
int size() method of LinkedHashMap class. It returns the number of key value
pairs stored in LinkedHashMap object.
*/
System.out.println("Size of LinkedHashMap : " + lHashMap.size());
//add key value pairs to LinkedHashMap using put method
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
System.out.println("Size of LinkedHashMap after addition : " + lHashMap.size());
//remove one element from LinkedHashMap using remove method
Object obj = lHashMap.remove("2");
System.out.println("Size of LinkedHashMap after removal : " + lHashMap.size());
}
示例3: unregisterScope
import java.util.LinkedHashMap; //导入方法依赖的package包/类
/**
* Unregister the scope with given <code>name</code>
* @param classLoader ClassLoader
* @param name Scope name
* @return <code>true</code> if unregistered
*/
public synchronized boolean unregisterScope(ClassLoader classLoader, String name) {
ObjectUtils.argumentNotNull(name, "Scope name must be not null");
final ClassLoader cl = classLoader == null ? getDefaultClassLoader() : classLoader;
ensureInited(cl);
final boolean removed;
LinkedHashMap<String, ContextScope> contextScopes = scopes.get(cl);
if (contextScopes.containsKey(name)) {
contextScopes.remove(name);
removed = true;
} else {
removed = false;
}
LOGGER.debug(() -> "Unregistered scope with name [" + name + "] for classloader [" + cl
+ "] - was registered: " + removed);
return removed;
}
示例4: setActivityFeedbackLookupId
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public static void setActivityFeedbackLookupId(Context context, String lookupId, String feedbackType) {
LinkedHashMap<String, String> lookupIds = getActivityFeedbackLookupId(context);
lookupIds.put(lookupId, feedbackType);
if (lookupIds.size() > 30) {
lookupIds.remove(lookupIds.size() - 1);
}
String json = new GsonBuilder().create().toJson(lookupIds);
SharedPreferences.Editor editor = getEditor(context);
editor.putString(FEEDBACK_ACTIVITY_LIST, json);
editor.apply();
}
示例5: sortHashMapByValues
import java.util.LinkedHashMap; //导入方法依赖的package包/类
/**
* Sorts LinkedHashMap by its values(natural descending order). keeps the
* duplicates as it is.
*
* @param passedMap
* An Object of type LinkedHashMap to be sorted by its values.
* @return An Object containing the sorted LinkedHashMap.
*/
private LinkedHashMap<?,?> sortHashMapByValues(LinkedHashMap<String,String> passedMap) {
List<String> mapKeys = new ArrayList<String>(passedMap.keySet());
List<String> mapValues = new ArrayList<String>(passedMap.values());
Collections.sort(mapValues, new ValueComparator());
Collections.sort(mapKeys);
// Reversing the collection to sort the values in descending order
Collections.reverse(mapValues);
LinkedHashMap<String,String> sortedMap = new LinkedHashMap<String,String>();
Iterator<String> valueIt = mapValues.iterator();
while (valueIt.hasNext()) {
String val = valueIt.next();
Iterator<String> keyIt = mapKeys.iterator();
while (keyIt.hasNext()) {
String key = keyIt.next();
String comp1 = passedMap.get(key).toString();
String comp2 = val.toString();
if (comp1.equals(comp2)) {
passedMap.remove(key);
mapKeys.remove(key);
sortedMap.put(key, val);
break;
}
}
}
return sortedMap;
}
示例6: sortHashMapByValues
import java.util.LinkedHashMap; //导入方法依赖的package包/类
/**
* Sorts LinkedHashMap by its values(natural descending order). keeps the
* duplicates as it is.
*
* @param passedMap
* An Object of type LinkedHashMap to be sorted by its values.
*
* @return An Object containing the sorted LinkedHashMap.
*/
private LinkedHashMap<String,String> sortHashMapByValues(LinkedHashMap<String,String> passedMap) {
List<String> mapKeys = new ArrayList<String>(passedMap.keySet());
List<String> mapValues = new ArrayList<String>(passedMap.values());
Collections.sort(mapValues, new ValueComparator());
Collections.sort(mapKeys);
Collections.reverse(mapValues);
LinkedHashMap<String,String> sortedMap = new LinkedHashMap<String,String>();
Iterator<String> valueIt = mapValues.iterator();
while (valueIt.hasNext()) {
String val = valueIt.next();
Iterator<String> keyIt = mapKeys.iterator();
while (keyIt.hasNext()) {
String key = keyIt.next();
String comp1 = passedMap.get(key).toString();
String comp2 = val.toString();
if (comp1.equals(comp2)) {
passedMap.remove(key);
mapKeys.remove(key);
sortedMap.put(key, val);
break;
}
}
}
return sortedMap;
}
示例7: setCustomDisplayProperty
import java.util.LinkedHashMap; //导入方法依赖的package包/类
@Override
public void setCustomDisplayProperty(String key, Object value)
{
LinkedHashMap<String, Object> map = getCustomDisplayMap();
if( value != null )
{
map.put(key, value);
}
else
{
map.remove(key);
}
wrapped.setData(AttachmentUtils.CUSTOM_DISPLAY_KEY, map);
}
示例8: addNumericUpdate
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public void addNumericUpdate(NumericDocValuesUpdate update, int docIDUpto) {
LinkedHashMap<Term,NumericDocValuesUpdate> fieldUpdates = numericUpdates.get(update.field);
if (fieldUpdates == null) {
fieldUpdates = new LinkedHashMap<>();
numericUpdates.put(update.field, fieldUpdates);
bytesUsed.addAndGet(BYTES_PER_NUMERIC_FIELD_ENTRY);
}
final NumericDocValuesUpdate current = fieldUpdates.get(update.term);
if (current != null && docIDUpto < current.docIDUpto) {
// Only record the new number if it's greater than or equal to the current
// one. This is important because if multiple threads are replacing the
// same doc at nearly the same time, it's possible that one thread that
// got a higher docID is scheduled before the other threads.
return;
}
update.docIDUpto = docIDUpto;
// since it's a LinkedHashMap, we must first remove the Term entry so that
// it's added last (we're interested in insertion-order).
if (current != null) {
fieldUpdates.remove(update.term);
}
fieldUpdates.put(update.term, update);
numNumericUpdates.incrementAndGet();
if (current == null) {
bytesUsed.addAndGet(BYTES_PER_NUMERIC_UPDATE_ENTRY + update.sizeInBytes());
}
}
示例9: addBinaryUpdate
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public void addBinaryUpdate(BinaryDocValuesUpdate update, int docIDUpto) {
LinkedHashMap<Term,BinaryDocValuesUpdate> fieldUpdates = binaryUpdates.get(update.field);
if (fieldUpdates == null) {
fieldUpdates = new LinkedHashMap<>();
binaryUpdates.put(update.field, fieldUpdates);
bytesUsed.addAndGet(BYTES_PER_BINARY_FIELD_ENTRY);
}
final BinaryDocValuesUpdate current = fieldUpdates.get(update.term);
if (current != null && docIDUpto < current.docIDUpto) {
// Only record the new number if it's greater than or equal to the current
// one. This is important because if multiple threads are replacing the
// same doc at nearly the same time, it's possible that one thread that
// got a higher docID is scheduled before the other threads.
return;
}
update.docIDUpto = docIDUpto;
// since it's a LinkedHashMap, we must first remove the Term entry so that
// it's added last (we're interested in insertion-order).
if (current != null) {
fieldUpdates.remove(update.term);
}
fieldUpdates.put(update.term, update);
numBinaryUpdates.incrementAndGet();
if (current == null) {
bytesUsed.addAndGet(BYTES_PER_BINARY_UPDATE_ENTRY + update.sizeInBytes());
}
}
示例10: removeBatchLoadableCollection
import java.util.LinkedHashMap; //导入方法依赖的package包/类
/**
* After a collection was initialized or evicted, we don't
* need to batch fetch it anymore, remove it from the queue
* if necessary
*/
public void removeBatchLoadableCollection(CollectionEntry ce) {
LinkedHashMap<CollectionEntry, PersistentCollection> map = batchLoadableCollections.get( ce.getLoadedPersister().getRole() );
if ( map != null ) {
map.remove( ce );
}
}
示例11: runDestructionCallbacks
import java.util.LinkedHashMap; //导入方法依赖的package包/类
protected void runDestructionCallbacks() {
LinkedHashMap<String, Runnable> index = DESTRUCTION_CALLBACKS.get();
DESTRUCTION_CALLBACKS.remove();
List<String> names = Lists.reverse(Lists.newArrayList(index.keySet()));
for (String name : names) {
Runnable callback = index.remove(name);
run(name, callback);
}
}
示例12: BSONObject
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public BSONObject(String BSONString) throws BSONException {
this.bson = new LinkedHashMap<String, Object>();
BSONString bs = new BSONString();
LinkedHashMap<String, Object> map = bs.getBSON(BSONString);
String msg = (String) map.get(BSON.TAG_MSG);
if (msg.equals(BSON.MSG_BSON)) {
String tag = (String) map.get(BSON.TAG_KEY);
String value = (String) map.get(BSON.TAG_VALUE);
LinkedHashMap<String, Object> hm = bs.getValue(value);
bson.put(tag, hm.get(BSON.TAG_VALUE));
} else if (msg.equals(BSON.MSG_BSON_ARRAY)) {
map.remove(BSON.TAG_MSG);
Iterator<Entry<String, Object>> iter = map.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, Object> entry = (Entry<String, Object>) iter.next();
bson.put(entry.getKey(), entry.getValue());
}
} else if (msg.equals(BSON.MSG_BSON_EMPTY)) {
BSON.Warn(BSON.MSG_BSON_EMPTY);
} else if (msg.equals(BSON.MSG_ERROR_NOTBSON)) {
throw new BSONException(msg);
} else if (msg.equals(BSON.MSG_ERROR_EMPTY)) {
throw new BSONException(msg);
} else {
throw new BSONException(BSON.MSG_ERROR_UNKNOW);
}
}
示例13: getNamedParameters
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public LinkedHashSet<NamedParameter> getNamedParameters(String resource, boolean excludeOverriden) throws Exception {
LinkedHashMap<String, NamedParameter> namedParameters = new LinkedHashMap<String, NamedParameter>();
Method method = getAnnotatedMethod(resource);
if (method != null) {
MethodParameterNames annotation = method.getAnnotation(MethodParameterNames.class);
String[] parameterNames = null;
if (annotation != null) {
parameterNames = annotation.value();
}
Class[] parameterTypes = method.getParameterTypes();
if (parameterNames != null && parameterTypes != null) {
for (int i = 0; i < parameterNames.length; i++) {
namedParameters.put(parameterNames[i], new NamedParameter(parameterNames[i], parameterTypes[i]));
}
}
}
Iterator<Entry<String, Object>> it = defaults.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Object> defaultParameter = it.next();
if (!namedParameters.containsKey(defaultParameter.getKey())) {
namedParameters.put(defaultParameter.getKey(), new NamedParameter(defaultParameter.getKey(), defaultParameter.getValue().getClass()));
}
}
it = overrides.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Object> overrideParameter = it.next();
namedParameters.put(overrideParameter.getKey(), new NamedParameter(overrideParameter.getKey(), overrideParameter.getValue().getClass()));
}
if (excludeOverriden) {
it = overrides.entrySet().iterator();
while (it.hasNext()) {
namedParameters.remove(it.next().getKey());
}
}
return new LinkedHashSet<NamedParameter>(namedParameters.values());
}
示例14: fix
import java.util.LinkedHashMap; //导入方法依赖的package包/类
private void fix() {
/*
* Useful references:
* http://tools.ietf.org/html/rfc4121#page-5
* http://tools.ietf.org/html/rfc2743#page-81
* https://msdn.microsoft.com/en-us/library/ms995330.aspx
*/
// Scan until we find the mech types list. If we find anything
// unexpected, abort the fix process.
if (!tag(0x60)) return;
if (!length()) return;
if (!oid("1.3.6.1.5.5.2")) return;
if (!tag(0xa0)) return;
if (!length()) return;
if (!tag(0x30)) return;
if (!length()) return;
if (!tag(0xa0)) return;
lengthAsInt();
if (!tag(0x30)) return;
// Now at the start of the mechType list.
// Read the mechTypes into an ordered set
int mechTypesLen = lengthAsInt();
int mechTypesStart = pos;
LinkedHashMap<String, int[]> mechTypeEntries = new LinkedHashMap<String, int[]>();
while (pos < mechTypesStart + mechTypesLen) {
int[] value = new int[2];
value[0] = pos;
String key = oidAsString();
value[1] = pos - value[0];
mechTypeEntries.put(key, value);
}
// Now construct the re-ordered mechType list
byte[] replacement = new byte[mechTypesLen];
int replacementPos = 0;
int[] first = mechTypeEntries.remove("1.2.840.113554.1.2.2");
if (first != null) {
System.arraycopy(token, first[0], replacement, replacementPos, first[1]);
replacementPos += first[1];
}
for (int[] markers : mechTypeEntries.values()) {
System.arraycopy(token, markers[0], replacement, replacementPos, markers[1]);
replacementPos += markers[1];
}
// Finally, replace the original mechType list with the re-ordered
// one.
System.arraycopy(replacement, 0, token, mechTypesStart, mechTypesLen);
}
示例15: buildSearchContext
import java.util.LinkedHashMap; //导入方法依赖的package包/类
protected SearchContext buildSearchContext(long userId, long groupId, long ownerUserId, String workPackage,
String description, int status, Date fromDate, Date untilDate, LinkedHashMap<String, Object> params,
boolean andSearch, boolean advancedSearch, int start, int end, Sort sort) throws PortalException {
SearchContext searchContext = new SearchContext();
searchContext.setAttribute("advancedSearch", advancedSearch);
searchContext.setAttribute(Field.STATUS, status);
if (Validator.isNotNull(description)) {
searchContext.setAttribute("description", description);
}
searchContext.setAttribute("fromDate", fromDate);
searchContext.setAttribute("untilDate", untilDate);
if (Validator.isNotNull(workPackage)) {
searchContext.setAttribute("workPackage", workPackage);
}
searchContext.setAttribute("paginationType", "more");
Group group = GroupLocalServiceUtil.getGroup(groupId);
searchContext.setCompanyId(group.getCompanyId());
if (ownerUserId > 0) {
searchContext.setOwnerUserId(ownerUserId);
}
searchContext.setEnd(end);
if (groupId > 0) {
searchContext.setGroupIds(new long[] { groupId });
}
searchContext.setSorts(sort);
searchContext.setStart(start);
searchContext.setUserId(userId);
searchContext.setAndSearch(andSearch);
if (params != null) {
String keywords = (String) params.remove("keywords");
if (Validator.isNotNull(keywords)) {
searchContext.setKeywords(keywords);
}
}
QueryConfig queryConfig = new QueryConfig();
queryConfig.setHighlightEnabled(false);
queryConfig.setScoreEnabled(false);
searchContext.setQueryConfig(queryConfig);
if (sort != null) {
searchContext.setSorts(sort);
}
searchContext.setStart(start);
return searchContext;
}