List of usage examples for java.util Iterator remove
default void remove()
From source file:com.liferay.portal.lar.LayoutExporter.java
public static List<Portlet> getAlwaysExportablePortlets(long companyId) throws Exception { List<Portlet> portlets = PortletLocalServiceUtil.getPortlets(companyId); Iterator<Portlet> itr = portlets.iterator(); while (itr.hasNext()) { Portlet portlet = itr.next();//from w w w . ja v a2 s . co m if (!portlet.isActive()) { itr.remove(); continue; } PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); if ((portletDataHandler == null) || (!portletDataHandler.isAlwaysExportable())) { itr.remove(); } } return portlets; }
From source file:ch.njol.skript.command.Commands.java
public static int unregisterCommands(final File script) { int numCommands = 0; final Iterator<ScriptCommand> commandsIter = commands.values().iterator(); while (commandsIter.hasNext()) { final ScriptCommand c = commandsIter.next(); if (script.equals(c.getScript())) { numCommands++;// www . java 2s . c o m c.unregisterHelp(); if (commandMap != null) { assert cmKnownCommands != null;// && cmAliases != null; c.unregister(commandMap, cmKnownCommands, cmAliases); } commandsIter.remove(); } } return numCommands; }
From source file:org.toobsframework.data.beanutil.BeanMonkey.java
public static Collection populateCollection(String beanClazz, String indexPropertyName, Map properties, boolean noload, boolean errorMode, Collection errorMessages) throws IllegalAccessException, InvocationTargetException, ValidationException, ClassNotFoundException, InstantiationException, PermissionException { String className = beanClazz.substring(beanClazz.lastIndexOf(".") + 1); IValidator v = null;/* w w w . ja v a2 s . com*/ String validatorName = className + "Validator"; if (beanFactory.containsBean(validatorName)) { v = (IValidator) beanFactory.getBean(validatorName); } else { log.warn("No validator for " + className); } Collection validationErrors = new ArrayList(); Collection returnObjs = populateCollection(v, beanClazz, indexPropertyName, properties, true, noload); if (v == null) { return returnObjs; } String objectName = (String) properties.get("returnObjectType") == null ? className : (String) properties.get("returnObjectType"); /* Validate Collection level properties - size() > 0 etc */ Errors e = new BindException(returnObjs, objectName); v.validateCollection(returnObjs, e); if (e.getAllErrors() != null && e.getAllErrors().size() > 0) { validationErrors.add(e); //return returnObjs; } else { Iterator it = returnObjs.iterator(); while (it.hasNext()) { Object bean = it.next(); v.prepare(bean, properties); boolean doCreate = v.doCreateCollectionMember(bean); if (!doCreate) { it.remove(); continue; } e = new BindException(bean, objectName); v.validate(bean, e); /* Safe bean in DoItRunner validationErrorObjects.add(v.getSafeBean(bean, properties)); */ if (e.getAllErrors() != null && e.getAllErrors().size() > 0) { validationErrors.add(e); } else if (errorMode) { it.remove(); } } } if (validationErrors.size() > 0) { if (errorMessages != null) { Iterator errIter = validationErrors.iterator(); while (errIter.hasNext()) { Errors err = (Errors) errIter.next(); errorMessages.addAll(err.getAllErrors()); } } else { throw new ValidationException(validationErrors); } } /* if(validationErrors.size() > 0){ //properties.put("ValidationErrors", validationErrors); //properties.put("ValidationErrorObject", validationErrorObjects); throw new ValidationException(validationErrors); } */ //If there are no errors, null out the errorsObjects to conserve memory. //validationErrorObjects = null; return returnObjs; }
From source file:com.linkedin.helix.tools.ClusterStateVerifier.java
static boolean verifyBestPossAndExtView(HelixDataAccessor accessor, Map<String, Map<String, String>> errStates) { try {//from w ww .j a v a2 s.c o m Builder keyBuilder = accessor.keyBuilder(); // read cluster once and do verification ClusterDataCache cache = new ClusterDataCache(); cache.refresh(accessor); Map<String, IdealState> idealStates = cache.getIdealStates(); if (idealStates == null) // || idealStates.isEmpty()) { // ideal state is null because ideal state is dropped idealStates = Collections.emptyMap(); } Map<String, ExternalView> extViews = accessor.getChildValuesMap(keyBuilder.externalViews()); if (extViews == null) // || extViews.isEmpty()) { extViews = Collections.emptyMap(); } // if externalView is not empty and idealState doesn't exist // add empty idealState for the resource for (String resource : extViews.keySet()) { if (!idealStates.containsKey(resource)) { idealStates.put(resource, new IdealState(resource)); } } // calculate best possible state BestPossibleStateOutput bestPossOutput = ClusterStateVerifier.calcBestPossState(cache); // set error states if (errStates != null) { for (String resourceName : errStates.keySet()) { Map<String, String> partErrStates = errStates.get(resourceName); for (String partitionName : partErrStates.keySet()) { String instanceName = partErrStates.get(partitionName); Map<String, String> partStateMap = bestPossOutput.getInstanceStateMap(resourceName, new Partition(partitionName)); partStateMap.put(instanceName, "ERROR"); } } } for (String resourceName : idealStates.keySet()) { ExternalView extView = extViews.get(resourceName); if (extView == null) { LOG.info("externalView for " + resourceName + " is not available"); return false; } // step 0: remove empty map and DROPPED state from best possible state Map<Partition, Map<String, String>> bpStateMap = bestPossOutput.getResourceMap(resourceName); Iterator<Entry<Partition, Map<String, String>>> iter = bpStateMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Partition, Map<String, String>> entry = iter.next(); Map<String, String> instanceStateMap = entry.getValue(); if (instanceStateMap.isEmpty()) { iter.remove(); } else { // remove instances with DROPPED state Iterator<Map.Entry<String, String>> insIter = instanceStateMap.entrySet().iterator(); while (insIter.hasNext()) { Map.Entry<String, String> insEntry = insIter.next(); String state = insEntry.getValue(); if (state.equalsIgnoreCase("DROPPED")) { insIter.remove(); } } } } // System.err.println("resource: " + resourceName + ", bpStateMap: " + bpStateMap); // step 1: externalView and bestPossibleState has equal size int extViewSize = extView.getRecord().getMapFields().size(); int bestPossStateSize = bestPossOutput.getResourceMap(resourceName).size(); if (extViewSize != bestPossStateSize) { LOG.info("exterView size (" + extViewSize + ") is different from bestPossState size (" + bestPossStateSize + ") for resource: " + resourceName); // System.out.println("extView: " + extView.getRecord().getMapFields()); // System.out.println("bestPossState: " + // bestPossOutput.getResourceMap(resourceName)); return false; } // step 2: every entry in external view is contained in best possible state for (String partition : extView.getRecord().getMapFields().keySet()) { Map<String, String> evInstanceStateMap = extView.getRecord().getMapField(partition); Map<String, String> bpInstanceStateMap = bestPossOutput.getInstanceStateMap(resourceName, new Partition(partition)); boolean result = ClusterStateVerifier.<String, String>compareMap(evInstanceStateMap, bpInstanceStateMap); if (result == false) { LOG.info("externalView is different from bestPossibleState for partition:" + partition); return false; } } } return true; } catch (Exception e) { LOG.error("exception in verification", e); return false; } }
From source file:com.liferay.portal.lar.PlaytechLayoutExporter.java
public static List<Portlet> getAlwaysExportablePortlets(long companyId) throws Exception { List<Portlet> portlets = PortletLocalServiceUtil.getPortlets(companyId); Iterator<Portlet> itr = portlets.iterator(); while (itr.hasNext()) { Portlet portlet = itr.next();// w ww . java2 s . com if (!portlet.isActive()) { itr.remove(); continue; } PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); if ((portletDataHandler == null) || !portletDataHandler.isAlwaysExportable()) { itr.remove(); } } return portlets; }
From source file:com.griefcraft.util.Closer.java
@Override public final void close() { if (list.isEmpty()) return;//from w w w . j a v a 2 s. co m Iterator<AutoCloseable> iter = list.iterator(); while (iter.hasNext()) { closeQuietly(iter.next()); iter.remove(); } }
From source file:io.swagger.codegen.languages.Swift4Codegen.java
private static CodegenModel reconcileProperties(CodegenModel codegenModel, CodegenModel parentCodegenModel) { // To support inheritance in this generator, we will analyze // the parent and child models, look for properties that match, and remove // them from the child models and leave them in the parent. // Because the child models extend the parents, the properties // will be available via the parent. // Get the properties for the parent and child models final List<CodegenProperty> parentModelCodegenProperties = parentCodegenModel.vars; List<CodegenProperty> codegenProperties = codegenModel.vars; codegenModel.allVars = new ArrayList<CodegenProperty>(codegenProperties); codegenModel.parentVars = parentCodegenModel.allVars; // Iterate over all of the parent model properties boolean removedChildProperty = false; for (CodegenProperty parentModelCodegenProperty : parentModelCodegenProperties) { // Now that we have found a prop in the parent class, // and search the child class for the same prop. Iterator<CodegenProperty> iterator = codegenProperties.iterator(); while (iterator.hasNext()) { CodegenProperty codegenProperty = iterator.next(); if (codegenProperty.baseName == parentModelCodegenProperty.baseName) { // We found a property in the child class that is // a duplicate of the one in the parent, so remove it. iterator.remove(); removedChildProperty = true; }/* w w w . j a va2 s .c om*/ } } if (removedChildProperty) { // If we removed an entry from this model's vars, we need to ensure hasMore is updated int count = 0; int numVars = codegenProperties.size(); for (CodegenProperty codegenProperty : codegenProperties) { count += 1; codegenProperty.hasMore = (count < numVars) ? true : false; } codegenModel.vars = codegenProperties; } return codegenModel; }
From source file:gda.util.exafs.Element.java
/** * Return elements sorted in atomic number range. * //from w w w .j av a2s.c o m * @param fromSymbol * (atomic symbol) * @param toSymbol * (atomic symbol) * @return String[] */ @SuppressWarnings("cast") public static String[] getSortedEdgeSymbols(final String fromSymbol, final String toSymbol) { final List<String> tmp = new ArrayList<String>(symbols.length); tmp.addAll(Arrays.asList(symbols)); Collections.sort(tmp); final Iterator<String> it = tmp.iterator(); final int from = Element.getElement(fromSymbol).getAtomicNumber(); final int to = Element.getElement(toSymbol).getAtomicNumber(); ELEMENT_LOOP: while (it.hasNext()) { final String symbol = it.next(); final Element ele = Element.getElement(symbol); if (ele.getAtomicNumber() < from) { it.remove(); continue ELEMENT_LOOP; } if (ele.getAtomicNumber() > to) { it.remove(); continue ELEMENT_LOOP; } for (int i = 0; i < edgeNames.length; i++) { if (ele.edgeExists(edgeNames[i])) { continue ELEMENT_LOOP; } } it.remove(); } return (String[]) tmp.toArray(new String[tmp.size()]); }
From source file:com.splicemachine.orc.OrcTester.java
private static void assertColumnValueEquals(DataType type, Object actual, Object expected) { if (actual == null) { assertNull(expected);/*from w w w.ja va 2 s . c om*/ return; } if (type instanceof ArrayType) { List<?> actualArray = (List<?>) actual; List<?> expectedArray = (List<?>) expected; assertEquals(actualArray.size(), expectedArray.size()); DataType elementType = ((ArrayType) type).elementType(); for (int i = 0; i < actualArray.size(); i++) { Object actualElement = actualArray.get(i); Object expectedElement = expectedArray.get(i); assertColumnValueEquals(elementType, actualElement, expectedElement); } } else if (type instanceof MapType) { Map<?, ?> actualMap = (Map<?, ?>) actual; Map<?, ?> expectedMap = (Map<?, ?>) expected; assertEquals(actualMap.size(), expectedMap.size()); DataType keyType = ((MapType) type).keyType(); DataType valueType = ((MapType) type).valueType(); List<Entry<?, ?>> expectedEntries = new ArrayList<>(expectedMap.entrySet()); for (Entry<?, ?> actualEntry : actualMap.entrySet()) { Iterator<Entry<?, ?>> iterator = expectedEntries.iterator(); while (iterator.hasNext()) { Entry<?, ?> expectedEntry = iterator.next(); try { assertColumnValueEquals(keyType, actualEntry.getKey(), expectedEntry.getKey()); assertColumnValueEquals(valueType, actualEntry.getValue(), expectedEntry.getValue()); iterator.remove(); } catch (AssertionError ignored) { } } } assertTrue("Unmatched entries " + expectedEntries, expectedEntries.isEmpty()); } else if (type instanceof StructType) { StructField[] fieldTypes = ((StructType) type).fields(); List<?> actualRow = (List<?>) actual; List<?> expectedRow = (List<?>) expected; assertEquals(actualRow.size(), fieldTypes.length); assertEquals(actualRow.size(), expectedRow.size()); for (int fieldId = 0; fieldId < actualRow.size(); fieldId++) { DataType fieldType = fieldTypes[fieldId].dataType(); Object actualElement = actualRow.get(fieldId); Object expectedElement = expectedRow.get(fieldId); assertColumnValueEquals(fieldType, actualElement, expectedElement); } } else if (type instanceof DoubleType) { Double actualDouble = (Double) actual; Double expectedDouble = (Double) expected; if (actualDouble.isNaN()) { assertTrue("expected double to be NaN", expectedDouble.isNaN()); } else { assertEquals(actualDouble, expectedDouble, 0.001); } } else if (!Objects.equals(actual, expected)) { assertEquals(expected, actual); } }
From source file:com.flexive.faces.FxJsfUtils.java
/** * Clears all faces messages (optional: for the given client id). * * @param clientId the client id to work on, or null to remove all messages. *//*from w w w. ja va 2 s . c o m*/ @SuppressWarnings("unchecked") public static void clearAllMessages(String clientId) { //noinspection unchecked Iterator<FacesMessage> it = (clientId == null || clientId.length() == 0) ? getCurrentInstance().getMessages() : getCurrentInstance().getMessages(clientId); while (it.hasNext()) { it.next(); it.remove(); } }