List of usage examples for java.util Collection iterator
Iterator<E> iterator();
From source file:net.sourceforge.floggy.maven.ZipUtils.java
/** * DOCUMENT ME!/*from w w w . j a v a 2 s . c o m*/ * * @param directories DOCUMENT ME! * @param output DOCUMENT ME! * * @throws IOException DOCUMENT ME! */ public static void zip(File[] directories, File output) throws IOException { FileInputStream in = null; ZipOutputStream out = null; ZipEntry entry = null; Collection allFiles = new LinkedList(); for (int i = 0; i < directories.length; i++) { allFiles.addAll(FileUtils.listFiles(directories[i], null, true)); } out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(output))); for (Iterator iter = allFiles.iterator(); iter.hasNext();) { File temp = (File) iter.next(); String name = getEntryName(directories, temp.getAbsolutePath()); entry = new ZipEntry(name); out.putNextEntry(entry); if (!temp.isDirectory()) { in = new FileInputStream(temp); IOUtils.copy(in, out); in.close(); } } out.close(); }
From source file:grails.plugin.searchable.internal.compass.mapping.CompassMappingUtils.java
/** * Resolve aliases between mappings//from ww w.java 2s. c o m * Note this method is destructive in the sense that it modifies the passed in mappings */ public static void resolveAliases(List classMappings, Collection grailsDomainClasses) { // set defaults for those classes without explicit aliases and collect aliases Map mappingByClass = new HashMap(); Map mappingsByAlias = new HashMap(); for (Iterator iter = classMappings.iterator(); iter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) iter.next(); if (classMapping.getAlias() == null) { classMapping.setAlias(getDefaultAlias(classMapping.getMappedClass())); } mappingByClass.put(classMapping.getMappedClass(), classMapping); List mappings = (List) mappingsByAlias.get(classMapping.getAlias()); if (mappings == null) { mappings = new ArrayList(); mappingsByAlias.put(classMapping.getAlias(), mappings); } mappings.add(classMapping); } // override duplicate inherited aliases for (Iterator iter = mappingsByAlias.keySet().iterator(); iter.hasNext();) { List mappings = (List) mappingsByAlias.get(iter.next()); if (mappings.size() == 1) { continue; } CompassClassMapping parentMapping = null; for (Iterator miter = mappings.iterator(); miter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) miter.next(); if (classMapping.getMappedClassSuperClass() == null) { parentMapping = classMapping; break; } } mappings.remove(parentMapping); for (Iterator miter = mappings.iterator(); miter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) miter.next(); LOG.debug("Overriding duplicated alias [" + classMapping.getAlias() + "] for class [" + classMapping.getMappedClass().getName() + "] with default alias. (Aliases must be unique - maybe this was inherited from a superclass?)"); classMapping.setAlias(getDefaultAlias(classMapping.getMappedClass())); } } // resolve property ref aliases for (Iterator iter = classMappings.iterator(); iter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) iter.next(); Class mappedClass = classMapping.getMappedClass(); for (Iterator piter = classMapping.getPropertyMappings().iterator(); piter.hasNext();) { CompassClassPropertyMapping propertyMapping = (CompassClassPropertyMapping) piter.next(); if ((propertyMapping.isComponent() || propertyMapping.isReference()) && !propertyMapping.hasAttribute("refAlias")) { Set aliases = new HashSet(); Class clazz = propertyMapping.getPropertyType(); aliases.add(((CompassClassMapping) mappingByClass.get(clazz)).getAlias()); GrailsDomainClassProperty domainClassProperty = GrailsDomainClassUtils .getGrailsDomainClassProperty(grailsDomainClasses, mappedClass, propertyMapping.getPropertyName()); GrailsDomainClass dc = domainClassProperty.getReferencedDomainClass(); if (dc == null) { Class elementClass = SearchableUtils.getElementClass(domainClassProperty); dc = GrailsDomainClassUtils.getGrailsDomainClass(elementClass, grailsDomainClasses); if (dc == null) { LOG.warn("Cannot find domain class for property '" + domainClassProperty.getName() + "' of class '" + domainClassProperty.getDomainClass().getFullName()); continue; } } Collection clazzes = GrailsDomainClassUtils.getClazzes(dc.getSubClasses()); for (Iterator citer = clazzes.iterator(); citer.hasNext();) { CompassClassMapping mapping = (CompassClassMapping) mappingByClass.get(citer.next()); if (mapping != null) { aliases.add(mapping.getAlias()); } } propertyMapping.setAttribute("refAlias", DefaultGroovyMethods.join(aliases, ", ")); } } } // resolve extend aliases for (Iterator iter = classMappings.iterator(); iter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) iter.next(); Class mappedClassSuperClass = classMapping.getMappedClassSuperClass(); if (mappedClassSuperClass != null && classMapping.getExtend() == null) { CompassClassMapping mapping = (CompassClassMapping) mappingByClass.get(mappedClassSuperClass); classMapping.setExtend(mapping.getAlias()); } } }
From source file:com.ebay.logstorm.core.utils.PipelineEnvironmentLoaderForTest.java
private static File findAssemblyJarFile(String relativeToHomePath) { String projectRootDir = System.getProperty("user.dir"); String assemblyModuleTargeDirPath = relativeToHomePath == null ? projectRootDir + "/assembly/target/" : projectRootDir + relativeToHomePath + "/assembly/target/"; File assemblyTargeDirFile = new File(assemblyModuleTargeDirPath); if (!assemblyTargeDirFile.exists()) { throw new IllegalStateException( assemblyModuleTargeDirPath + " not found, please execute 'mvn install -DskipTests' under " + projectRootDir + " to build the project firstly and retry"); }/*www .j a v a2 s .c o m*/ String jarFileNameWildCard = "logstorm-assembly-*.jar"; Collection<File> jarFiles = FileUtils.listFiles(assemblyTargeDirFile, new WildcardFileFilter(jarFileNameWildCard), TrueFileFilter.INSTANCE); if (jarFiles.size() == 0) { throw new IllegalStateException( "jar is not found, please execute 'mvn install -DskipTests' from project root firstly and retry"); } File jarFile = jarFiles.iterator().next(); LOG.debug("Found pipeline.jar: {}", jarFile.getAbsolutePath()); return jarFile; }
From source file:edu.byu.nlp.util.Collections3.java
/** * Creates a new collection that is logically the concatenation of the provided collections. The returned collection * is a view over the original two.//from w w w . ja va2 s. c o m */ public static <E> Collection<E> concat(final Collection<E> coll1, final Collection<E> coll2) { return new AbstractCollection<E>() { @Override public Iterator<E> iterator() { return Iterators.concat(coll1.iterator(), coll2.iterator()); } @Override public int size() { return coll1.size() + coll2.size(); } }; }
From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.ServiceDescriptionTests.java
public static Collection<Object[]> getReferencedUrls(String base) throws IOException, XPathException, ParserConfigurationException, SAXException { Properties setupProps = SetupProperties.setup(null); String userId = setupProps.getProperty("userId"); String pw = setupProps.getProperty("pw"); HttpResponse resp = OSLCUtils.getResponseFromUrl(base, base, new UsernamePasswordCredentials(userId, pw), OSLCConstants.CT_DISC_CAT_XML + ", " + OSLCConstants.CT_DISC_DESC_XML); //If our 'base' is a ServiceDescription we don't need to recurse as this is the only one we can find if (resp.getEntity().getContentType().getValue().contains(OSLCConstants.CT_DISC_DESC_XML)) { Collection<Object[]> data = new ArrayList<Object[]>(); data.add(new Object[] { base }); EntityUtils.consume(resp.getEntity()); return data; }/*from w w w .ja v a 2 s .c o m*/ Document baseDoc = OSLCUtils.createXMLDocFromResponseBody(EntityUtils.toString(resp.getEntity())); //ArrayList to contain the urls from all SPCs Collection<Object[]> data = new ArrayList<Object[]>(); //Get all the ServiceDescriptionDocuments from this ServiceProviderCatalog NodeList sDescs = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_disc:services/@rdf:resource", baseDoc, XPathConstants.NODESET); for (int i = 0; i < sDescs.getLength(); i++) { String uri = sDescs.item(i).getNodeValue(); uri = OSLCUtils.absoluteUrlFromRelative(base, uri); data.add(new Object[] { uri }); } //Get all ServiceProviderCatalog urls from the base document in order to recursively add all the //description documents from them as well. NodeList spcs = (NodeList) OSLCUtils.getXPath().evaluate( "//oslc_disc:entry/oslc_disc:ServiceProviderCatalog/@rdf:about", baseDoc, XPathConstants.NODESET); for (int i = 0; i < spcs.getLength(); i++) { String uri = spcs.item(i).getNodeValue(); uri = OSLCUtils.absoluteUrlFromRelative(base, uri); if (!uri.equals(base)) { Collection<Object[]> subCollection = getReferencedUrls(uri); Iterator<Object[]> iter = subCollection.iterator(); while (iter.hasNext()) { data.add(iter.next()); } } } return data; }
From source file:edu.northwestern.bioinformatics.studycalendar.domain.StudySite.java
@Transient public static StudySite findStudySite(Study study, Site site) { if (study != null && site != null) { Collection<StudySite> studySite = CollectionUtils.intersection(study.getStudySites(), site.getStudySites());/*from w ww.ja v a2 s .co m*/ if (studySite != null && studySite.size() > 0) { return studySite.iterator().next(); } } return null; }
From source file:Main.java
/** * Format a collection using it's element's {@link String#valueOf(Object)} method, but inserting a separator between * consecutive elements, and not surrounding the result by any braket, brace or parenthesis. * * @param theCollection The collection to format. Must not be null. * @param theSeparator The string used to interleave between consecutive elements. May be "" to pack elements together. Normally use a * space around, e.g. " OR ". If null, then the empty string is used. * @return A formatter string, never null. May span several lines depending on the element's toString() or on the separator value. * @throws IllegalArgumentException If coll is null. *///from w w w. j a v a 2 s . co m public static String formatSeparated(Collection<?> theCollection, String theSeparator) { if (theCollection == null) { throw new IllegalArgumentException("Cannot format null collection"); } String separator = theSeparator; if (separator == null) { separator = ""; } final StringBuilder sb = new StringBuilder(); for (final Iterator<?> iter = theCollection.iterator(); iter.hasNext();) { final String element = String.valueOf(iter.next()); sb.append(element); if (iter.hasNext()) { sb.append(separator); } } return sb.toString(); }
From source file:ar.com.qbe.siniestros.model.utils.MimeMagic.Magic.java
/** * print a magic match//from w ww . j av a 2s .c o m * * @param stream DOCUMENT ME! * @param matcher DOCUMENT ME! * @param spacing DOCUMENT ME! */ private static void printMagicMatcher(PrintStream stream, MagicMatcher matcher, String spacing) { stream.println(spacing + "name: " + matcher.getMatch().getDescription()); stream.println(spacing + "children: "); Collection matchers = matcher.getSubMatchers(); Iterator i = matchers.iterator(); while (i.hasNext()) { printMagicMatcher(stream, (MagicMatcher) i.next(), spacing + " "); } }
From source file:de.innovationgate.webgate.api.WGDocumentListCache.java
public static WGDocumentListCache buildFromDocuments(Collection<? extends WGDocument> col) { WGDocumentListCache cache = new WGDocumentListCache(); if (col != null) { Iterator<? extends WGDocument> docs = col.iterator(); while (docs.hasNext()) { WGDocument doc = docs.next(); cache._keys.add(doc.getDocumentKeyObj()); }/*from w ww .j a v a 2s . c o m*/ } cache.setComplete(true); cache.setReachedEnd(true); return cache; }
From source file:org.fcrepo.integration.connector.file.AbstractFedoraFileSystemConnectorIT.java
protected static void cleanUpJsonFilesFiles(final File directory) { final WildcardFileFilter filter = new WildcardFileFilter("*.modeshape.json"); final Collection<File> files = FileUtils.listFiles(directory, filter, TrueFileFilter.INSTANCE); final Iterator<File> iterator = files.iterator(); // Clean up files persisted in previous runs while (iterator.hasNext()) { final File f = iterator.next(); final String path = f.getAbsolutePath(); try {/* www .jav a2 s. c o m*/ Files.deleteIfExists(Paths.get(path)); } catch (final IOException e) { logger.error("Error in clean up", e); fail("Unable to delete work files from a previous test run. File=" + path); } } }