List of usage examples for java.util Collection iterator
Iterator<E> iterator();
From source file:Main.java
public static <E extends Comparable<E>> E getSmallest(final Collection<? extends E> c) { if (c.isEmpty()) { throw new NoSuchElementException(); }/*from w w w.j a v a 2 s . c om*/ if ((c instanceof List) && (c instanceof RandomAccess)) { return getSmallest((List<? extends E>) c); } final Iterator<? extends E> iterator = c.iterator(); E result = iterator.next(); E element; while (iterator.hasNext()) { element = iterator.next(); if (element.compareTo(result) < 0) { result = element; } } return result; }
From source file:Main.java
public static <E extends Comparable<E>> E getGreatest(final Collection<? extends E> c) { if (c.isEmpty()) { throw new NoSuchElementException(); }/*from ww w.j a v a 2 s . co m*/ if ((c instanceof List) && (c instanceof RandomAccess)) { return getGreatest((List<? extends E>) c); } final Iterator<? extends E> iterator = c.iterator(); E result = iterator.next(); E element; while (iterator.hasNext()) { element = iterator.next(); if (element.compareTo(result) > 0) { result = element; } } return result; }
From source file:com.gargoylesoftware.htmlunit.util.Cookie.java
/** * Converts the specified collection of cookies into an collection of HttpClient cookies. * @param cookies the cookies to be converted * @return the specified cookies, as HttpClient cookies *//*w w w . j a v a 2 s .c o m*/ public static List<org.apache.http.cookie.Cookie> toHttpClient(final Collection<Cookie> cookies) { final ArrayList<org.apache.http.cookie.Cookie> array = new ArrayList<>(cookies.size()); final Iterator<Cookie> it = cookies.iterator(); while (it.hasNext()) { array.add(it.next().toHttpClient()); } return array; }
From source file:com.doculibre.constellio.plugins.PluginFactory.java
public static boolean isValidPlugin(String name) { boolean validPlugin; File pluginsDir = getPluginsDir(); File pluginDir = new File(pluginsDir, name); if (!pluginDir.exists() || pluginDir.isFile()) { validPlugin = false;/*from w ww.ja v a 2s. co m*/ } else { Collection<File> pluginJarFiles = FileUtils.listFiles(pluginDir, new String[] { "jar" }, false); // Accept only one root dir jar File pluginJarFile = pluginJarFiles.isEmpty() ? null : pluginJarFiles.iterator().next(); if (pluginJarFile != null) { validPlugin = true; } else { validPlugin = false; } } return validPlugin; }
From source file:com.splout.db.common.SploutConfiguration.java
/** * Get the Splout configuration using double configuration: defaults + custom *///from w w w . ja v a 2 s. co m public static SploutConfiguration get(String rootDir) { SploutConfiguration properties = new SploutConfiguration(); PropertiesConfiguration config = load(rootDir, SPLOUT_PROPERTIES, false); if (config != null) { properties.addConfiguration(config); } config = load(rootDir, SPLOUT_PROPERTIES + ".default", true); properties.addConfiguration(config); // The following lines replaces the default "localhost" by the local IP for convenience: String myIp = "localhost"; try { Collection<InetAddress> iNetAddresses = GetIPAddresses.getAllLocalIPs(); // but only if there is Internet connectivity! if (iNetAddresses != null) { Iterator<InetAddress> it = iNetAddresses.iterator(); if (it.hasNext()) { InetAddress address = it.next(); if (address.getHostAddress() != null) { myIp = address.getHostAddress(); } } } } catch (IOException e) { throw new RuntimeException(e); } if (config.getString(QNodeProperties.HOST) != null && config.getString(QNodeProperties.HOST).equals("localhost")) { config.setProperty(QNodeProperties.HOST, myIp); } if (config.getString(DNodeProperties.HOST) != null && config.getString(DNodeProperties.HOST).equals("localhost")) { config.setProperty(DNodeProperties.HOST, myIp); } return properties; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToSharedAppFeedObj.java
public static JSONObject json(Collection<Contact> contacts, String feedName, String packageName) { JSONObject obj = new JSONObject(); try {// w ww . j a va 2 s .c o m obj.put("packageName", packageName); obj.put("sharedFeedName", feedName); JSONArray participants = new JSONArray(); Iterator<Contact> it = contacts.iterator(); while (it.hasNext()) { String localId = "@l" + it.next().id; participants.put(participants.length(), localId); } // Need to add ourself to participants participants.put(participants.length(), "@l" + Contact.MY_ID); obj.put("participants", participants); } catch (JSONException e) { } return obj; }
From source file:com.appglu.impl.util.StringUtils.java
public static String collectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix) {/*from w ww. j a v a 2 s .c o m*/ if (CollectionUtils.isEmpty(coll)) { return ""; } StringBuilder sb = new StringBuilder(); Iterator<?> it = coll.iterator(); while (it.hasNext()) { sb.append(prefix).append(it.next()).append(suffix); if (it.hasNext()) { sb.append(delim); } } return sb.toString(); }
From source file:com.bigdata.dastor.tools.SSTableExport.java
private static String serializeColumns(Collection<IColumn> cols, AbstractType comp) { StringBuilder json = new StringBuilder("["); Iterator<IColumn> iter = cols.iterator(); while (iter.hasNext()) { json.append("["); IColumn column = iter.next();// w w w . j a v a2 s. co m json.append(quote(bytesToHex(column.name()))); json.append(", "); json.append(quote(bytesToHex(column.value()))); json.append(", "); json.append(column.timestamp()); json.append(", "); json.append(column.isMarkedForDelete()); json.append("]"); if (iter.hasNext()) json.append(", "); } json.append("]"); return json.toString(); }
From source file:Main.java
public static <E> E getSmallest(final Comparator<? super E> comparator, final Collection<? extends E> c) { if (c.isEmpty()) { throw new NoSuchElementException(); }//from ww w. j ava2 s . c o m if ((c instanceof List) && (c instanceof RandomAccess)) { return getSmallest(comparator, (List<? extends E>) c); } final Iterator<? extends E> iterator = c.iterator(); E result = iterator.next(); E element; while (iterator.hasNext()) { element = iterator.next(); if (comparator.compare(element, result) < 0) { result = element; } } return result; }
From source file:Main.java
public static <E> E getGreatest(final Comparator<? super E> comparator, final Collection<? extends E> c) { if (c.isEmpty()) { throw new NoSuchElementException(); }/* w w w. ja v a 2 s . c o m*/ if ((c instanceof List) && (c instanceof RandomAccess)) { return getGreatest(comparator, (List<? extends E>) c); } final Iterator<? extends E> iterator = c.iterator(); E result = iterator.next(); E element; while (iterator.hasNext()) { element = iterator.next(); if (comparator.compare(element, result) > 0) { result = element; } } return result; }