List of usage examples for java.util Iterator remove
default void remove()
From source file:de.Keyle.MyPet.util.BukkitUtil.java
@SuppressWarnings("unchecked") public static boolean registerMyPetEntity(Class<? extends EntityMyPet> myPetEntityClass, String entityTypeName, int entityTypeId) { try {/*w ww . j av a2s . c om*/ Field EntityTypes_d = EntityTypes.class.getDeclaredField("d"); Field EntityTypes_f = EntityTypes.class.getDeclaredField("f"); EntityTypes_d.setAccessible(true); EntityTypes_f.setAccessible(true); Map<Class, String> d = (Map) EntityTypes_d.get(EntityTypes_d); Map<Class, Integer> f = (Map) EntityTypes_f.get(EntityTypes_f); Iterator cIterator = d.keySet().iterator(); while (cIterator.hasNext()) { Class clazz = (Class) cIterator.next(); if (clazz.getCanonicalName().equals(myPetEntityClass.getCanonicalName())) { cIterator.remove(); } } Iterator eIterator = f.keySet().iterator(); while (eIterator.hasNext()) { Class clazz = (Class) eIterator.next(); if (clazz.getCanonicalName().equals(myPetEntityClass.getCanonicalName())) { eIterator.remove(); } } d.put(myPetEntityClass, entityTypeName); f.put(myPetEntityClass, entityTypeId); return true; } catch (Exception e) { DebugLogger.severe("error while registering " + myPetEntityClass.getCanonicalName()); DebugLogger.severe(e.getMessage()); return false; } }
From source file:com.wolvereness.overmapped.lib.WellOrdered.java
private static <T> boolean handleTokens(final T token, final Map<T, Collection<T>> map, final Set<T> in) { final Iterator<T> it = getIterator(token, map); if (it == null) return true; while (it.hasNext()) { if (in.contains(it.next())) return false; // Short the search for next time it.remove(); }/*from w ww . j a v a 2 s . c o m*/ // Short the search further for next time as collection is empty map.remove(token); return true; }
From source file:de.uniba.wiai.kinf.pw.projects.lillytab.terms.impl.AbstractFixedTermList.java
protected static <T extends Comparable<? super T> & ITerm> void sortAndEnsureUnique(AbstractFixedTermList<T> t, final int minimumSize) { Collections.sort(t.getModifiableTermList()); final Iterator<T> iter = t.getModifiableTermList().iterator(); T prev = null;/*from w ww. j av a 2s . c om*/ while (iter.hasNext()) { final T cur = iter.next(); if ((prev != null) && prev.equals(cur)) { prev = cur; iter.remove(); } } if (t.size() < minimumSize) throw new IllegalArgumentException("Need at least " + minimumSize + " distinct arguments"); }
From source file:com.netflix.subtitles.ttml.TtmlUtils.java
/** * Reduce timed objects according to start and end and normalize timeExpressions according to virtual track times. * <p></p>/* w w w .j av a 2 s . c om*/ * dur attributes will be converted to end attributes and all time expression will be in SMPTE time code format. If * frameRate and frameRateMultiplier are not specified then default 30 and 1000 1001 values will be used. * <p></p> * region, span and set <timeExpression> will be ignored. Nested div elements are not supported too. * * @param tt root timed object that will be reduced by times * @param offsetMS virtual track time offset in millis * @param startMS ttml content start time in millis * @param endMS ttml content end time in millis * @param frameRate ttml new frame rate. If specified, timeExpressions will be normalized according new value. */ public static void reduceAccordingSegment(TtEltype tt, long offsetMS, long startMS, long endMS, BigFraction frameRate) { TtmlTimeConverter ttConverter = new TtmlTimeConverter(tt); long totalBegin = ttConverter.parseTimeExpression(tt.getBody().getBegin()); // remove body timeExpressions tt.getBody().setBegin(null); tt.getBody().setEnd(null); tt.getBody().setDur(null); Iterator<DivEltype> divIt = tt.getBody().getDiv().iterator(); while (divIt.hasNext()) { DivEltype div = divIt.next(); totalBegin += ttConverter.parseTimeExpression(div.getBegin()); // remove div timeExpressions div.setBegin(null); div.setEnd(null); div.setDur(null); // remove nested divs and filter p according interval [startMS; endMS] Iterator blockIt = div.getBlockClass().iterator(); // p or div while (blockIt.hasNext()) { Object blockClass = blockIt.next(); if (!(blockClass instanceof PEltype)) { blockIt.remove(); continue; } PEltype p = (PEltype) blockClass; long pBegin = totalBegin + ttConverter.parseTimeExpression(p.getBegin()); long pEnd = totalBegin + getEnd(ttConverter, p.getBegin(), p.getEnd(), p.getDur()); if (pEnd < startMS || pBegin > endMS) { // remove not matched blockIt.remove(); continue; } if (pBegin < startMS) { pBegin = startMS; } if (pEnd > endMS) { pEnd = endMS; } // set p timeExpression according to a virtual track times p.setBegin(ConversionHelper.msToSmpteTimecode(offsetMS + pBegin - startMS, frameRate == null ? ttConverter.getUnitsInSec() : frameRate)); p.setEnd(ConversionHelper.msToSmpteTimecode(offsetMS + pEnd - startMS, frameRate == null ? ttConverter.getUnitsInSec() : frameRate)); p.setDur(null); } if (div.getBlockClass().isEmpty()) { divIt.remove(); } } // update ttml values according to new frame rate if (frameRate != null) { frameRate = frameRate.reduce(); if (frameRate.getDenominatorAsInt() == 1) { tt.setFrameRate(frameRate.getNumerator()); tt.setFrameRateMultiplier("1 1"); } else { BigInteger ttFrameRate = frameRate.getNumerator().divide(new BigInteger("1000")); tt.setFrameRate(ttFrameRate); tt.setFrameRateMultiplier("1000" + " " + frameRate.getDenominatorAsInt()); } } }
From source file:net.sourceforge.stripes.integration.spring.SpringHelper.java
/** * Fetches the methods on a class that are annotated with SpringBean. The first time it * is called for a particular class it will introspect the class and cache the results. * All non-overridden methods are examined, including protected and private methods. * If a method is not public an attempt it made to make it accessible - if it fails * it is removed from the collection and an error is logged. * * @param clazz the class on which to look for SpringBean annotated methods * @return the collection of methods with the annotation *///from www. ja v a 2s . co m protected static Collection<Method> getMethods(Class<?> clazz) { Collection<Method> methods = methodMap.get(clazz); if (methods == null) { methods = ReflectUtil.getMethods(clazz); Iterator<Method> iterator = methods.iterator(); while (iterator.hasNext()) { Method method = iterator.next(); if (!method.isAnnotationPresent(SpringBean.class)) { iterator.remove(); } else { // If the method isn't public, try to make it accessible if (!method.isAccessible()) { try { method.setAccessible(true); } catch (SecurityException se) { throw new StripesRuntimeException("Method " + clazz.getName() + "." + method.getName() + "is marked " + "with @SpringBean and is not public. An attempt to call " + "setAccessible(true) resulted in a SecurityException. Please " + "either make the method public or modify your JVM security " + "policy to allow Stripes to setAccessible(true).", se); } } // Ensure the method has only the one parameter if (method.getParameterTypes().length != 1) { throw new StripesRuntimeException( "A method marked with @SpringBean must have exactly one parameter: " + "the bean to be injected. Method [" + method.toGenericString() + "] has " + method.getParameterTypes().length + " parameters."); } } } methodMap.put(clazz, methods); } return methods; }
From source file:com.doculibre.constellio.solr.context.SolrCoreContext.java
public static synchronized void initCores() { try {/* w w w . ja v a 2 s . com*/ // do not use CoreAdminRequest Set<String> collectionNameSet = new HashSet<String>(); mainSolrServer.connect(); ZkStateReader reader = mainSolrServer.getZkStateReader(); ClusterState state = reader.getClusterState(); // do synchronization between coreServers and solrCloud for (String collectionName : state.getCollections()) { if (!collectionName.startsWith("_") || DEFAULT_COLLECTION_NAME.equals(collectionName)) { // "_xxx" is for system only, not for users collectionNameSet.add(collectionName); } } Map<String, String> aliasMap = reader.getAliases().getCollectionAliasMap(); if (aliasMap != null) { for (String aliasName : aliasMap.keySet()) { if (!aliasName.startsWith("_")) { // "_xxx" is for system only, not for users collectionNameSet.remove(aliasMap.get(aliasName)); collectionNameSet.add(aliasName); } } } for (String collectionName : collectionNameSet) { if (!coreServers.containsKey(collectionName)) { setHttpSolrServer(collectionName, ConstellioSpringUtils.getSolrServerAddress()); } } userCoreNames.clear(); Iterator<Map.Entry<String, SolrServer>> iter = coreServers.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, SolrServer> entry = iter.next(); if (!collectionNameSet.contains(entry.getKey())) { entry.getValue().shutdown(); iter.remove(); } else if (!DEFAULT_COLLECTION_NAME.equals(entry.getKey())) { userCoreNames.add(entry.getKey()); } } // CoreAdminRequest adminRequest = new CoreAdminRequest(); // adminRequest.setAction(CoreAdminAction.STATUS); // CoreAdminResponse adminResponse = // adminRequest.process(solrServer); // NamedList<NamedList<Object>> coreStatus = // adminResponse.getCoreStatus(); // for (Object core : coreStatus) { // String coreName = StringUtils.substringBefore(core.toString(), // "="); // if (!coreName.startsWith("_"))// "_xxx" is for system only, like // "_log", "_fetch_db" // setHttpSolrServer(coreName, ((HttpSolrServer) // solrServer).getBaseURL()); // } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.zenoss.jmx.ValueExtractor.java
/** * Traverses a TabularData or CompositeData structure to return nested data * /*from w w w . j a va 2 s. com*/ * e.g. To get the the used perm gen memory before last garbage collection * value from the result of the lastGcInfo attribute of the * java.lang:type=GarbageCollector,name=Copy mbean the path used would be * * memoryUsageBeforeGc.[Perm Gen].used * * In general the non bracketed values are keys into CompositeData and the * bracketed values are indexes into TabularData. For TabularData indexes * with more than one value a comma separated list without spaces should be * used, spaces are treated as part of the values in the index array. * * e.g. [key1,key2] * * The brackets aren't mandatory for indexes but are included for clarity. * * Curly brackets can be used after a table index to specify a column name. * * e.g memoryUsageBeforeGc.[Perm Gen].{value}.used * * The column name is only necessary when the table has more than two * columns. If the table has two columns then the value is read from the * column not used for the index. * * @param obj * TabularData, CompositeData, or Map * @param path * dot separated string that represents a path through the object * @return Object the value at the end of the path * @throws JmxException * if a path element doesn't exist */ public static Object getDataValue(final Object obj, String path) throws JmxException { if (!(obj instanceof TabularData) && !(obj instanceof CompositeData) && !(obj instanceof Map)) { throw new IllegalArgumentException("Cannot process object of type " + obj.getClass().getName()); } _logger.debug("getDataValue: path is " + path); List<String> pathList = split(path); _logger.debug("getDataValue: pathList " + pathList); Object currentObj = obj; Iterator<String> pathElements = pathList.iterator(); try { while (pathElements.hasNext()) { _logger.debug("getDataValue: current object is " + obj); String currentKey = pathElements.next(); pathElements.remove(); _logger.debug("getDataValue: currentKey: " + currentKey); if (currentObj instanceof TabularData) { _logger.debug("getDataValue: dealing with tabularData"); TabularData tData = (TabularData) currentObj; String[] index = createTableIndex(currentKey); currentObj = getDataByTableIndex(tData, index); CompositeData cData = (CompositeData) currentObj; int columnCount = cData.values().size(); String nextKey = null; // look ahead and look for explicit column if (!pathList.isEmpty()) { nextKey = pathList.get(0); } if (nextKey != null && (isColumn(nextKey) || columnCount > 2)) { String columnKey = pathElements.next(); pathElements.remove(); if (isColumn(columnKey)) { _logger.debug("using explicit column key " + columnKey + " for tabular data"); // remove first and last char - should be curly // brackets columnKey = columnKey.substring(1, columnKey.length() - 1); } else { _logger.debug( "using column key " + columnKey + " for tabular data. No curly brackets found"); } currentObj = getData(cData, columnKey); } else if (cData.values().size() == 2) { currentObj = getTableRowData(cData, index); } } else if (currentObj instanceof CompositeData) { _logger.debug("getDataValue: dealing with CompositeData"); CompositeData cData = (CompositeData) currentObj; currentObj = getData(cData, currentKey); } else if (currentObj instanceof Map) { _logger.debug("getDataValue: dealing with Map"); Map mData = (Map) currentObj; currentObj = getData(mData, currentKey); } else { // we still have a path but the object isn't composite or // tabluar String remainingPath = currentKey; for (String val : pathList) { remainingPath += "."; remainingPath += val; } _logger.warn( "getDataValue: we still have a path but the " + "object isn't composite or tabluar"); _logger.warn("getDataValue: remaining path is " + remainingPath); throw new JmxException("we still have a path but the " + "object isn't composite or tabluar, remaining " + "" + "path is " + remainingPath); } } } catch (Exception e) { _logger.warn("could not get object for path " + path, e); throw new JmxException("could not get object for path " + path + "; " + e.getMessage(), e); } return currentObj; }
From source file:cooccurrence.emf.java
/** * Method to populate the apache matrix from cooccur hashmap * * @param matrixR/* w w w.j ava 2 s . c o m*/ * @param cooccur * @param rowStrings * @param colStrings */ private static void populateMatrixR(RealMatrix matrixR, HashMap<String, HashMap<String, Double>> cooccur, ArrayList<String> rowStrings, ArrayList<String> colStrings) { Iterator iter = cooccur.keySet().iterator(); while (iter.hasNext()) { String row = iter.next().toString(); int i = rowStrings.indexOf(row); HashMap<String, Double> inner = cooccur.get(row); for (String col : inner.keySet()) { int j = colStrings.indexOf(col); double val = inner.get(col); matrixR.setEntry(j, i, val); // each column in D represents the vector w-> d_w } iter.remove(); } }
From source file:com.oinux.lanmitm.util.RequestParser.java
public static ArrayList<BasicClientCookie> getCookiesFromHeaders(ArrayList<String> headers) { ArrayList<String> values = getHeaderValues("Cookie", headers); if (values != null && values.size() > 0) { ArrayList<BasicClientCookie> cookies = new ArrayList<BasicClientCookie>(); for (String value : values) { ArrayList<BasicClientCookie> lineCookies = parseRawCookie(value); if (lineCookies != null && lineCookies.size() > 0) { cookies.addAll(lineCookies); }//from w w w.j a v a 2 s .c om } Iterator<BasicClientCookie> it = cookies.iterator(); while (it.hasNext()) { BasicClientCookie cookie = (BasicClientCookie) it.next(); if (cookie.getName().startsWith("__utm") || cookie.getName().equals("__cfduid")) it.remove(); } return cookies.size() > 0 ? cookies : new ArrayList<BasicClientCookie>(); } return new ArrayList<BasicClientCookie>(); }
From source file:com.splicemachine.db.impl.ast.FindHashJoinColumns.java
private static void rebuildJoinNodeRCL(JoinNode node, ResultSetNode child, ResultColumn rc) throws StandardException { boolean isLeft = node.getLeftResultSet() == child ? true : false; ResultColumnList rcl = node.getResultColumns(); if (isLeft) { int size = rcl.size(); JBitSet leftReferencedTableMap = node.getLeftResultSet().getReferencedTableMap(); // make a copy of result column list ResultColumnList temp = new ResultColumnList(); for (int i = 0; i < size; ++i) { temp.addResultColumn(rcl.elementAt(0)); rcl.removeElementAt(0);//from w ww . j av a 2s . c om } // copy result columns that reference to left result set Set<ResultSetNode> leftResultSetNodeSet = getResultSetNodes(node.getLeftResultSet()); Iterator<ResultColumn> iter = temp.iterator(); while (iter.hasNext()) { ResultColumn resultColumn = iter.next(); if (fromResultSets(leftResultSetNodeSet, resultColumn)) { rcl.addResultColumn(resultColumn); iter.remove(); } else break; } // Add a new column to join result column list rcl.addResultColumn(rc); // copy columns that reference to the right result set while (temp.size() > 0) { rcl.addResultColumn(temp.elementAt(0)); temp.removeElementAt(0); } } else { rcl.addResultColumn(rc); } }