/* * public HashMap getLeafElements() { HashMap map = new HashMap(); Object[] * elts = dataElements.values().toArray(); for (int j=0; j<elts.length; j++) * { PDMDataElement data = (PDMDataElement) elts[j]; * map.put(data.getID(),data); } Object[] ops = * operations.values().toArray(); for (int i=0; i<ops.length; i++){ * PDMOperation op = (PDMOperation) ops[i]; if * (!(op.getInputElements().isEmpty())){ HashMap outs = * op.getOutputElements(); Object[] outArray = outs.values().toArray(); for * (int j=0; j<outArray.length; j++) { PDMDataElement d = (PDMDataElement) * outArray[j]; map.remove(d.getID()); } } } return map; } */ public HashMap getLeafElements() { HashMap result = new HashMap(); HashSet leafOps = getLeafOperations(); if (!(leafOps.isEmpty())) { Iterator it = leafOps.iterator(); while (it.hasNext()) { PDMOperation op = (PDMOperation) it.next(); PDMDataElement data = op.getOutputElement(); result.put(data.getID(), data); } } else { Object[] elts = dataElements.values().toArray(); for (int j = 0; j < elts.length; j++) { PDMDataElement data = (PDMDataElement) elts[j]; result.put(data.getID(), data); } Object[] ops = operations.values().toArray(); for (int i = 0; i < ops.length; i++) { PDMOperation op = (PDMOperation) ops[i]; HashMap outs = op.getOutputElements(); Object[] outArray = outs.values().toArray(); for (int j = 0; j < outArray.length; j++) { PDMDataElement d = (PDMDataElement) outArray[j]; result.remove(d.getID()); } } } return result; }
/** Extracts document and cluster lists before serialization. */ @Persist private void beforeSerialization() { /* * See http://issues.carrot2.org/browse/CARROT-693; this monitor does not save us * in multi-threaded environment anyway. A better solution would be to prepare * this eagerly in the constructor, but we try to balance overhead and full * correctness here. */ synchronized (this) { query = (String) attributes.get(AttributeNames.QUERY); if (getDocuments() != null) { documents = Lists.newArrayList(getDocuments()); } else { documents = null; } if (getClusters() != null) { clusters = Lists.newArrayList(getClusters()); } else { clusters = null; } otherAttributesForSerialization = MapUtils.asHashMap(SimpleXmlWrappers.wrap(attributes)); otherAttributesForSerialization.remove(AttributeNames.QUERY); otherAttributesForSerialization.remove(AttributeNames.CLUSTERS); otherAttributesForSerialization.remove(AttributeNames.DOCUMENTS); if (otherAttributesForSerialization.isEmpty()) { otherAttributesForSerialization = null; } } }
/** Remove the temporary block file (if any) */ public synchronized void unfinalizeBlock(Block b) throws IOException { // remove the block from in-memory data structure ActiveFile activefile = ongoingCreates.remove(b); if (activefile == null) { return; } volumeMap.remove(b); // delete the on-disk temp file if (delBlockFromDisk(activefile.file, getMetaFile(activefile.file, b), b)) { DataNode.LOG.warn("Block " + b + " unfinalized and removed. "); } }
private static void unloadPlugin(String name) { loadedPlugins.get(name).unload(); loadedPlugins.remove(name); System.gc(); System.gc(); System.gc(); }
private static LinkedHashMap sortHashMapByValuesD(HashMap passedMap) { List mapKeys = new ArrayList(passedMap.keySet()); List mapValues = new ArrayList(passedMap.values()); Collections.sort(mapValues); Collections.sort(mapKeys); LinkedHashMap sortedMap = new LinkedHashMap(); Iterator valueIt = mapValues.iterator(); while (valueIt.hasNext()) { Object val = valueIt.next(); Iterator keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { Object 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; }
@Override public void update() { if (!transmitting) { super.update(); ArrayList deadMonsters = new ArrayList(); Monster monster = null; try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster != null) { monster.update(); if (monster.getIsDead()) { deadMonsters.add(key); } } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } } }
private void removeMonster(String monsterType) { Monster monster = null; ArrayList deadMonsters = new ArrayList(); try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster.getName().equals(monsterType)) { deadMonsters.add(key); break; } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } }
public void removeAllMonsters() { Monster monster = null; ArrayList deadMonsters = new ArrayList(); try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.getName().equals("Pig") && !monster.getName().equals("BlueThorn") && !monster.getName().equals("VineThorn")) { deadMonsters.add(key); if (gameController.multiplayerMode == gameController.multiplayerMode.SERVER && registry.getNetworkThread() != null) { if (registry.getNetworkThread().readyForUpdates()) { UpdateMonster um = new UpdateMonster(monster.getId()); um.mapX = monster.getMapX(); um.mapY = monster.getMapY(); um.action = "Die"; registry.getNetworkThread().sendData(um); } } } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } }
public <T> void removeAttribute(AttributeKey<T> key) { if (hasAttribute(key)) { T oldValue = key.get(this); attributes.remove(key); fireAttributeChanged(key, oldValue, key.getDefaultValue()); } }
public void sendrecv(Request request, Response response, long timeout) throws IOException { synchronized (response_map) { makeKey(request); response.isReceived = false; try { response_map.put(request, response); doSend(request); response.expiration = System.currentTimeMillis() + timeout; while (!response.isReceived) { response_map.wait(timeout); timeout = response.expiration - System.currentTimeMillis(); if (timeout <= 0) { throw new TransportException(name + " timedout waiting for response to " + request); } } } catch (IOException ioe) { if (log.level > 2) ioe.printStackTrace(log); try { disconnect(true); } catch (IOException ioe2) { ioe2.printStackTrace(log); } throw ioe; } catch (InterruptedException ie) { throw new TransportException(ie); } finally { response_map.remove(request); } } }
/** * Sets an application attribute. * * @param name the name of the attribute * @param value the value of the attribute */ public void setAttribute(String name, Object value) { Object oldValue; synchronized (_attributes) { if (value != null) oldValue = _attributes.put(name, value); else oldValue = _attributes.remove(name); } // Call any listeners if (_applicationAttributeListeners != null) { ServletContextAttributeEvent event; if (oldValue != null) event = new ServletContextAttributeEvent(this, name, oldValue); else event = new ServletContextAttributeEvent(this, name, value); for (int i = 0; i < _applicationAttributeListeners.size(); i++) { ServletContextAttributeListener listener; Object objListener = _applicationAttributeListeners.get(i); listener = (ServletContextAttributeListener) objListener; try { if (oldValue != null) listener.attributeReplaced(event); else listener.attributeAdded(event); } catch (Exception e) { log.log(Level.FINE, e.toString(), e); } } } }
private static void endInterpreter(String contextId) throws EvalError { Interpreter i = interpreters.get(contextId); if (i == null) return; i.eval("clear();"); // can't hurt to tell bsh to clean up internally interpreters.remove(contextId); // now wait for GC Log.log("Destroyed context: " + contextId + " (" + i + ")"); }
private void write(List<String> words, String documentsName) throws DictionaryException { for (int i = 0; i < words.size(); i++) { HashMap<String, Integer> hashMap = new HashMap<String, Integer>(); if (dictionary.containsKey(words.get(i))) { hashMap = dictionary.get(words.get(i)); int countWords; if (hashMap.containsKey(documentsName)) { countWords = hashMap.get(documentsName); countWords += 1; hashMap.remove(documentsName); hashMap.put(documentsName, countWords); } else { hashMap.put(documentsName, 1); } dictionary.remove(words.get(i)); dictionary.put(words.get(i), hashMap); } else { hashMap.put(documentsName, 1); dictionary.put(words.get(i), hashMap); } } writeToFile(); }
/** * Removes an attribute from the servlet context. * * @param name the name of the attribute to remove. */ public void removeAttribute(String name) { Object oldValue; synchronized (_attributes) { oldValue = _attributes.remove(name); } // Call any listeners if (_applicationAttributeListeners != null) { ServletContextAttributeEvent event; event = new ServletContextAttributeEvent(this, name, oldValue); for (int i = 0; i < _applicationAttributeListeners.size(); i++) { ServletContextAttributeListener listener; Object objListener = _applicationAttributeListeners.get(i); listener = (ServletContextAttributeListener) objListener; try { listener.attributeRemoved(event); } catch (Throwable e) { log.log(Level.FINE, e.toString(), e); } } } }
/** * Obtient le socket enregistré correspondant à l'addresse IP donnée. * * @return le socket correspondant à l'IP source donnée s'il a été enregistré null sinon. */ public Socket popSocket(InetAddress addr) { String addrname = toId(addr); if (acceptedSockets.containsKey(addrname)) { Socket sock = acceptedSockets.get(addrname); acceptedSockets.remove(addrname); return sock; } return null; }
public Conversation removeConversation(long rmt_ip, int lcl_port, int rmt_port) { modLong.setLong(rmt_ip); modInt.setInt((lcl_port << 16) | (rmt_port & 0xFFFF)); HashMap portsMap = (HashMap) hostsMap.get(modLong); Conversation conv = null; if (portsMap != null) { conv = (Conversation) portsMap.remove(modInt); if (conv != null) { if (portsMap.size() == 0) { hostsMap.remove(modLong); } } } allConversations.remove(conv); return conv; }
public void removeRestoration(Player player) { UUID uuid = player.getUniqueId(); if (multipleInventories()) { String keyName = uuid + "." + getWorldGroups(player); if (RESTORATIONS.containsKey(keyName)) { RESTORATIONS.remove(keyName); plugin.logDebug("Removing: " + keyName); } } removeRestoration(uuid); }
void removeUnboundConnections() { if (UnboundConnections.size() == 0) { return; } ArrayList<Long> currentUnboundConnections = UnboundConnections; // fix concurrent modification exception UnboundConnections = new ArrayList<Long>(); for (long b : currentUnboundConnections) { EventableChannel ec = Connections.remove(b); if (ec != null) { if (ProxyConnections != null) { ProxyConnections.remove(b); } eventCallback(b, EM_CONNECTION_UNBOUND, null); ec.close(); EventableSocketChannel sc = (EventableSocketChannel) ec; if (sc != null && sc.isAttached()) DetachedConnections.add(sc); } } }
/** Remove an additional properties dictionary. */ public synchronized void removeProps(String key) { if (additionalProps != null) { // remove added properties for this key. If we had // properties associated with the key, mark props as updated. Object p = additionalProps.remove(key); if (p != null) { // fully reload properties and mark as updated reload(); lastadd = System.currentTimeMillis(); } } }
void removeUnboundConnections() { ListIterator<Long> iter = UnboundConnections.listIterator(0); while (iter.hasNext()) { long b = iter.next(); EventableChannel ec = Connections.remove(b); if (ec != null) { eventCallback(b, EM_CONNECTION_UNBOUND, null); ec.close(); EventableSocketChannel sc = (EventableSocketChannel) ec; if (sc != null && sc.isAttached()) DetachedConnections.add(sc); } } UnboundConnections.clear(); }
@Override public void updateLong() { if (!transmitting) { if (nextBossOrcSpawn == 0) { // spawn melvin every 10 - 30 min nextBossOrcSpawn = registry.currentTime + Rand.getRange(10 * 60 * 1000, 30 * 60 * 1000); } if (nextSnailRiderSpawn == 0) { // spawn melvin every 10 - 30 min nextSnailRiderSpawn = registry.currentTime + Rand.getRange(10 * 60 * 1000, 30 * 60 * 1000); } Monster monster = null; ArrayList deadMonsters = new ArrayList(); // make sure we have enough bad guys on the map if (gameController.multiplayerMode != gameController.multiplayerMode.CLIENT) { spawnNearPlayers(); spawnNearPlaceable(); } try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (!monster.isFeared()) { gameController.checkIfFeared(monster); } gameController.checkPlaceableDamageAgainstMob(monster); monster.updateLong(); if (monster.isDirty()) { deadMonsters.add(key); } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } } }
private boolean removeBeginNode() { List heads = getHeads(); if (heads.size() != 1) { // System.out.println("heads: "+heads); // System.out.println("Error: the size of heads is not equal to 1!"); return false; // System.exit(1); } else { JPegStmt head = (JPegStmt) heads.get(0); // System.out.println("test head: "+head); if (!head.getName().equals("begin")) { System.err.println("Error: the head is not begin node!"); System.exit(1); } // remove begin node from heads list heads.remove(0); // set the preds list of the succs of head to a new list and put succs of head into heads Iterator succOfHeadIt = getSuccsOf(head).iterator(); while (succOfHeadIt.hasNext()) { JPegStmt succOfHead = (JPegStmt) succOfHeadIt.next(); unitToPreds.put(succOfHead, new ArrayList()); // put succs of head into heads heads.add(succOfHead); } // remove begin node from inlinee Peg if (!mainPegChain.remove(head)) { System.err.println("fail to remove begin node in from mainPegChain!"); System.exit(1); } if (!allNodes.contains(head)) { System.err.println("fail to find begin node in FlowSet allNodes!"); System.exit(1); } else { allNodes.remove(head); } // remove begin node from unitToSuccs if (unitToSuccs.containsKey(head)) { unitToSuccs.remove(head); } } return true; }
/** * 从登记簿中移除路径对应的状态们<br> * Removes from equivalenceClassMDAGNodeHashmap the entries of all the nodes in a _transition * path. * * @param str a String corresponding to a _transition path from sourceNode */ private void removeTransitionPathRegisterEntries(String str) { MDAGNode currentNode = sourceNode; int charCount = str.length(); for (int i = 0; i < charCount; i++) { currentNode = currentNode.transition(str.charAt(i)); if (equivalenceClassMDAGNodeHashMap.get(currentNode) == currentNode) equivalenceClassMDAGNodeHashMap.remove(currentNode); // The hashCode of an MDAGNode is cached the first time a hash is performed without a cache // value present. // Since we just hashed currentNode, we must clear this regardless of its presence in // equivalenceClassMDAGNodeHashMap // since we're not actually declaring equivalence class representatives here. if (currentNode != null) currentNode.clearStoredHashCode(); } }
/** Complete the block write! */ public synchronized void finalizeBlock(Block b) throws IOException { ActiveFile activeFile = ongoingCreates.get(b); if (activeFile == null) { throw new IOException("Block " + b + " is already finalized."); } File f = activeFile.file; if (f == null || !f.exists()) { throw new IOException("No temporary file " + f + " for block " + b); } FSVolume v = volumeMap.get(b).getVolume(); if (v == null) { throw new IOException("No volume for temporary file " + f + " for block " + b); } File dest = null; dest = v.addBlock(b, f); volumeMap.put(b, new DatanodeBlockInfo(v, dest)); ongoingCreates.remove(b); }
public void generatePlants() { int passes = 0; int blueThornCount = 0; int vineThornCount = 0; do { blueThornCount = this.getCountByType("BlueThorn"); vineThornCount = this.getCountByType("VineThorn"); spawnPlants(); Monster monster = null; ArrayList deadMonsters = new ArrayList(); try { for (String key : monsters.keySet()) { monster = (Monster) monsters.get(key); if (monster != null) { monster.update(); if (monster.getIsDead()) { deadMonsters.add(key); } } } if (deadMonsters.size() > 0) { for (int i = 0; i < deadMonsters.size(); i++) { // EIError.debugMsg((String) deadMonsters.get(i)); monsters.remove((String) deadMonsters.get(i)); } } } catch (ConcurrentModificationException concEx) { // another thread was trying to modify monsters while iterating // we'll continue and the new item can be grabbed on the next update } passes++; } while ((blueThornCount < 200 || vineThornCount < 200) && passes < 50); int g = 1; }
void isAcceptable(SelectionKey k) { ServerSocketChannel ss = (ServerSocketChannel) k.channel(); SocketChannel sn; long b; for (int n = 0; n < 10; n++) { try { sn = ss.accept(); if (sn == null) break; } catch (IOException e) { e.printStackTrace(); k.cancel(); ServerSocketChannel server = Acceptors.remove(k.attachment()); if (server != null) try { server.close(); } catch (IOException ex) { } ; break; } try { sn.configureBlocking(false); } catch (IOException e) { e.printStackTrace(); continue; } b = createBinding(); EventableSocketChannel ec = new EventableSocketChannel(sn, b, mySelector); Connections.put(b, ec); NewConnections.add(b); eventCallback(((Long) k.attachment()).longValue(), EM_CONNECTION_ACCEPTED, null, b); } }
public void OnPointDestroy(long nID) { println("OnPointDestroy, handId: " + nID); // remove list if (_pointLists.containsKey(nID)) _pointLists.remove(nID); }
public void solve() { // Scanner sc = new Scanner(System.in); // int n = Integer.parseInt(sc.nextLine()); // n = 10000; pr("\n".getBytes()); int n = ni(); // int xx=100000; while (n != 0) { String s = ns1(); // int size = (int)(Math.random()*10000); // char [] axx = new char[size]; // for (int i = 0; i < axx.length; i++) { // char ccc = (char)((Math.random()*('z'-'a'))+'a'); //// pr(ccc); // axx[i]=ccc; // } // String s =new String(axx); // for (int i = 0; i < 1000000; i++) { // s+='x'; // } // int[] xa = new int[1000000000]; // pr(s); int a = 0; HashMap<Character, Integer> set = new HashMap<Character, Integer>(); // int [] alf= new int[128]; int r = 0; for (int i = 0; i < s.length(); i++) { // pr(set); // char that = s.charAt(a); char thix = s.charAt(i); if (set.size() < n) { Integer ax = set.get(thix); if (ax == null) { set.put(thix, 1); } else set.put(thix, ax + 1); } else if (set.size() == n) { if (!set.containsKey(thix)) { while (set.size() == n && a < s.length()) { char that = s.charAt(a); if (set.containsKey(that) && set.get(that) > 1) set.put(that, set.get(that) - 1); else set.remove(that); a++; } set.put(thix, 1); } else set.put(thix, set.get(thix) + 1); } int newr = i - a + 1; // pr(newr, set,a,i,s.substring(a,i)); if (newr > r) { // pr() // pr(set,a,i,s.substring(a,i)); r = newr; } // r=max(r,); } out.println(r); // n = (int)(Math.random()*128); n = ni(); } }
static void removeFromCache(ZLFile file) { ourZipFileMap.remove(file); }
public static MiningResult importFile(InputStream input) throws IOException { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Document doc; // NodeList netNodes; dbf.setValidating(false); dbf.setIgnoringComments(true); dbf.setIgnoringElementContentWhitespace(true); // dbf.setExpandEntityReferences(false); // dbf.setNamespaceAware(false); DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver( new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { if (systemId.indexOf("ARIS-Export") != -1) { return new InputSource("file:" + About.EXTLIBLOCATION() + "ARIS-Export101.dtd"); } else { return null; } } }); InputSource inpStream = new InputSource(input); inpStream.setSystemId("file:" + System.getProperty("user.dir", "")); doc = db.parse(inpStream); // check if root element is a aml tag Message.add("parsing done" + doc, Message.DEBUG); if (!(doc.getDocumentElement().getNodeName().equals("AML"))) { Message.add("aml tag not found", Message.ERROR); throw new Exception("aml tag not found"); } else { Message.add("aml root element found"); } EPCResult result = new EPCResult(null, (EPC) null); HashMap ObjDef_LinkId = new HashMap(); HashMap modelid_net = new HashMap(); HashMap ObjDef_Name = new HashMap(); HashMap function_LinkId = new HashMap(); HashMap ModelId_ModelType = new HashMap(); traverseAMLforObjectNames( ObjDef_Name, doc.getDocumentElement(), ObjDef_LinkId, ModelId_ModelType); Iterator findLinkToEpc = ObjDef_LinkId.keySet().iterator(); while (findLinkToEpc.hasNext()) { String currentObjDef = (String) findLinkToEpc.next(); String Links = (String) ObjDef_LinkId.get(currentObjDef); StringTokenizer linkSet = new StringTokenizer(Links); String realEpcLink = ""; while (linkSet.hasMoreTokens()) { String currentLink = linkSet.nextToken(); if (ModelId_ModelType.get(currentLink).equals("MT_EEPC")) { realEpcLink = currentLink; break; } } if (realEpcLink.equals(" ")) { ObjDef_LinkId.remove(currentObjDef); } else { ObjDef_LinkId.put(currentObjDef, realEpcLink); } } result = traverseAML( result, doc.getDocumentElement(), null, ObjDef_Name, ObjDef_LinkId, modelid_net, function_LinkId); Iterator hierarchicalFunctions = function_LinkId.keySet().iterator(); while (hierarchicalFunctions.hasNext()) { EPCSubstFunction f = (EPCSubstFunction) hierarchicalFunctions.next(); f.setSubstitutedEPC((EPC) modelid_net.get(function_LinkId.get(f))); // Message.add(f.getSubstitutedEPC().getName()); } return result; } catch (Throwable x) { Message.add(x.toString()); throw new IOException(x.getMessage()); } }