List of usage examples for java.util Iterator remove
default void remove()
From source file:net.duckling.ddl.web.api.pan.APIPanListController.java
private void filterFolder(List<PanResourceBean> beans) { Iterator<PanResourceBean> it = beans.iterator(); while (it.hasNext()) { PanResourceBean bean = it.next(); if (!LynxConstants.TYPE_FOLDER.equals(bean.getItemType())) { it.remove(); }/*from w w w.ja v a2 s . c o m*/ } }
From source file:com.googlecode.flyway.core.validation.DbValidator.java
/** * Validate the checksum of all existing sql migration in the metadata table with the checksum of the sql migrations * in the classpath/* w ww. j av a 2s . c o m*/ * * @param resolvedMigrations All migrations available on the classpath, sorted by version, newest first. * @return description of validation error or NULL if no validation error was found */ public String validate(List<Migration> resolvedMigrations) { if (ValidationMode.NONE.equals(validationMode)) { return null; } LOG.debug(String.format("Validating (mode %s) migrations ...", validationMode)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); final List<MetaDataTableRow> appliedMigrations = new ArrayList<MetaDataTableRow>( metaDataTable.allAppliedMigrations()); if (appliedMigrations.isEmpty()) { LOG.info("No migrations applied yet. No validation necessary."); return null; } List<Migration> migrations = new ArrayList<Migration>(resolvedMigrations); // migrations now with newest last Collections.reverse(migrations); final MetaDataTableRow firstAppliedMigration = appliedMigrations.get(0); if (MigrationType.INIT.equals(firstAppliedMigration.getMigrationType())) { // if first migration is INIT, just check checksum of following migrations final SchemaVersion initVersion = firstAppliedMigration.getVersion(); appliedMigrations.remove(firstAppliedMigration); Iterator<Migration> iterator = migrations.iterator(); while (iterator.hasNext()) { Migration migration = iterator.next(); if (migration.getVersion().compareTo(initVersion) <= 0) { iterator.remove(); } } } if (appliedMigrations.size() > migrations.size()) { List<SchemaVersion> schemaVersions = new ArrayList<SchemaVersion>(); for (MetaDataTableRow metaDataTableRow : appliedMigrations) { schemaVersions.add(metaDataTableRow.getVersion()); } for (Migration migration : migrations) { schemaVersions.remove(migration.getVersion()); } String diff = StringUtils.collectionToCommaDelimitedString(schemaVersions); return String.format( "More applied migrations than classpath migrations: DB=%s, Classpath=%s, Missing migrations=(%s)", appliedMigrations.size(), migrations.size(), diff); } for (int i = 0; i < appliedMigrations.size(); i++) { MetaDataTableRow appliedMigration = appliedMigrations.get(i); //Migrations are sorted in the opposite order: newest first. Migration classpathMigration = migrations.get(i); if (!appliedMigration.getVersion().equals(classpathMigration.getVersion())) { return String.format("Version mismatch for migration %s: DB=%s, Classpath=%s", appliedMigration.getScript(), appliedMigration.getVersion(), classpathMigration.getVersion()); } if (!appliedMigration.getMigrationType().equals(classpathMigration.getMigrationType())) { return String.format("Migration Type mismatch for migration %s: DB=%s, Classpath=%s", appliedMigration.getScript(), appliedMigration.getMigrationType(), classpathMigration.getMigrationType()); } final Integer appliedChecksum = appliedMigration.getChecksum(); final Integer classpathChecksum = classpathMigration.getChecksum(); if (!ObjectUtils.nullSafeEquals(appliedChecksum, classpathChecksum)) { return String.format("Checksum mismatch for migration %s: DB=%s, Classpath=%s", appliedMigration.getScript(), appliedChecksum, classpathMigration.getChecksum()); } } stopWatch.stop(); if (appliedMigrations.size() == 1) { LOG.info(String.format("Validated 1 migration (mode: %s) (execution time %s)", validationMode, TimeFormat.format(stopWatch.getTotalTimeMillis()))); } else { LOG.info(String.format("Validated %d migrations (mode: %s) (execution time %s)", appliedMigrations.size(), validationMode, TimeFormat.format(stopWatch.getTotalTimeMillis()))); } return null; }
From source file:net.sourceforge.atunes.kernel.modules.player.PlayerEngineSelector.java
/** * @return/*from w w w. j ava2 s .c o m*/ */ private List<AbstractPlayerEngine> getAvailableEngines() { // Remove unsupported engines // To do that create a clone of list to be able to remove from List<AbstractPlayerEngine> availableEngines = new ArrayList<AbstractPlayerEngine>(engines); Iterator<AbstractPlayerEngine> it = availableEngines.iterator(); while (it.hasNext()) { AbstractPlayerEngine engine = it.next(); // Engines must be supported for given OS and available if (!osManager.isPlayerEngineSupported(engine) || !engine.isEngineAvailable()) { it.remove(); } } return availableEngines; }
From source file:com.kurento.kmf.connector.ThriftConnectorJsonRpcHandler.java
@Override public void afterConnectionClosed(Session session, String status) throws Exception { Iterator<Entry<String, Session>> it = subscriptions.entrySet().iterator(); while (it.hasNext()) { Entry<String, Session> value = it.next(); if (value.getValue() == session) { it.remove(); }/*from ww w.j a va 2s.co m*/ } }
From source file:com.ace.erp.service.sys.impl.ResourceServiceImpl.java
/** * ??????/*from w ww. ja v a 2 s .c o m*/ * ?,?? * * @param user * @return */ public List<Menu> findMenus(User user) { String sort = "parent_id desc,weight desc"; Map<String, Object> params = new HashMap<String, Object>(); params.put("sort", sort); List<Resource> resources = resourceMapper.getAllWithSort(params); Set<String> userPermissions = userAuthService.findStringPermissions(user); Iterator<Resource> iter = resources.iterator(); while (iter.hasNext()) { if (!hasPermission(iter.next(), userPermissions)) { iter.remove(); } } return convertToMenus(resources); }
From source file:org.darwinathome.server.controller.HubController.java
@RequestMapping(Hub.GET_WORLD_SERVICE) public void getWorld(@PathVariable("session") String session, OutputStream outputStream) throws IOException { log.info(Hub.GET_WORLD_SERVICE + " " + session); DataOutputStream dos = new DataOutputStream(outputStream); PlayerSession playerSession = sessionMap.get(session); if (playerSession != null) { dos.writeUTF(Hub.SUCCESS);/* ww w.j ava 2 s .co m*/ dos.write(worldHistory.getFrozenWorld().getWorld()); Iterator<PlayerSession> sessionWalk = sessionMap.values().iterator(); while (sessionWalk.hasNext()) { if (sessionWalk.next().isExpired()) { sessionWalk.remove(); } } } else { dos.writeUTF(Hub.FAILURE); dos.writeUTF(Failure.SESSION.toString()); } }
From source file:cc.arduino.packages.discoverers.NetworkDiscovery.java
private void removeDuplicateBoards(BoardPort newBoard) { synchronized (boardPortsDiscoveredWithJmDNS) { Iterator<BoardPort> iterator = boardPortsDiscoveredWithJmDNS.iterator(); while (iterator.hasNext()) { BoardPort board = iterator.next(); if (newBoard.getAddress().equals(board.getAddress())) { iterator.remove(); }/*from w w w . ja v a2 s . c o m*/ } } }
From source file:com.esofthead.mycollab.module.project.view.assignments.gantt.GanttItemContainer.java
private void removeAssociatesPredecessorsAndDependents(GanttItemWrapper removedTask) { List items = getAllItemIds(); for (Object itemId : items) { GanttItemWrapper item = (GanttItemWrapper) itemId; List<TaskPredecessor> removedPredecessors = new ArrayList<>(); List<TaskPredecessor> predecessors = item.getPredecessors(); if (CollectionUtils.isNotEmpty(predecessors)) { Iterator<TaskPredecessor> iterator = predecessors.iterator(); while (iterator.hasNext()) { TaskPredecessor predecessor = iterator.next(); if (predecessor.getDescid().intValue() == removedTask.getId().intValue()) { iterator.remove(); removedPredecessors.add(predecessor); }/*from w w w. ja va 2 s . c o m*/ } } if (CollectionUtils.isNotEmpty(removedPredecessors)) { GanttAssignmentService ganttAssignmentService = ApplicationContextUtil .getSpringBean(GanttAssignmentService.class); ganttAssignmentService.massDeletePredecessors(removedPredecessors, AppContext.getAccountId()); } List<TaskPredecessor> dependents = item.getDependents(); if (CollectionUtils.isNotEmpty(dependents)) { Iterator<TaskPredecessor> iterator = predecessors.iterator(); while (iterator.hasNext()) { TaskPredecessor dependent = iterator.next(); if (dependent.getSourceid().intValue() == removedTask.getId().intValue()) { iterator.remove(); } } } } }
From source file:com.dianping.lion.web.tag.MainNavigator.java
private int hasPrivilege(MenuGroup menuGroup) { if (menuGroup.menuOrGroups.isEmpty()) { return -1; }//ww w . j av a 2s . c om int menuSize = menuGroup.menuOrGroups.size(); Iterator<Object> iterator = menuGroup.menuOrGroups.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next instanceof MenuGroup) { int hasPrivilege = hasPrivilege((MenuGroup) next); if (hasPrivilege < 0) { iterator.remove(); menuSize--; } } else if (next instanceof Menu) { int hasPrivilege = hasPrivilege((Menu) next); if (hasPrivilege < 0) { iterator.remove(); menuSize--; } else if (hasPrivilege == 0) { menuSize--; } } } return menuSize > 0 ? 1 : -1; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.xml.FormData.java
/** * Sets a new value for an existing key inside a {@code FormData} object, * or adds the key if it does not already exist. * @param name the name of the field whose data is contained in {@code value} * @param value the field's value/*from w w w. j a v a 2 s . co m*/ * @param filename the filename reported to the server (optional) */ @JsxFunction({ @WebBrowser(value = FF, minVersion = 45), @WebBrowser(CHROME) }) public void set(final String name, final Object value, final Object filename) { if (StringUtils.isEmpty(name)) { return; } int pos = -1; final Iterator<NameValuePair> iter = requestParameters_.iterator(); int idx = 0; while (iter.hasNext()) { final NameValuePair pair = iter.next(); if (name.equals(pair.getName())) { iter.remove(); if (pos < 0) { pos = idx; } } idx++; } if (pos < 0) { pos = requestParameters_.size(); } if (value instanceof File) { final File file = (File) value; String fileName = null; if (filename instanceof String) { fileName = (String) filename; } requestParameters_.add(pos, new KeyDataPair(name, file.getFile(), fileName, file.getType(), null)); } else { requestParameters_.add(pos, new NameValuePair(name, Context.toString(value))); } }