List of usage examples for java.util Collection iterator
Iterator<E> iterator();
From source file:com.esofthead.mycollab.vaadin.resources.StreamDownloadResourceUtil.java
public static String getDownloadFileName(Collection<Resource> lstRes) { if (CollectionUtils.isEmpty(lstRes)) { throw new UserInvalidInputException("No selected file to download"); } else if (lstRes.size() == 1) { Resource resource = lstRes.iterator().next(); return (resource instanceof Folder) ? resource + ".zip" : resource.getName(); } else {/*w w w . j a v a 2 s . co m*/ return "out.zip"; } }
From source file:ch.admin.suis.msghandler.common.MessageType.java
/** * Formats a collection of message types. * * @param types the collection of message types * @return A concatenated string of message types *//*from ww w.j a v a 2s . c o m*/ public static String collectionToString(Collection<MessageType> types) { final StringBuilder typeResult = new StringBuilder(); if (null != types) { for (Iterator<MessageType> i = types.iterator(); i.hasNext();) { typeResult.append(i.next().toString()); if (i.hasNext()) { typeResult.append(", "); } } } return typeResult.toString(); }
From source file:gaffer.rest.service.SimpleGraphConfigurationService.java
private static void keepPublicConcreteClasses(final Collection<Class> classes) { if (null != classes) { final Iterator<Class> itr = classes.iterator(); while (itr.hasNext()) { final Class clazz = itr.next(); if (null != clazz) { final int modifiers = clazz.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) { itr.remove();/*from w w w . ja v a2s . c o m*/ } } } } }
From source file:apm.common.utils.Collections3.java
/** * ?Collectioncollectionnull./* www . j a va2 s. c o m*/ */ public static <T> T getFirst(Collection<T> collection) { if (isEmpty(collection)) { return null; } return collection.iterator().next(); }
From source file:net.sourceforge.jcctray.utils.ObjectPersister.java
private static void saveHosts(Writer writer, Collection hosts) throws IOException { writer.write(" <hosts>\n"); for (Iterator iterator = hosts.iterator(); iterator.hasNext();) { Host host = (Host) iterator.next(); writer.write(" <host"); writer.write(" cruiseClass=\"" + escape(host.getCruiseClass()) + "\""); writer.write(" hostName=\"" + escape(host.getHostName()) + "\""); writer.write(" hostString=\"" + escape(host.getHostString()) + "\""); if (!StringUtils.isEmptyOrNull(host.getUsername())) { writer.write(" username=\"" + escape(host.getUsername()) + "\""); }/* www .j ava2 s . c o m*/ if (!StringUtils.isEmptyOrNull(host.getPassword())) { writer.write(" password=\"" + escape(host.getPassword()) + "\""); } writer.write(">\n"); saveProjects(writer, host.getConfiguredProjects()); writer.write(" </host>\n"); } writer.write(" </hosts>\n"); }
From source file:Main.java
/** * /*from ww w. java 2 s . co m*/ * @param collection * @return int[] */ public static int[] toIntArray(final Collection<Integer> collection) { final int[] array = new int[collection == null ? 0 : collection.size()]; if (collection != null) { int i = 0; for (Iterator<Integer> iterator = collection.iterator(); iterator.hasNext();) { array[i++] = iterator.next().intValue(); } } return array; }
From source file:Main.java
/** * Convenience method to return a Collection as a delimited (e.g. CSV) * String. E.g. useful for toString() implementations. * * @param coll Collection to display// w w w . j a v a 2s.c o m * @param delim delimiter to use (probably a ",") * @param prefix string to start each element with * @param suffix string to end each element with */ public static String tooDelimitedString(final Collection coll, final String delim, final String prefix, final String suffix) { if (coll == null) { return ""; } final StringBuilder sb = new StringBuilder(); Iterator it = coll.iterator(); int i = 0; while (it.hasNext()) { if (i > 0) { sb.append(delim); } sb.append(prefix).append(it.next()).append(suffix); i++; } return sb.toString(); }
From source file:net.sourceforge.jcctray.utils.ObjectPersister.java
private static void saveProjects(Writer writer, Collection projects) throws IOException { writer.write(" <projects>\n"); for (Iterator iterator2 = projects.iterator(); iterator2.hasNext();) { DashBoardProject project = (DashBoardProject) iterator2.next(); writer.write(" <project"); writer.write(" enabled=\"" + project.isEnabled() + "\""); writer.write(" name=\"" + project.getName() + "\""); writer.write("/>\n"); }//from w w w . j a v a 2 s. c om writer.write(" </projects>\n"); }
From source file:org.shept.util.BeanUtilsExtended.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private static boolean isInstanceVisited(Collection coll, Object value) throws Exception { for (Iterator<?> it = coll.iterator(); it.hasNext();) { Object v = it.next();/*from ww w.ja v a 2 s .c om*/ if (v.equals(value)) { return true; } } // sometimes ConcurrentModificationExceptions here coll.add(value); return false; }
@Atomic public static InfoCurriculum run(Integer executionDegreeCode, String curricularCourseCode, String stringExecutionYear) throws FenixServiceException { check(RolePredicates.COORDINATOR_PREDICATE); InfoCurriculum infoCurriculum = null; if (curricularCourseCode == null) { throw new FenixServiceException("nullCurricularCourse"); }// w w w . java2 s. c om if (stringExecutionYear == null || stringExecutionYear.length() == 0) { throw new FenixServiceException("nullExecutionYearName"); } CurricularCourse curricularCourse = (CurricularCourse) FenixFramework.getDomainObject(curricularCourseCode); if (curricularCourse == null) { throw new NonExistingServiceException("noCurricularCourse"); } final ExecutionYear executionYear = ExecutionYear.readExecutionYearByName(stringExecutionYear); if (executionYear == null) { throw new NonExistingServiceException("noExecutionYear"); } Curriculum curriculumExecutionYear = curricularCourse .findLatestCurriculumModifiedBefore(executionYear.getEndDate()); if (curriculumExecutionYear != null) { List allCurricularCourseScopes = new ArrayList(); List allExecutionCourses = new ArrayList(); Collection executionPeriods = executionYear.getExecutionPeriodsSet(); Iterator iterExecutionPeriods = executionPeriods.iterator(); while (iterExecutionPeriods.hasNext()) { ExecutionSemester executionSemester = (ExecutionSemester) iterExecutionPeriods.next(); Set<CurricularCourseScope> curricularCourseScopes = curricularCourse .findCurricularCourseScopesIntersectingPeriod(executionSemester.getBeginDate(), executionSemester.getEndDate()); if (curricularCourseScopes != null) { List disjunctionCurricularCourseScopes = (List) CollectionUtils .disjunction(allCurricularCourseScopes, curricularCourseScopes); List intersectionCurricularCourseScopes = (List) CollectionUtils .intersection(allCurricularCourseScopes, curricularCourseScopes); allCurricularCourseScopes = (List) CollectionUtils.union(disjunctionCurricularCourseScopes, intersectionCurricularCourseScopes); } List associatedExecutionCourses = new ArrayList(); Collection<ExecutionCourse> executionCourses = curricularCourse.getAssociatedExecutionCoursesSet(); for (ExecutionCourse executionCourse : executionCourses) { if (executionCourse.getExecutionPeriod().equals(executionSemester)) { associatedExecutionCourses.add(executionCourse); } } if (associatedExecutionCourses != null) { allExecutionCourses.addAll(associatedExecutionCourses); } } infoCurriculum = createInfoCurriculum(curriculumExecutionYear, allCurricularCourseScopes, allExecutionCourses); } return infoCurriculum; }