/** * Removes all copies of the specified object from the bag. * * @param object the object to remove * @return true if the bag changed */ public virtual bool remove(Object obj) { MutableInteger mut = (MutableInteger)map.get(obj); if (mut == null) { return(false); } modCount++; map.remove(obj); sizeJ -= mut.value; return(true); }
bool addProvider(Object provider) { ProviderNode node = new ProviderNode(provider); nodeMap.put(provider, node); Object obj = providers.put(provider.getClass(), provider); if (obj != null) { nodeMap.remove(obj); return(false); } return(true); }
public bool remove(Object obj) { int size = map.size(); map.remove(obj); return(map.size() != size); }
public Object next() { if (firstNodes.empty()) { throw new java.util.NoSuchElementException(); } // get a node from firstNodes ProviderNode node = firstNodes.pop(); // find all the outgoing nodes java.util.Iterator <Object> it = node.getOutgoingNodes(); while (it.hasNext()) { ProviderNode outNode = (ProviderNode)it.next(); // remove the incoming edge from the node. int edges = incomingEdges.get(outNode); edges--; incomingEdges.put(outNode, new java.lang.Integer(edges)); // add to the firstNodes if this node's incoming edge is equal to 0 if (edges == 0) { firstNodes.push(outNode); } } incomingEdges.remove(node); return(node.getProvider()); }
/** * Create a new Transformer that calls one of the transformers depending * on the predicates. * <p> * The Map consists of Predicate keys and Transformer values. A transformer * is called if its matching predicate returns true. Each predicate is evaluated * until one returns true. If no predicates evaluate to true, the default * transformer is called. The default transformer is set in the map with a * null key. The ordering is that of the iterator() method on the entryset * collection of the map. * * @param predicatesAndTransformers a map of predicates to transformers * @return the <code>switch</code> transformer * @throws IllegalArgumentException if the map is null * @throws IllegalArgumentException if any transformer in the map is null * @throws ClassCastException if the map elements are of the wrong type */ public static Transformer getInstance(java.util.Map <Object, Object> predicatesAndTransformers) { Transformer[] transformers = null; Predicate[] preds = null; if (predicatesAndTransformers == null) { throw new java.lang.IllegalArgumentException("The predicate and transformer map must not be null"); } if (predicatesAndTransformers.size() == 0) { return(ConstantTransformer.NULL_INSTANCE); } // convert to array like this to guarantee iterator() ordering Transformer defaultTransformer = (Transformer)predicatesAndTransformers.remove(null); int size = predicatesAndTransformers.size(); if (size == 0) { return(defaultTransformer == null ? ConstantTransformer.NULL_INSTANCE : defaultTransformer); } transformers = new Transformer[size]; preds = new Predicate[size]; int i = 0; for (java.util.Iterator <Object> it = (java.util.Iterator <Object>)predicatesAndTransformers.entrySet().iterator(); it.hasNext();) { java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next(); preds[i] = (Predicate)entry.getKey(); transformers[i] = (Transformer)entry.getValue(); i++; } return(new SwitchTransformer(preds, transformers, defaultTransformer)); }
/** * Create a new Closure that calls one of the closures depending * on the predicates. * <p> * The Map consists of Predicate keys and Closure values. A closure * is called if its matching predicate returns true. Each predicate is evaluated * until one returns true. If no predicates evaluate to true, the default * closure is called. The default closure is set in the map with a * null key. The ordering is that of the iterator() method on the entryset * collection of the map. * * @param predicatesAndClosures a map of predicates to closures * @return the <code>switch</code> closure * @throws IllegalArgumentException if the map is null * @throws IllegalArgumentException if any closure in the map is null * @throws ClassCastException if the map elements are of the wrong type */ public static Closure getInstance(java.util.Map <Object, Object> predicatesAndClosures) { Closure[] closures = null; Predicate[] preds = null; if (predicatesAndClosures == null) { throw new java.lang.IllegalArgumentException("The predicate and closure map must not be null"); } if (predicatesAndClosures.size() == 0) { return(NOPClosure.INSTANCE); } // convert to array like this to guarantee iterator() ordering Closure defaultClosure = (Closure)predicatesAndClosures.remove(null); int size = predicatesAndClosures.size(); if (size == 0) { return(defaultClosure == null ? NOPClosure.INSTANCE : defaultClosure); } closures = new Closure[size]; preds = new Predicate[size]; int i = 0; for (java.util.Iterator <Object> it = (java.util.Iterator <Object>)predicatesAndClosures.entrySet().iterator(); it.hasNext();) { java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next(); preds[i] = (Predicate)entry.getKey(); closures[i] = (Closure)entry.getValue(); i++; } return(new SwitchClosure(preds, closures, defaultClosure)); }
/** * Flushes the <code>BeanInfo</code> caches of the specified bean class * * @param clazz * the specified bean class */ public static void flushFromCaches(java.lang.Class clazz) { if (clazz == null) { throw new java.lang.NullPointerException(); } theCache.remove(clazz); }
/** * Walks through all recorded entries and adds the data available * from the local file header. * * <p>Also records the offsets for the data to read from the * entries.</p> */ private void resolveLocalFileHeaderData(java.util.Map <ZipArchiveEntry, IAC_NameAndComment> entriesWithoutUTF8Flag) //throws IOException { java.util.Enumeration <ZipArchiveEntry> e = getEntries(); while (e.hasMoreElements()) { ZipArchiveEntry ze = e.nextElement(); IAC_OffsetEntry offsetEntry = entries.get(ze); long offset = offsetEntry.headerOffset; archive.seek(offset + LFH_OFFSET_FOR_FILENAME_LENGTH); byte[] b = new byte[SHORT]; archive.readFully(b); int fileNameLen = ZipShort.getValue(b); archive.readFully(b); int extraFieldLen = ZipShort.getValue(b); int lenToSkip = fileNameLen; while (lenToSkip > 0) { int skipped = archive.skipBytes(lenToSkip); if (skipped <= 0) { throw new java.lang.RuntimeException("failed to skip file name in" + " local file header"); } lenToSkip -= skipped; } byte[] localExtraData = new byte[extraFieldLen]; archive.readFully(localExtraData); ze.setExtra(localExtraData); /*dataOffsets.put(ze, * new Long(offset + LFH_OFFSET_FOR_FILENAME_LENGTH + SHORT + SHORT + fileNameLen + extraFieldLen)); */ offsetEntry.dataOffset = offset + LFH_OFFSET_FOR_FILENAME_LENGTH + SHORT + SHORT + fileNameLen + extraFieldLen; if (entriesWithoutUTF8Flag.containsKey(ze)) { String orig = ze.getName(); IAC_NameAndComment nc = (IAC_NameAndComment)entriesWithoutUTF8Flag.get(ze); ZipUtil.setNameAndCommentFromExtraFields(ze, nc.name, nc.comment); if (!orig.equals(ze.getName())) { nameMap.remove(orig); nameMap.put(ze.getName(), ze); } } } }
bool removeProvider(Object provider, ServiceRegistry registry, java.lang.Class category) { Object obj = providers.get(provider.getClass()); if ((obj == null) || (obj != provider)) { return(false); } providers.remove(provider.getClass()); nodeMap.remove(provider); if (provider is RegisterableService) { ((RegisterableService)provider).onDeregistration(registry, category); } return(true); }
/** * Puts a key-value mapping into the map at the specified index. * <p> * If the map already contains the key, then the original mapping * is removed and the new mapping added at the specified index. * The remove may change the effect of the index. The index is * always calculated relative to the original state of the map. * <p> * Thus the steps are: (1) remove the existing key-value mapping, * then (2) insert the new key-value mapping at the position it * would have been inserted had the remove not ocurred. * * @param index the index at which the mapping should be inserted * @param key the key * @param value the value * @return the value previously mapped to the key * @throws IndexOutOfBoundsException if the index is out of range * @since Commons Collections 3.2 */ public virtual Object put(int index, Object key, Object value) { java.util.Map <Object, Object> m = getMap(); if (m.containsKey(key)) { Object result = m.remove(key); int pos = insertOrder.indexOf(key); insertOrder.remove(pos); if (pos < index) { index--; } insertOrder.add(index, key); m.put(key, value); return(result); } else { insertOrder.add(index, key); m.put(key, value); return(null); } }
/** * Create a new Transformer that uses the input object as a key to find the * transformer to call. * <p> * The Map consists of object keys and Transformer values. A transformer * is called if the input object equals the key. If there is no match, the * default transformer is called. The default transformer is set in the map * using a null key. If no default is set, null will be returned in a default case. * * @see org.apache.commons.collections.functors.SwitchTransformer * * @param objectsAndTransformers a map of objects to transformers * @return the transformer * @throws IllegalArgumentException if the map is null * @throws IllegalArgumentException if the map is empty * @throws IllegalArgumentException if any transformer in the map is null */ public static Transformer switchMapTransformer(java.util.Map <Object, Object> objectsAndTransformers) { Transformer[] trs = null; Predicate[] preds = null; if (objectsAndTransformers == null) { throw new java.lang.IllegalArgumentException("The object and transformer map must not be null"); } Transformer def = (Transformer)objectsAndTransformers.remove(null); int size = objectsAndTransformers.size(); trs = new Transformer[size]; preds = new Predicate[size]; int i = 0; for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = objectsAndTransformers.entrySet().iterator(); it.hasNext();) { java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next(); preds[i] = EqualPredicate.getInstance(entry.getKey()); trs[i] = (Transformer)entry.getValue(); i++; } return(switchTransformer(preds, trs, def)); }
public virtual bool remove(Object obj, int nCopies) { _mods++; bool result = false; int count = getCount(obj); if (nCopies <= 0) { result = false; } else if (count > nCopies) { _map.put(obj, new java.lang.Integer(count - nCopies)); result = true; _total -= nCopies; } else { // count > 0 && count <= i // need to remove all result = (_map.remove(obj) != null); _total -= count; } return(result); }
/** * Create a new Closure that uses the input object as a key to find the * closure to call. * <p> * The Map consists of object keys and Closure values. A closure * is called if the input object equals the key. If there is no match, the * default closure is called. The default closure is set in the map * using a null key. * * @see org.apache.commons.collections.functors.SwitchClosure * * @param objectsAndClosures a map of objects to closures * @return the closure * @throws IllegalArgumentException if the map is null * @throws IllegalArgumentException if the map is empty * @throws IllegalArgumentException if any closure in the map is null */ public static Closure switchMapClosure(java.util.Map <Object, Object> objectsAndClosures) { Closure[] trs = null; Predicate[] preds = null; if (objectsAndClosures == null) { throw new java.lang.IllegalArgumentException("The object and closure map must not be null"); } Closure def = (Closure)objectsAndClosures.remove(null); int size = objectsAndClosures.size(); trs = new Closure[size]; preds = new Predicate[size]; int i = 0; for (java.util.Iterator <java.util.MapNS.Entry <Object, Object> > it = objectsAndClosures.entrySet().iterator(); it.hasNext();) { java.util.MapNS.Entry <Object, Object> entry = it.next(); preds[i] = EqualPredicate.getInstance(entry.getKey()); trs[i] = (Closure)entry.getValue(); i++; } return(switchClosure(preds, trs, def)); }
public virtual Object remove(Object key) { return(map.remove(key)); }