List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:Main.java
private static Set<Method> findMethodsCompatibleWith(boolean staticMethod, Set<Method> methods, String methodName, Class<?>[] argTypes) { final Set<Method> list = new HashSet<Method>(methods); for (final Iterator<Method> it = list.iterator(); it.hasNext();) { final Method method = it.next(); if (!methodName.equals(method.getName())) { it.remove();//from w w w . j a v a2s. c o m continue; } if (argTypes.length != method.getParameterTypes().length) { it.remove(); continue; } if (Modifier.isAbstract(method.getModifiers()) || Modifier.isStatic(method.getModifiers()) != staticMethod) { it.remove(); continue; } if (!isMethodArgCompatible(method, argTypes)) { it.remove(); continue; } } return list; }
From source file:mml.handler.json.Dialect.java
private static boolean compareObjects(JSONObject o1, JSONObject o2) { boolean res = true; Set<String> keys = o1.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext() && res) { String key = iter.next(); Object obj1 = o1.get(key); Object obj2 = o2.get(key); if (obj1 != null && obj2 != null && obj1.getClass().equals(obj2.getClass())) { if (obj1 instanceof String) res = obj1.equals(obj2); else if (obj1 instanceof Number) return obj1.equals(obj2); else if (obj1 instanceof JSONArray) res = compareArrays((JSONArray) obj1, (JSONArray) obj2); else if (obj1 instanceof JSONObject) res = compareObjects((JSONObject) obj1, (JSONObject) obj2); else if (obj1 instanceof Boolean) res = obj1.equals(obj2); else//from w ww. j a va2s . c o m res = false; } else res = false; } return res; }
From source file:Main.java
public static <T> Set<T> toImmutableSet(Set<T> set) { switch (set.size()) { case 0:/*from w w w. ja va 2s.co m*/ return Collections.emptySet(); case 1: return Collections.singleton(set.iterator().next()); default: return Collections.unmodifiableSet(set); } }
From source file:tv.icntv.log.crawl2.commons.HttpClientUtil.java
public static String getContentPost(String url, Map<String, String> params) throws IOException { HttpPost httpPost = new HttpPost(url); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); if (params != null) { Set set = params.keySet(); Iterator iterator = set.iterator(); while (iterator.hasNext()) { Object key = iterator.next(); Object value = params.get(key); formParams.add(new BasicNameValuePair(key.toString(), value.toString())); }//from w ww .j a va2 s . c o m } httpPost.setHeader(new BasicHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")); httpPost.setEntity(new UrlEncodedFormEntity(formParams, HTTP.UTF_8)); // execute CloseableHttpClient client = HttpClientHolder.getClient(); return EntityUtils.toString(client.execute(httpPost).getEntity(), "utf-8"); }
From source file:edu.cmu.sv.modelinference.common.Util.java
public static String getSupportedHandlersString(Set<? extends LogHandler<?>> supportedHandlers) { StringBuilder sb = new StringBuilder(); Iterator<? extends LogHandler<?>> logIter = supportedHandlers.iterator(); while (logIter.hasNext()) { sb.append(logIter.next().getHandlerName()); if (logIter.hasNext()) sb.append(" | "); }/*from w w w .j a v a 2 s .com*/ return sb.toString(); }
From source file:com.appnexus.opensdk.PBImplementation.java
private static void trimBuffer() { if (buffer.size() > PB_BUFFER_LIMIT) { Set<String> keys = buffer.keySet(); String key = keys.iterator().next(); buffer.remove(key);//from w w w. ja v a2 s . c o m } }
From source file:Main.java
/** * Returns a {@link Collection} containing the union of the given * {@link Collection}s./* w w w.ja v a2 s . c o m*/ * <p> * The cardinality of each element in the returned {@link Collection} will * be equal to the maximum of the cardinality of that element in the two * given {@link Collection}s. * * @see Collection#addAll */ public static Collection union(final Collection a, final Collection b) { ArrayList list = new ArrayList(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set elts = new HashSet(a); elts.addAll(b); Iterator it = elts.iterator(); while (it.hasNext()) { Object obj = it.next(); for (int i = 0, m = Math.max(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj); } } return list; }
From source file:com.hybridbpm.ui.component.chart.util.DiagrammeUtil.java
public static String[] getCategoriesNames(Set columnValues) { String[] categoriesNames = new String[columnValues.size()]; Iterator it = columnValues.iterator(); int i = 0;// ww w .jav a2 s. c om while (it.hasNext()) { categoriesNames[i] = it.next().toString(); i++; } return categoriesNames; }
From source file:com.sonicle.webtop.core.app.util.ClassHelper.java
public static Annotation getClassAnnotation(Class clazz, Class annotationClass) { if (clazz == null) return null; Set<Annotation> annotations = getClassAnnotations(clazz, annotationClass); return annotations.isEmpty() ? null : annotations.iterator().next(); }
From source file:Main.java
/** * Returns a {@link Collection} containing the exclusive disjunction * (symmetric difference) of the given {@link Collection}s. * <p>/*w w w . j a v a 2 s . c om*/ * The cardinality of each element <i>e</i> in the returned * {@link Collection} will be equal to * <tt>max(cardinality(<i>e</i>,<i>a</i>),cardinality(<i>e</i>,<i>b</i>)) - min(cardinality(<i>e</i>,<i>a</i>),cardinality(<i>e</i>,<i>b</i>))</tt>. * <p> * This is equivalent to * <tt>{@link #subtract subtract}({@link #union union(a,b)},{@link #intersection intersection(a,b)})</tt> * or * <tt>{@link #union union}({@link #subtract subtract(a,b)},{@link #subtract subtract(b,a)})</tt>. */ public static Collection disjunction(final Collection a, final Collection b) { ArrayList list = new ArrayList(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set elts = new HashSet(a); elts.addAll(b); Iterator it = elts.iterator(); while (it.hasNext()) { Object obj = it.next(); for (int i = 0, m = ((Math.max(getFreq(obj, mapa), getFreq(obj, mapb))) - (Math.min(getFreq(obj, mapa), getFreq(obj, mapb)))); i < m; i++) { list.add(obj); } } return list; }