public <T extends Anim> void clearanims(Class<T> type) { for (Iterator<Anim> i = nanims.iterator(); i.hasNext(); ) { Anim a = i.next(); if (type.isInstance(a)) i.remove(); } for (Iterator<Anim> i = anims.iterator(); i.hasNext(); ) { Anim a = i.next(); if (type.isInstance(a)) i.remove(); } }
private void deleteJsonJobs(ApplicationInfo appInfo, List<CIJob> selectedJobs) throws PhrescoException { try { if (CollectionUtils.isEmpty(selectedJobs)) { return; } Gson gson = new Gson(); List<CIJob> jobs = getJobs(appInfo); if (CollectionUtils.isEmpty(jobs)) { return; } // all values Iterator<CIJob> iterator = jobs.iterator(); // deletable values for (CIJob selectedInfo : selectedJobs) { while (iterator.hasNext()) { CIJob itrCiJob = iterator.next(); if (itrCiJob.getName().equals(selectedInfo.getName())) { iterator.remove(); break; } } } writeJsonJobs(appInfo, jobs, CI_CREATE_NEW_JOBS); } catch (Exception e) { throw new PhrescoException(e); } }
/** * Closes given {@link #transportManagers} of this <tt>Conference</tt> and removes corresponding * channel bundle. */ void closeTransportManager(TransportManager transportManager) { synchronized (transportManagers) { for (Iterator<IceUdpTransportManager> i = transportManagers.values().iterator(); i.hasNext(); ) { if (i.next() == transportManager) { i.remove(); // Presumably, we have a single association for // transportManager. break; } } // Close manager try { transportManager.close(); } catch (Throwable t) { logger.warn( "Failed to close an IceUdpTransportManager of" + " conference " + getID() + "!", t); // The whole point of explicitly closing the // transportManagers of this Conference is to prevent memory // leaks. Hence, it does not make sense to possibly leave // TransportManagers open because a TransportManager has // failed to close. if (t instanceof InterruptedException) Thread.currentThread().interrupt(); else if (t instanceof ThreadDeath) throw (ThreadDeath) t; } } }
/** * Remove records telling what entity caps node a contact has. * * @param contact the contact */ public void removeContactCapsNode(Contact contact) { Caps caps = null; String lastRemovedJid = null; Iterator<String> iter = userCaps.keySet().iterator(); while (iter.hasNext()) { String jid = iter.next(); if (StringUtils.parseBareAddress(jid).equals(contact.getAddress())) { caps = userCaps.get(jid); lastRemovedJid = jid; iter.remove(); } } // fire only for the last one, at the end the event out // of the protocol will be one and for the contact if (caps != null) { UserCapsNodeListener[] listeners; synchronized (userCapsNodeListeners) { listeners = userCapsNodeListeners.toArray(NO_USER_CAPS_NODE_LISTENERS); } if (listeners.length != 0) { String nodeVer = caps.getNodeVer(); for (UserCapsNodeListener listener : listeners) listener.userCapsNodeRemoved(lastRemovedJid, nodeVer, false); } } }
private static void clearClosedConnection() { long time = System.currentTimeMillis(); // sometimes user change system time,just return if (time < m_lastClearClosedConnection) { m_lastClearClosedConnection = time; return; } // no need check very often if (time - m_lastClearClosedConnection < CHECK_CLOSED_CONNECTION_TIME) { return; } m_lastClearClosedConnection = time; // begin check Iterator iterator = m_notUsedConnection.iterator(); while (iterator.hasNext()) { ConnectionWrapper wrapper = (ConnectionWrapper) iterator.next(); try { if (wrapper.connection.isClosed()) { iterator.remove(); } } catch (Exception e) { iterator.remove(); if (DEBUG) { System.out.println("connection is closed, this connection initial StackTrace"); wrapper.debugInfo.printStackTrace(); } } } // make connection pool size smaller if too big int decrease = getDecreasingConnectionCount(); if (m_notUsedConnection.size() < decrease) { return; } while (decrease-- > 0) { ConnectionWrapper wrapper = (ConnectionWrapper) m_notUsedConnection.removeFirst(); try { wrapper.connection.close(); } catch (Exception e) { } } }
/** * Method for resolving member method information: aggregating all non-static methods and * combining annotations (to implement method-annotation inheritance) * * @param collectIgnored Whether to collect list of ignored methods for later retrieval */ public void resolveMemberMethods(MethodFilter methodFilter, boolean collectIgnored) { _memberMethods = new AnnotatedMethodMap(); AnnotatedMethodMap mixins = new AnnotatedMethodMap(); // first: methods from the class itself _addMemberMethods(_class, methodFilter, _memberMethods, _primaryMixIn, mixins); // and then augment these with annotations from super-types: for (Class<?> cls : _superTypes) { Class<?> mixin = (_mixInResolver == null) ? null : _mixInResolver.findMixInClassFor(cls); _addMemberMethods(cls, methodFilter, _memberMethods, mixin, mixins); } // Special case: mix-ins for Object.class? (to apply to ALL classes) if (_mixInResolver != null) { Class<?> mixin = _mixInResolver.findMixInClassFor(Object.class); if (mixin != null) { _addMethodMixIns(methodFilter, _memberMethods, mixin, mixins); } } /* Any unmatched mix-ins? Most likely error cases (not matching * any method); but there is one possible real use case: * exposing Object#hashCode (alas, Object#getClass can NOT be * exposed, see [JACKSON-140]) */ if (!mixins.isEmpty()) { Iterator<AnnotatedMethod> it = mixins.iterator(); while (it.hasNext()) { AnnotatedMethod mixIn = it.next(); try { Method m = Object.class.getDeclaredMethod(mixIn.getName(), mixIn.getParameterClasses()); if (m != null) { AnnotatedMethod am = _constructMethod(m); _addMixOvers(mixIn.getAnnotated(), am, false); _memberMethods.add(am); } } catch (Exception e) { } } } /* And last but not least: let's remove all methods that are * deemed to be ignorable after all annotations have been * properly collapsed. */ Iterator<AnnotatedMethod> it = _memberMethods.iterator(); while (it.hasNext()) { AnnotatedMethod am = it.next(); if (_annotationIntrospector.isIgnorableMethod(am)) { it.remove(); if (collectIgnored) { _ignoredMethods = ArrayBuilders.addToList(_ignoredMethods, am); } } } }
String filter(String[] args, boolean include) { verifyCommand(args, String.format(_filterHelp, args[0]), null, 3, 3); Collection<String> list = new ArrayList<String>(Processor.split(args[1])); Pattern pattern = Pattern.compile(args[2]); for (Iterator<String> i = list.iterator(); i.hasNext(); ) { if (pattern.matcher(i.next()).matches() == include) i.remove(); } return Processor.join(list); }
/** * Returns an array containing all installed providers that satisfy the specified* selection * criteria, or null if no such providers have been installed. The returned providers are ordered * according to their <a href= "#insertProviderAt(java.security.Provider, int)">preference * order</a>. * * <p>The selection criteria are represented by a map. Each map entry represents a selection * criterion. A provider is selected iff it satisfies all selection criteria. The key for any * entry in such a map must be in one of the following two formats: * * <ul> * <li><i><crypto_service>.<algorithm_or_type></i> * <p>The cryptographic service name must not contain any dots. * <p>The value associated with the key must be an empty string. * <p>A provider satisfies this selection criterion iff the provider implements the * specified algorithm or type for the specified cryptographic service. * <li><i><crypto_service>.<algorithm_or_type> <attribute_name></i> * <p>The cryptographic service name must not contain any dots. There must be one or more * space charaters between the <i><algorithm_or_type></i> and the * <i><attribute_name></i>. * <p>The value associated with the key must be a non-empty string. A provider satisfies * this selection criterion iff the provider implements the specified algorithm or type for * the specified cryptographic service and its implementation meets the constraint expressed * by the specified attribute name/value pair. * </ul> * * <p>See Appendix A in the <a href= "../../../guide/security/CryptoSpec.html#AppA"> Java * Cryptogaphy Architecture API Specification & Reference </a> for information about standard * cryptographic service names, standard algorithm names and standard attribute names. * * @param filter the criteria for selecting providers. The filter is case-insensitive. * @return all the installed providers that satisfy the selection criteria, or null if no such * providers have been installed. * @throws InvalidParameterException if the filter is not in the required format * @throws NullPointerException if filter is null * @see #getProviders(java.lang.String) */ public static Provider[] getProviders(Map<String, String> filter) { // Get all installed providers first. // Then only return those providers who satisfy the selection criteria. Provider[] allProviders = Security.getProviders(); Set keySet = filter.keySet(); LinkedHashSet candidates = new LinkedHashSet(5); // Returns all installed providers // if the selection criteria is null. if ((keySet == null) || (allProviders == null)) { return allProviders; } boolean firstSearch = true; // For each selection criterion, remove providers // which don't satisfy the criterion from the candidate set. for (Iterator ite = keySet.iterator(); ite.hasNext(); ) { String key = (String) ite.next(); String value = (String) filter.get(key); LinkedHashSet newCandidates = getAllQualifyingCandidates(key, value, allProviders); if (firstSearch) { candidates = newCandidates; firstSearch = false; } if ((newCandidates != null) && !newCandidates.isEmpty()) { // For each provider in the candidates set, if it // isn't in the newCandidate set, we should remove // it from the candidate set. for (Iterator cansIte = candidates.iterator(); cansIte.hasNext(); ) { Provider prov = (Provider) cansIte.next(); if (!newCandidates.contains(prov)) { cansIte.remove(); } } } else { candidates = null; break; } } if ((candidates == null) || (candidates.isEmpty())) return null; Object[] candidatesArray = candidates.toArray(); Provider[] result = new Provider[candidatesArray.length]; for (int i = 0; i < result.length; i++) { result[i] = (Provider) candidatesArray[i]; } return result; }
/** Closes the {@link #transportManagers} of this <tt>Conference</tt>. */ private void closeTransportManagers() { synchronized (transportManagers) { for (Iterator<IceUdpTransportManager> i = transportManagers.values().iterator(); i.hasNext(); ) { IceUdpTransportManager transportManager = i.next(); i.remove(); closeTransportManager(transportManager); } } }
private void nudge() { for (Iterator<RecorderEvent> iter = pendingEvents.iterator(); iter.hasNext(); ) { RecorderEvent ev = iter.next(); long instant = getSynchronizer().getLocalTime(ev.getSsrc(), ev.getRtpTimestamp()); if (instant != -1) { iter.remove(); ev.setInstant(instant); handler.handleEvent(ev); } } }
public void tick(double dt) throws InterruptedException { Widget next; for (Widget wdg = child; wdg != null; wdg = next) { next = wdg.next; wdg.tick(dt); } /* It would be very nice to do these things in harmless mix-in * classes, but alas, this is Java. */ anims.addAll(nanims); nanims.clear(); for (Iterator<Anim> i = anims.iterator(); i.hasNext(); ) { Anim anim = i.next(); if (anim.tick(dt)) i.remove(); } }
private boolean verifyTestMethodsInJUnit38TestClassThatShouldRun(JUnit38ClassRunner runner) { Description testClassDescription = runner.getDescription(); Class<?> testClass = testClassDescription.getTestClass(); Iterator<Description> itr = testClassDescription.getChildren().iterator(); while (itr.hasNext()) { Description testDescription = itr.next(); String testMethodName = testDescription.getMethodName(); testMethod = findPublicVoidMethod(testClass, testMethodName); Boolean shouldRun = shouldRunTestInCurrentTestRun(null, testMethod); if (shouldRun != null && !shouldRun) { itr.remove(); } } return testClassDescription.getChildren().isEmpty(); }
boolean closeAndRemoveResultSets(Set rsSet) { boolean okay = true; synchronized (rsSet) { for (Iterator ii = rsSet.iterator(); ii.hasNext(); ) { ResultSet rs = (ResultSet) ii.next(); try { rs.close(); } catch (SQLException e) { if (Debug.DEBUG) logger.log(MLevel.WARNING, "An exception occurred while cleaning up a ResultSet.", e); // e.printStackTrace(); okay = false; } finally { ii.remove(); } } } return okay; }
List<Modification> getModifications( final T o, final boolean deleteNullValues, final String... attributes) throws LDAPPersistException { final ReadOnlyEntry originalEntry; if (entryField != null) { originalEntry = getEntry(o); } else { originalEntry = null; } if (originalEntry != null) { try { final T decodedOrig = decode(originalEntry); final Entry reEncodedOriginal = encode(decodedOrig, originalEntry.getParentDNString()); final Entry newEntry = encode(o, originalEntry.getParentDNString()); final List<Modification> mods = Entry.diff(reEncodedOriginal, newEntry, true, false, attributes); if (!deleteNullValues) { final Iterator<Modification> iterator = mods.iterator(); while (iterator.hasNext()) { final Modification m = iterator.next(); if (m.getRawValues().length == 0) { iterator.remove(); } } } HashSet<String> stripAttrs = null; for (final FieldInfo i : fieldMap.values()) { if (!i.includeInModify()) { if (stripAttrs == null) { stripAttrs = new HashSet<String>(10); } stripAttrs.add(toLowerCase(i.getAttributeName())); } } for (final GetterInfo i : getterMap.values()) { if (!i.includeInModify()) { if (stripAttrs == null) { stripAttrs = new HashSet<String>(10); } stripAttrs.add(toLowerCase(i.getAttributeName())); } } if (stripAttrs != null) { final Iterator<Modification> iterator = mods.iterator(); while (iterator.hasNext()) { final Modification m = iterator.next(); if (stripAttrs.contains(toLowerCase(m.getAttributeName()))) { iterator.remove(); } } } return mods; } catch (final Exception e) { debugException(e); } finally { setDNAndEntryFields(o, originalEntry); } } final HashSet<String> attrSet; if ((attributes == null) || (attributes.length == 0)) { attrSet = null; } else { attrSet = new HashSet<String>(attributes.length); for (final String s : attributes) { attrSet.add(toLowerCase(s)); } } final ArrayList<Modification> mods = new ArrayList<Modification>(5); for (final Map.Entry<String, FieldInfo> e : fieldMap.entrySet()) { final String attrName = toLowerCase(e.getKey()); if ((attrSet != null) && (!attrSet.contains(attrName))) { continue; } final FieldInfo i = e.getValue(); if (!i.includeInModify()) { continue; } final Attribute a = i.encode(o, false); if (a == null) { if (!deleteNullValues) { continue; } if ((originalEntry != null) && (!originalEntry.hasAttribute(attrName))) { continue; } mods.add(new Modification(ModificationType.REPLACE, i.getAttributeName())); continue; } if (originalEntry != null) { final Attribute originalAttr = originalEntry.getAttribute(attrName); if ((originalAttr != null) && originalAttr.equals(a)) { continue; } } mods.add(new Modification(ModificationType.REPLACE, i.getAttributeName(), a.getRawValues())); } for (final Map.Entry<String, GetterInfo> e : getterMap.entrySet()) { final String attrName = toLowerCase(e.getKey()); if ((attrSet != null) && (!attrSet.contains(attrName))) { continue; } final GetterInfo i = e.getValue(); if (!i.includeInModify()) { continue; } final Attribute a = i.encode(o); if (a == null) { if (!deleteNullValues) { continue; } if ((originalEntry != null) && (!originalEntry.hasAttribute(attrName))) { continue; } mods.add(new Modification(ModificationType.REPLACE, i.getAttributeName())); continue; } if (originalEntry != null) { final Attribute originalAttr = originalEntry.getAttribute(attrName); if ((originalAttr != null) && originalAttr.equals(a)) { continue; } } mods.add(new Modification(ModificationType.REPLACE, i.getAttributeName(), a.getRawValues())); } if (superclassHandler != null) { final List<Modification> superMods = superclassHandler.getModifications(o, deleteNullValues, attributes); final ArrayList<Modification> modsToAdd = new ArrayList<Modification>(superMods.size()); for (final Modification sm : superMods) { boolean add = true; for (final Modification m : mods) { if (m.getAttributeName().equalsIgnoreCase(sm.getAttributeName())) { add = false; break; } } if (add) { modsToAdd.add(sm); } } mods.addAll(modsToAdd); } return Collections.unmodifiableList(mods); }
public void buildTypeGraph() { Map<String, JarFile> openJarFiles = new HashMap<String, JarFile>(); Map<String, File> openClassFiles = new HashMap<String, File>(); // use global cache to load resource in/out of the same jar as the classes Set<String> resourceCacheSet = new HashSet<>(); try { for (String path : pathsToScan) { File f = null; try { f = new File(path); if (!f.exists() || f.isDirectory() || (!f.getName().endsWith("jar") && !f.getName().endsWith("class"))) { continue; } if (GENERATED_CLASSES_JAR.equals(f.getName())) { continue; } if (f.getName().endsWith("class")) { typeGraph.addNode(f); openClassFiles.put(path, f); } else { JarFile jar = new JarFile(path); openJarFiles.put(path, jar); java.util.Enumeration<JarEntry> entriesEnum = jar.entries(); while (entriesEnum.hasMoreElements()) { final java.util.jar.JarEntry jarEntry = entriesEnum.nextElement(); String entryName = jarEntry.getName(); if (jarEntry.isDirectory()) { continue; } if (entryName.endsWith("-javadoc.xml")) { try { processJavadocXml(jar.getInputStream(jarEntry)); // break; } catch (Exception ex) { LOG.warn("Cannot process javadoc {} : ", entryName, ex); } } else if (entryName.endsWith(".class")) { TypeGraph.TypeGraphVertex newNode = typeGraph.addNode(jarEntry, jar); // check if any visited resources belong to this type for (Iterator<String> iter = resourceCacheSet.iterator(); iter.hasNext(); ) { String entry = iter.next(); if (entry.startsWith(entryName.substring(0, entryName.length() - 6))) { newNode.setHasResource(true); iter.remove(); } } } else { String className = entryName; boolean foundClass = false; // check if this resource belongs to any visited type while (className.contains("/")) { className = className.substring(0, className.lastIndexOf('/')); TypeGraph.TypeGraphVertex tgv = typeGraph.getNode(className.replace('/', '.')); if (tgv != null) { tgv.setHasResource(true); foundClass = true; break; } } if (!foundClass) { resourceCacheSet.add(entryName); } } } } } catch (IOException ex) { LOG.warn("Cannot process file {}", f, ex); } } typeGraph.trim(); typeGraph.updatePortTypeInfoInTypeGraph(openJarFiles, openClassFiles); } finally { for (Entry<String, JarFile> entry : openJarFiles.entrySet()) { try { entry.getValue().close(); } catch (IOException e) { DTThrowable.wrapIfChecked(e); } } } }