public void handle(PeerMessage event) { PeerAddress oldFriend; PeerAddress sender = event.getMSPeerSource(); PeerAddress newFriend = event.getNewFriend(); // add the sender address to the list of friends if (!friends.contains(sender)) { if (friends.size() == viewSize) { oldFriend = friends.get(rand.nextInt(viewSize)); friends.remove(oldFriend); fdUnregister(oldFriend); Snapshot.removeFriend(serverPeerAddress, oldFriend); } friends.addElement(sender); fdRegister(sender); Snapshot.addFriend(serverPeerAddress, sender); } // add the received new friend from the sender to the list of friends if (!friends.contains(newFriend) && !serverPeerAddress.equals(newFriend)) { if (friends.size() == viewSize) { oldFriend = friends.get(rand.nextInt(viewSize)); friends.remove(oldFriend); fdUnregister(oldFriend); Snapshot.removeFriend(serverPeerAddress, oldFriend); } friends.addElement(newFriend); fdRegister(newFriend); Snapshot.addFriend(serverPeerAddress, newFriend); } }
public static void main(String[] args) { // Creating a Vector of String Elements Vector<String> vector = new Vector<String>(); // Adding elements to the Vector vector.add("Harry"); vector.add("Steve"); vector.add("Vince"); vector.add("David"); vector.add("Matt"); System.out.println("Vector elements before remove(): "); for (int i = 0; i < vector.size(); i++) { System.out.println(vector.get(i)); } // Removing Harry vector.remove("Harry"); // Removing Matt vector.remove("Matt"); System.out.println("\nVector elements after remove(): "); for (int i = 0; i < vector.size(); i++) { System.out.println(vector.get(i)); } }
public void putOutMessages() { synchronized (collectedMessages) { int sendable; int pool = collectedMessages.size(); if (pool >= (MIN_POOL + MIN_SEND)) { sendable = pool - MIN_SEND; sendable = Math.min(sendable, Math.max(1, (int) Math.round((double) pool * SEND_RATE))); } else { sendable = 0; } if (sendable > 0) { if (isRequestPool) { for (int i = 0; i < sendable; i++) { int chosen = secureRandom.nextInt(collectedMessages.size()); anonNode.putOutRequest((Request) collectedMessages.remove(chosen)); } } else { for (int i = 0; i < sendable; i++) { int chosen = secureRandom.nextInt(collectedMessages.size()); anonNode.putOutReply((Reply) collectedMessages.remove(chosen)); } } } } }
/** * calculates the TP, FP, FN and the first Part for the Performance * * @param idsWithHull * @param GOsWithHull */ private void calcPosNegs(Vector<String> idsWithHull, Vector<String> GOsWithHull) { int TP = 0; int FP = 0; int FN = 0; Vector<String> toRemove = new Vector<String>(); for (String a : idsWithHull) { if (GOsWithHull.contains(a)) { TP++; toRemove.add(a); } } for (String tr : toRemove) { idsWithHull.remove(tr); GOsWithHull.remove(tr); } FP = GOsWithHull.size(); FN = idsWithHull.size(); calcPerformanceI(TP, FP, FN); }
/** Sort all the painters (according to priority and name) */ protected void sortThem() { sortByPriority.clear(); sortByName.clear(); sortByName.addAll(paintersByName.keySet()); Collections.sort(sortByName); Vector<String> painterNames = new Vector<String>(); Vector<Integer> priorities = new Vector<Integer>(); painterNames.addAll(sortByName); priorities.addAll(painterPriorities.values()); Collections.sort(priorities); while (!priorities.isEmpty()) { int prio = priorities.get(0); priorities.remove(0); for (int i = 0; i < painterNames.size(); i++) { if (painterPriorities.get(painterNames.get(i)) == prio) { sortByPriority.add(painterNames.get(i)); painterNames.remove(i); break; } } } }
public void getMinimum_GValue() { Coordinate tmpCoordinate = null; int backtmpG = tmpList.elementAt(0).getGValue(); for (Coordinate b : tmpList) { if (b.getGValue() <= backtmpG) { backtmpG = b.getGValue(); backTmpList.add(b); tmpCoordinate = b; } } if (backTmpList.size() > 1) { int tmpHValue = backTmpList.elementAt(0).getHValue(); for (Coordinate b : backTmpList) { if (b.getHValue() > tmpHValue) { tmpCoordinate = b; tmpHValue = b.getHValue(); } } } closeList.remove(current); way.add(0, tmpCoordinate); current = tmpCoordinate; for (Coordinate b : tmpList) if (closeList.contains(b)) closeList.remove(b); tmpList.removeAllElements(); backTmpList.removeAllElements(); }
public void dbRemoveElement(int id) { lm.remove(id); dbItems.remove(id); dbItemsK.remove(id); dbItemsK2.remove(id); this.setModel(lm); }
public void computerCowMove2(GridSimulationWorldState state) { w_state = state; Vector<Double> weight_vec = new Vector<Double>(); Vector<int[]> pos_vec = new Vector<int[]>(); double max_weight = -Double.MAX_VALUE; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { int x = posx + i; int y = posy + j; // we take care only about the empty cell around cow and cow's cell self if (x >= 0 && y >= 0 && x < state.sizex && y < state.sizey && (state.board[x][y].freeCell() || (x == posx && y == posy))) { int pos[] = {x, y}; double weight = calcWeight(state.board[x][y], pos); weight_vec.add(weight); pos_vec.add(pos); if (max_weight < weight) max_weight = weight; } } } // boolean remove = true; // while(remove){ // remove = false; // for(int i = 0; i<weight_vec.size();i++){ // if(weight_vec.get(i) < max_weight){ // pos_vec.remove(i); // weight_vec.remove(i); // remove = true; // } // } // } // int i = 0; while (i < weight_vec.size()) { if (weight_vec.get(i) < max_weight) { pos_vec.remove(i); weight_vec.remove(i); } else { i++; } } Collections.shuffle(pos_vec); int move_pos[] = pos_vec.get(0); direction = getDir(move_pos); }
public void removeBlock(long blockId) { transactionIds.remove(blockId); headerIds.remove(blockId); BitCoopFile fileToDelete = getFileForId(blockId); if (fileToDelete != null) { fileToDelete.delete(); } }
/** * This methods removes a socket from the list of sockets that should be checked for messages * * @param socket The socket that should be removed */ public void removeSocket(IDatagramSocket socket) { synchronized (listLock) { int index = socketList.indexOf(socket); if (index != -1) { socketList.remove(index); messageHandlerList.remove(index); } } }
/** Remove a message from the table */ public void removeRow(int row) { SOAPMonitorData soap = null; if (filter_data == null) { soap = (SOAPMonitorData) data.elementAt(row); data.remove(soap); } else { soap = (SOAPMonitorData) filter_data.elementAt(row); filter_data.remove(soap); data.remove(soap); } fireTableRowsDeleted(row, row); }
/** * Before each frame generator tables must be updated. Remove transmitters that are finished, and * add pending. */ private final void updateGenerators() { while (removedTransmitters.size() > 0) audioOutputGenerators.remove(removedTransmitters.remove(0)); while (addedTransmitters.size() > 0) { Voice transmitter = addedTransmitters.remove(0); if (transmitter.nextVoice != null) { int nIndex = audioOutputGenerators.indexOf(transmitter.nextVoice); if (nIndex > -1) audioOutputGenerators.add(nIndex, transmitter); else audioOutputGenerators.add(transmitter); } else audioOutputGenerators.add(transmitter); } }
@Override public Path getPath() { Path p = new Path(generateSpeed()); MapNode curNode = lastMapNode; MapNode prevNode = lastMapNode; MapNode nextNode = null; List<MapNode> neighbors; Coord nextCoord; assert lastMapNode != null : "Tried to get a path before placement"; // start paths from current node p.addWaypoint(curNode.getLocation()); int pathLength = rng.nextInt(maxPathLength - minPathLength) + minPathLength; for (int i = 0; i < pathLength; i++) { neighbors = curNode.getNeighbors(); Vector<MapNode> n2 = new Vector<MapNode>(neighbors); if (!this.backAllowed) { n2.remove(prevNode); // to prevent going back } if (okMapNodeTypes != null) { // remove neighbor nodes that aren't ok for (int j = 0; j < n2.size(); ) { if (!n2.get(j).isType(okMapNodeTypes)) { n2.remove(j); } else { j++; } } } if (n2.size() == 0) { // only option is to go back nextNode = prevNode; } else { // choose a random node from remaining neighbors nextNode = n2.get(rng.nextInt(n2.size())); } prevNode = curNode; nextCoord = nextNode.getLocation(); curNode = nextNode; p.addWaypoint(nextCoord); } lastMapNode = curNode; return p; }
public void testBallCatch() { for (int i = 0; i < balls.size(); i++) { if (bucket.contains(balls.get(i))) { if (balls.get(i).isGood()) points++; else lives--; balls.remove(i); i--; } else if (balls.get(i).getLocation().getY() >= HEIGHT + Ball.RADIUS) { if (balls.get(i).isGood()) lives--; balls.remove(i); i--; } } }
/* * (non-Javadoc) * * @see pt.up.fe.dceg.neptus.consolebase.SubPanelChangeListener#subPanelChanged(pt.up.fe.dceg.neptus.consolebase. * SubPanelChangeEvent) */ @Override public void subPanelChanged(SubPanelChangeEvent panelChange) { if (panelChange == null) return; renderersPopups = getConsole().getSubPanelsOfInterface(IMapPopup.class); if (ReflectionUtil.hasInterface(panelChange.getPanel().getClass(), IMapPopup.class)) { IMapPopup sub = (IMapPopup) panelChange.getPanel(); if (panelChange.added()) { renderersPopups.add(sub); IMapPopup str2d = sub; if (str2d != null) { str2d.addMenuExtension(this); } } if (panelChange.removed()) { renderersPopups.remove(sub); IMapPopup str2d = sub; if (str2d != null) { str2d.removeMenuExtension(this); } } } if (ReflectionUtil.hasInterface(panelChange.getPanel().getClass(), ILayerPainter.class)) { ILayerPainter sub = (ILayerPainter) panelChange.getPanel(); if (panelChange.added()) { renderers.add(sub); ILayerPainter str2d = sub; if (str2d != null) { str2d.addPostRenderPainter(this, "My location"); } } if (panelChange.removed()) { renderers.remove(sub); ILayerPainter str2d = sub; if (str2d != null) { str2d.removePostRenderPainter(this); } } } }
public void removeLastColumn() { if (hasHeader && header.size() > 0) { header.remove(header.size() - 1); } int columnCount = getColumnCount(); if (columnCount > 0) { int size = dataVector.size(); for (int i = 0; i < size; i++) { Vector row = (Vector) dataVector.elementAt(i); row.remove(columnCount - 1); } } fireTableStructureChanged(); }
public void moveSelection(int direction) { int selectedIndex = definitionList.getSelectedIndex(); String fileName = fileNames.get(selectedIndex); if (direction == MOVE_UP && selectedIndex > 0) { fileNames.remove(selectedIndex); fileNames.add(--selectedIndex, fileName); } else if (direction == MOVE_DOWN && selectedIndex < definitionList.getModel().getSize()) { fileNames.remove(selectedIndex); fileNames.add(++selectedIndex, fileName); } updateListModel(); definitionList.setSelectedIndex(selectedIndex); }
// This method is called when a client has disconnected from the server and its thread is about to // end // It just presents a status message and removes the given client and thread from our lists public synchronized void clientThreadEnding(ClientConnection clientConnection) { parent.updateStatusBox( clientSocketList.indexOf(clientConnection) + " " + "Client " + clientConnection.id + " disconnected, removing from connection pool"); clientThreadList.remove(clientSocketList.indexOf(clientConnection)); clientSocketList.remove(clientSocketList.indexOf(clientConnection)); numClients--; parent.updateStatusBox("There are " + numClients + " clients connected"); }
@Override protected void onResize(float width, float height) { int w = (int) width, h = (int) height; m_curEntry = searchEntry((int) width, (int) height); if (m_curEntry != null) { if (m_curEntry.isValid()) { return; } m_cache.remove(m_curEntry); } super.onResize((int) width, (int) height); if (m_cache.size() == 0) { caches.add(m_cache); } m_curEntry = new BmpCacheEntry(); m_curEntry.w = w; m_curEntry.h = h; m_curEntry.bmpNormal = Bitmap.createBitmap(w, h, Config.ARGB_8888); boolean press = m_bPressed; boolean ch = m_bCheckable; m_bCheckable = false; m_bPressed = false; super.draw(new Canvas(m_curEntry.bmpNormal), null); m_bPressed = true; m_curEntry.bmpPress = Bitmap.createBitmap(w, h, Config.ARGB_8888); super.draw(new Canvas(m_curEntry.bmpPress), null); if (m_cache.size() == m_cacheSize) { m_cache.remove(0); } m_cache.add(m_curEntry); m_bPressed = press; m_bCheckable = ch; // try { // File f = new // File(Environment.getExternalStorageDirectory()+"/test"+System.currentTimeMillis()+".jpg"); // f.createNewFile(); // boolean ok = m_curEntry.bmpNormal.compress(CompressFormat.JPEG, 100, new // FileOutputStream(f)); // if(!ok||!f.exists()) // { // long aa = 1; // long bb = aa; // } // } catch (Throwable e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } }
@Override public void run() { while (running) { if (queue.size() == 0) { try { Thread.sleep(20); } catch (InterruptedException ex) { // üres } continue; } Token aToken = queue.remove(0); try { objectOutput.writeObject(aToken.outputMsg); objectOutput.flush(); } catch (IOException e) { onException(e); } /* * Értesíteni a szálat ami küldte ezt a "Token"-t, hogy befejeztük a vele kapcsolatos műveletetek */ synchronized (aToken) { aToken.notify(); } } // "while" ciklus végét jelző zárójel }
/** * attempts to send data to the client<br> * if all the data has been successfully sent, the ConnectionHandler will automatically switch to * read only mode, otherwise it'll stay in it's current mode (which is read / write). * * @throws IOException if the write operation fails * @throws ClosedChannelException if the channel have been closed while registering to the * Selector */ public synchronized void write() { if (_outData.size() == 0) { // if nothing left in the output string, go back to read mode switchToReadOnlyMode(); return; } // if there is something to send ByteBuffer buf = _outData.remove(0); if (buf.remaining() != 0) { try { _sChannel.write(buf); } catch (IOException e) { // this should never happen. e.printStackTrace(); } // check if the buffer contains more data if (buf.remaining() != 0) { _outData.add(0, buf); } } // check if the OLD.protocol indicated close. if (_protocol.shouldClose()) { switchToWriteOnlyMode(); if (buf.remaining() == 0) { closeConnection(); SocketAddress address = _sChannel.socket().getRemoteSocketAddress(); logger.info("disconnecting client on " + address); } } }
public void removeConnectionListener(NCCPConnection.ConnectionListener l) { if (listeners.contains(l)) { // ExpCoordinator.printer.print(new String("NCCPConnection.removeConnectionListener to " + // toString()), 2); listeners.remove(l); } }
/** * Removes the specified <code>JSChannelsPane</code> from the view. * * @param chnPane The <code>JSChannelsPane</code> to be removed. * @return <code>true</code> if the specified code>JSChannelsPane</code> is actually removed from * the view, <code>false</code> otherwise. */ public boolean removeChannelsPane(JSChannelsPane chnPane) { chnPane.removeListSelectionListener(this); tabbedPane.remove(chnPane); boolean b = super.removeChannelsPane(chnPane); for (int i = 0; i < miList.size(); i++) { A4n.MoveChannelsTo a = (A4n.MoveChannelsTo) miList.get(i).getAction(); if (a.getChannelsPane().equals(chnPane)) { miList.remove(i); break; } } updateTabsMenu(); if (getChannelsPaneCount() == 1) { A4n.closeChannelsTab.setEnabled(false); A4n.editTabTitle.setEnabled(false); tabbedPane.remove(getChannelsPane(0)); channelsPane.remove(tabbedPane); channelsPane.add(getChannelsPane(0)); } return b; }
private void runScript(File script) { FileReader fr; try { fr = new FileReader(script); } catch (FileNotFoundException e) { HF.showErrorMessage(i18n.getMessage("FileNotFound!")); return; } BufferedReader br = new BufferedReader(fr); try { String s = br.readLine(); while (s != null) { getLSConsoleModel().setCommandLineText(s); getLSConsoleModel().execCommand(); s = br.readLine(); } } catch (Exception e) { HF.showErrorMessage(e); return; } if (!cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0); String s = script.getAbsolutePath(); recentScripts.remove(s); recentScripts.insertElementAt(s, 0); while (recentScripts.size() > ClassicPrefs.getRecentScriptsSize()) { recentScripts.removeElementAt(recentScripts.size() - 1); } updateRecentScriptsMenu(); }
public static Task GetOne() { if (allTask.size() != 0) { Task res = allTask.get(0); allTask.remove(0); return res; } else return null; }
@Override public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException { if (!(CMLib.intermud().imc2online())) { mob.tell(L("IMC2 is unavailable.")); return false; } commands.remove(0); if (commands.size() < 1) { IMC2Error(mob); return false; } final String str = (String) commands.get(0); if (!(CMLib.intermud().imc2online())) mob.tell(L("IMC2 is unavailable.")); else if (str.equalsIgnoreCase("list")) CMLib.intermud().giveIMC2MudList(mob); else if (str.equalsIgnoreCase("locate")) CMLib.intermud().i3locate(mob, CMParms.combine(commands, 1)); else if (str.equalsIgnoreCase("channels") && CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.IMC2)) CMLib.intermud().giveIMC2ChannelsList(mob); else if (str.equalsIgnoreCase("info")) CMLib.intermud().imc2mudInfo(mob, CMParms.combine(commands, 1)); else if (str.equalsIgnoreCase("restart") && CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.IMC2)) { try { mob.tell(CMLib.hosts().get(0).executeCommand("START IMC2")); } catch (final Exception e) { Log.errOut("IMC2Cmd", e); } } else IMC2Error(mob); return false; }
/* * (non-Javadoc) * * @see pt.lsts.neptus.util.comm.manager.CommonCommBaseImplementation#triggerExtraActionOnSetActive(boolean, * pt.lsts.neptus.messages.listener.MessageInfo, pt.lsts.neptus.messages.IMessage) */ @Override protected void triggerExtraActionOnSetActive( boolean isActive, MessageInfo info, IMCMessage message) { ImcSystem sys = ImcSystemsHolder.lookupSystem(getSystemCommId()); if (sys != null) { if (message == null || !StringUtils.isTokenInList("Announce,EntityList", message.getAbbrev())) { if (!useActivityCounter) { sys.setActive(isActive); // NeptusLog.pub().info("<###> "+sys.getName()+": "+isActive()+" "+(message != // null?message.getAbbrevName():"")); } else { // If IMCAuthorityState.OFF then we consider not active if (sys.getAuthorityState() == ImcSystem.IMCAuthorityState.OFF) { sys.setActive(false); } else if (!isActive) { sys.setActive(false); } else { activityCounter.add(System.currentTimeMillis()); int vecSize = activityCounter.size(); if (vecSize > 3) { activityCounter.remove(0); } vecSize = activityCounter.size(); if (vecSize == 3) { if (activityCounter.get(2) - activityCounter.get(0) <= 3000) sys.setActive(true); else sys.setActive(false); } else { sys.setActive(false); } } } } } }
public boolean supprimerProduitOut(EugesProduit a) { if (contientProduitOut(a)) { _produitsOut.remove(a); return true; } return false; }
public boolean supprimerActRealise(EugesActRealise a) { if (contientActRealise(a)) { _activites.remove(a); return true; } return false; }
/** * Removes the given value for the given key * * @param key: the key to search in the Table * @param value: the value to remove from the Table */ public void remove(A key, B value) { Vector<B> values = multimap.get(key); if (values != null) { values.remove(value); size--; } }