本文整理汇总了Java中java.util.HashMap.remove方法的典型用法代码示例。如果您正苦于以下问题:Java HashMap.remove方法的具体用法?Java HashMap.remove怎么用?Java HashMap.remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashMap
的用法示例。
在下文中一共展示了HashMap.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nodeProperty
import java.util.HashMap; //导入方法依赖的package包/类
@Usage("node-property <id> <key>")
@Named("node-property")
@Command
public void nodeProperty(InvocationContext<ObjectName> context,
@Usage("the node id") @Required @Argument final String id,
@Usage("the property key") @Required @Argument final String key) throws Exception {
HashMap<String, Object> node = Server.db.getNode(id);
if (node == null) {
throw new Err(Status.NOT_FOUND);
} else {
node.remove(key);
Server.db.updateNode(id, node);
node = Server.db.getNode(id);
context.append(mapper.writeValueAsString(node));
}
}
示例2: relationshipProperty
import java.util.HashMap; //导入方法依赖的package包/类
@Usage("relationship-property <type> <from> <to> <key>")
@Named("relationship-property")
@Command
public void relationshipProperty(InvocationContext<ObjectName> context,
@Usage("the relationship type") @Required @Argument final String type,
@Usage("the starting node") @Required @Argument final String from,
@Usage("the ending node") @Required @Argument final String to,
@Usage("the property key") @Required @Argument final String key) throws Exception {
HashMap<String, Object> rel = Server.db.getRelationship(type, from, to);
if (rel == null) {
throw new Err(Status.NOT_FOUND);
} else {
rel.remove(key);
Server.db.updateRelationship(type, from, to, rel);
rel = Server.db.getRelationship(type, from, to);
context.append(mapper.writeValueAsString(rel));
}
}
示例3: fetchPositionListIndexesStatic
import java.util.HashMap; //导入方法依赖的package包/类
protected static List<PositionListIndex> fetchPositionListIndexesStatic(List<HashMap<String, IntArrayList>> clusterMaps, boolean isNullEqualNull) {
List<PositionListIndex> clustersPerAttribute = new ArrayList<>();
for (int columnId = 0; columnId < clusterMaps.size(); columnId++) {
List<IntArrayList> clusters = new ArrayList<>();
HashMap<String, IntArrayList> clusterMap = clusterMaps.get(columnId);
if (!isNullEqualNull)
clusterMap.remove(null);
for (IntArrayList cluster : clusterMap.values())
if (cluster.size() > 1)
clusters.add(cluster);
clustersPerAttribute.add(new PositionListIndex(columnId, clusters));
}
return clustersPerAttribute;
}
示例4: removeLastItem
import java.util.HashMap; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public void removeLastItem() {
try {
// remove the item from the cache
HashMap cache = getCache();
if (cache != null) {
Object item = getItem(m_pool.getSize() - 1);
cache.remove(item);
}
// remove the actual item
// based off of LongVector.addElement()
Object items = m_items.get(m_pool);
Object[][] objects = (Object[][])m_objects.get(items);
int numElements = (Integer)m_elements.get(items) - 1;
int nth = numElements >> 7;
int offset = numElements & (128 - 1);
objects[nth][offset] = null;
// decrement the number of items
m_elements.set(items, numElements);
m_numItems.set(m_pool, (Integer)m_numItems.get(m_pool) - 1);
} catch (Exception ex) {
throw new Error(ex);
}
}
示例5: deleteKVConfig
import java.util.HashMap; //导入方法依赖的package包/类
public void deleteKVConfig(final String namespace, final String key) {
try {
this.lock.writeLock().lockInterruptibly();
try {
HashMap<String, String> kvTable = this.configTable.get(namespace);
if (null != kvTable) {
String value = kvTable.remove(key);
log.info("deleteKVConfig delete a config item, Namespace: {} Key: {} Value: {}", //
namespace, key, value);
}
}
finally {
this.lock.writeLock().unlock();
}
}
catch (InterruptedException e) {
log.error("deleteKVConfig InterruptedException", e);
}
this.persist();
}
示例6: testGetItemsMissingValue
import java.util.HashMap; //导入方法依赖的package包/类
@Test
public void testGetItemsMissingValue() throws Exception {
// Get test bean
ConfigurationBean bean = getTestBean();
// Remove one default value from controller settings
HashMap<String, Setting> def_settings = platformService
.getControllerSettings("ess.common",
new PasswordAuthentication("user", "password"));
def_settings.remove(ControllerConfigurationKey.BSS_ORGANIZATION_ID
.name());
def_settings.remove("TEST1");
platformService.storeControllerSettings("ess.common", def_settings,
new PasswordAuthentication("user", "password"));
// Get default items (missing value must be defined with an empty
// string!)
List<ConfigurationItem> items = bean.getAccessItems();
assertNotNull(items);
assertEquals(4, items.size());
// Check the missing value
ConfigurationItem item = findItem(items, "BSS_ORGANIZATION_ID");
assertEquals("", item.getValue());
}
示例7: main
import java.util.HashMap; //导入方法依赖的package包/类
public static void main(String[] args) {
HashMap<Integer, Integer> map = new HashMap<>();
ArrayDeque<Integer> deque = new ArrayDeque<>();
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int max = 0;
for (int i = 0; i < n; i++) {
/* Remove old value (if necessary) */
if (i >= m) {
int old = deque.removeFirst();
if (map.get(old) == 1) {
map.remove(old);
} else {
map.merge(old, -1, Integer::sum);
}
}
/* Add new value */
int num = scan.nextInt();
deque.addLast(num);
map.merge(num, 1, Integer::sum);
max = Math.max(max, map.size());
}
scan.close();
System.out.println(max);
}
示例8: getTopTags
import java.util.HashMap; //导入方法依赖的package包/类
public CSList<TextTag> getTopTags(int nTags, HashMap<String,TextTag> tags) throws Exception {
int resLen = nTags < tags.size() ? nTags : tags.size();
CSList<TextTag> res = new CSList<TextTag>();
String tag = null;
float maxWeight;
for (int i = 0;i < resLen;i++)
{
maxWeight = Float.MIN_VALUE;
for (TextTag t : tags.values())
{
if (t.getWeight() > maxWeight)
{
tag = t.getWord();
maxWeight = t.getWeight();
}
}
res.add(new TextTag(tag, maxWeight, true));
tags.remove(tag);
if (res.size() > nTags)
break;
}
return res;
}
示例9: resetToken
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Reset the saved transaction token from request in the user's session.
*
* @param request
* The servlet request
*/
public synchronized void resetToken(HttpServletRequest request) {
HttpSession session = request.getSession(false);
if (session == null) {
return;
}
HashMap tokens = getTokens(session);
if (tokens == null) {
return;
}
String token = getTokenFromRequest(request);
if (token == null) {
return;
}
tokens.remove(token);
}
示例10: markComponent
import java.util.HashMap; //导入方法依赖的package包/类
public void markComponent(Component comp, int dx, int dy) {
HashMap<Location, String> avoid = this.avoid;
boolean translated = dx != 0 || dy != 0;
Bounds bds = comp.getBounds();
int x0 = bds.getX() + dx;
int y0 = bds.getY() + dy;
int x1 = x0 + bds.getWidth();
int y1 = y0 + bds.getHeight();
x0 += 9 - (x0 + 9) % 10;
y0 += 9 - (y0 + 9) % 10;
for (int x = x0; x <= x1; x += 10) {
for (int y = y0; y <= y1; y += 10) {
Location loc = Location.create(x, y);
// loc is most likely in the component, so go ahead and
// put it into the map as if it is - and in the rare event
// that loc isn't in the component, we can remove it.
String prev = avoid.put(loc, Connector.ALLOW_NEITHER);
if (prev != Connector.ALLOW_NEITHER) {
Location baseLoc = translated ? loc.translate(-dx, -dy) : loc;
if (!comp.contains(baseLoc)) {
if (prev == null) {
avoid.remove(loc);
} else {
avoid.put(loc, prev);
}
}
}
}
}
}
示例11: unregisterProducer
import java.util.HashMap; //导入方法依赖的package包/类
public void unregisterProducer(final String group, final ClientChannelInfo clientChannelInfo) {
try {
if (this.groupChannelLock.tryLock(LockTimeoutMillis, TimeUnit.MILLISECONDS)) {
try {
HashMap<Channel, ClientChannelInfo> channelTable = this.groupChannelTable.get(group);
if (null != channelTable && !channelTable.isEmpty()) {
ClientChannelInfo old = channelTable.remove(clientChannelInfo.getChannel());
if (old != null) {
log.info("unregister a producer[{}] from groupChannelTable {}", group,
clientChannelInfo.toString());
}
if (channelTable.isEmpty()) {
this.groupChannelTable.remove(group);
log.info("unregister a producer group[{}] from groupChannelTable", group);
}
}
}
finally {
this.groupChannelLock.unlock();
}
}
else {
log.warn("ProducerManager unregisterProducer lock timeout");
}
}
catch (InterruptedException e) {
log.error("", e);
}
}
示例12: mapToHashtable
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Converts a map into a valid hash table, i.e.
* it removes all the 'null' values from the map.
*/
public static <K, V> Hashtable<K, V> mapToHashtable(Map<K, V> map) {
HashMap<K, V> m = new HashMap<K, V>(map);
if (m.containsKey(null)) m.remove(null);
for (Iterator<?> i = m.values().iterator(); i.hasNext(); )
if (i.next() == null) i.remove();
return new Hashtable<K, V>(m);
}
示例13: show
import java.util.HashMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void show(Context context) {
HashMap<String, Object> shareParamsMap = new HashMap<String, Object>();
shareParamsMap.putAll(params);
MobSDK.init(context.getApplicationContext());
ShareSDK.initSDK(context);
// 打开分享菜单的统计
ShareSDK.logDemoEvent(1, null);
int iTheme = 0;
try {
iTheme = ResHelper.parseInt(String.valueOf(shareParamsMap.remove("theme")));
} catch (Throwable t) {}
OnekeyShareTheme theme = OnekeyShareTheme.fromValue(iTheme);
OnekeyShareThemeImpl themeImpl = theme.getImpl();
themeImpl.setShareParamsMap(shareParamsMap);
themeImpl.setDialogMode(shareParamsMap.containsKey("dialogMode") ? ((Boolean) shareParamsMap.remove("dialogMode")) : false);
themeImpl.setSilent(shareParamsMap.containsKey("silent") ? ((Boolean) shareParamsMap.remove("silent")) : false);
themeImpl.setCustomerLogos((ArrayList<CustomerLogo>) shareParamsMap.remove("customers"));
themeImpl.setHiddenPlatforms((HashMap<String, String>) shareParamsMap.remove("hiddenPlatforms"));
themeImpl.setPlatformActionListener((PlatformActionListener) shareParamsMap.remove("callback"));
themeImpl.setShareContentCustomizeCallback((ShareContentCustomizeCallback) shareParamsMap.remove("customizeCallback"));
if (shareParamsMap.containsKey("disableSSO") ? ((Boolean) shareParamsMap.remove("disableSSO")) : false) {
themeImpl.disableSSO();
}
themeImpl.show(context.getApplicationContext());
}
示例14: removeTemplate
import java.util.HashMap; //导入方法依赖的package包/类
final <T> ImmutableInternalData removeTemplate(ProxyLookup proxy, Template<T> template) {
if (getResults().containsKey(template)) {
HashMap<Template,Reference<R>> c = new HashMap<Template, Reference<ProxyLookup.R>>(getResults());
Reference<R> ref = c.remove(template);
if (ref != null && ref.get() != null) {
// seems like there is a reference to a result for this template
// thta is still alive
return this;
}
return create(getRawLookups(), c);
} else {
return this;
}
}
示例15: remove
import java.util.HashMap; //导入方法依赖的package包/类
public static void remove(Symbol symbol) {
HashMap<Type, ArrayList<Symbol>> vars = SYMBOL_STACK.peek();
if (vars.containsKey(symbol.type)) {
ArrayList<Symbol> symbolsOfType = vars.get(symbol.type);
symbolsOfType.remove(symbol);
if (symbolsOfType.isEmpty()) {
vars.remove(symbol.type);
}
}
}