List of usage examples for java.util List contains
boolean contains(Object o);
From source file:com.wrmsr.wava.transform.Transforms.java
public static com.wrmsr.wava.core.unit.Function eliminateUnreferencedLocals( com.wrmsr.wava.core.unit.Function function) { LocalAnalysis.Entry la = LocalAnalysis.analyze(function.getBody()).get(function.getBody()); List<Index> indices = new ArrayList<>(Sets.union(la.getLocalGets(), la.getLocalPuts())); Collections.sort(indices);//from w w w. j a v a 2s . com Locals locals = Locals .of(function.getLocals().getList().stream().filter(l -> indices.contains(l.getIndex())) .map(l -> ImmutablePair.of(l.getName(), l.getType())).collect(toImmutableList())); Map<Index, Index> indexMap = enumerate(indices.stream()) .collect(toImmutableMap(i -> i.getItem(), i -> Index.of(i.getIndex()))); return new com.wrmsr.wava.core.unit.Function(function.getName(), function.getResult(), function.getArgCount(), locals, remapLocals(function.getBody(), indexMap)); }
From source file:com.company.project.core.connector.JSONHelper.java
/** * This method would create a string consisting of a JSON document with all * the necessary elements set from the HttpServletRequest request. * //w w w .j av a2 s .c o m * @param request * The HttpServletRequest * @return the string containing the JSON document. * @throws Exception * If there is any error processing the request. */ public static String createJSONString(HttpServletRequest request, String controller) throws Exception { JSONObject obj = new JSONObject(); try { Field[] allFields = Class .forName("com.microsoft.windowsazure.activedirectory.sdk.graph.models." + controller) .getDeclaredFields(); String[] allFieldStr = new String[allFields.length]; for (int i = 0; i < allFields.length; i++) { allFieldStr[i] = allFields[i].getName(); } List<String> allFieldStringList = Arrays.asList(allFieldStr); Enumeration<String> fields = request.getParameterNames(); while (fields.hasMoreElements()) { String fieldName = fields.nextElement(); String param = request.getParameter(fieldName); if (allFieldStringList.contains(fieldName)) { if (param == null || param.length() == 0) { if (!fieldName.equalsIgnoreCase("password")) { obj.put(fieldName, JSONObject.NULL); } } else { if (fieldName.equalsIgnoreCase("password")) { obj.put("passwordProfile", new JSONObject("{\"password\": \"" + param + "\"}")); } else { obj.put(fieldName, param); } } } } } catch (JSONException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return obj.toString(); }
From source file:de.micromata.genome.util.runtime.ClassUtils.java
/** * Set all String field to empty on current class. * * @param object the object// w ww . ja va2 s . c o m * @param exceptClass the except class * @throws IllegalArgumentException the illegal argument exception * @throws IllegalAccessException the illegal access exception */ // CHECKSTYLE.OFF com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck Trivial code. public static void fillDefaultEmptyFieldsIfEmpty(Object object, Class<?>... exceptClass) // NOSONAR "Methods should not be too complex" trivial throws IllegalArgumentException, IllegalAccessException { Class<?> currentClazz = object.getClass(); List exClazzes = Arrays.asList(exceptClass); while (currentClazz.getSuperclass() != null) { if (exClazzes.contains(currentClazz) == false) { Field[] fields = currentClazz.getDeclaredFields(); for (Field field : fields) { if (String.class.equals(field.getType())) { field.setAccessible(true); if (field.get(object) == null) { field.set(object, ""); } } if (Integer.class.equals(field.getType())) { field.setAccessible(true); if (field.get(object) == null) { field.set(object, 0); } } if (BigDecimal.class.equals(field.getType())) { field.setAccessible(true); if (field.get(object) == null) { field.set(object, BigDecimal.ZERO); } } if (Date.class.equals(field.getType())) { field.setAccessible(true); if (field.get(object) == null) { field.set(object, new Date()); } } } } currentClazz = currentClazz.getSuperclass(); } }
From source file:com.none.tom.simplerssreader.feed.CurrentFeed.java
public static List<String> getCategories() { final List<String> allCategories = new ArrayList<>(); for (final SyndEntry entry : sCurrentFeed.getEntries()) { for (final SyndCategory category : entry.getCategories()) { final String name = category.getName(); if (!TextUtils.isEmpty(name) && !allCategories.contains(name)) { allCategories.add(name); }//from w w w . j a v a2 s . co m } } Collections.sort(allCategories); return allCategories; }
From source file:com.open.cas.shiro.util.CollectionsUtils.java
/** * a-bList./*w ww . jav a2s . c o m*/ */ public static <T> List<T> subtract(final Collection<T> a, final Collection<T> b) { List<T> list = new ArrayList<T>(a); for (T element : b) { if (list.contains(element)) { list.remove(element); } } return list; }
From source file:Main.java
/** * Populates the import style pattern map from give comma delimited string *//*from w w w. ja va 2s . c om*/ public static void addImportStylePatterns(Map<String, Object> patterns, String str) { if (str == null || "".equals(str.trim())) { return; } String[] items = str.split(" "); for (String item : items) { String qualifiedNamespace = item.substring(0, item.lastIndexOf('.')).trim(); String name = item.substring(item.lastIndexOf('.') + 1).trim(); Object object = patterns.get(qualifiedNamespace); if (object == null) { if (STAR.equals(name)) { patterns.put(qualifiedNamespace, STAR); } else { // create a new list and add it List<String> list = new ArrayList<String>(); list.add(name); patterns.put(qualifiedNamespace, list); } } else if (name.equals(STAR)) { // if its a STAR now add it anyway, we don't care if it was a STAR or a List before patterns.put(qualifiedNamespace, STAR); } else { // its a list so add it if it doesn't already exist List list = (List) object; if (!list.contains(name)) { list.add(name); } } } }
From source file:com.dm.estore.common.utils.FileUtils.java
public static void createFilesFromClasspath(final String destFoder, List<String> resources, List<String> resourcesToIgnoreIfExist) { // create all required parent folders FileUtils.ensurePathExist(destFoder); for (String fileName : resources) { final String configFileName = destFoder + File.separator + fileName; FileUtils.ensurePathExist(configFileName); final File configFile = new File(configFileName); if (!resourcesToIgnoreIfExist.contains(fileName) || !configFile.exists()) { // re-create default configuration file if (configFile.exists()) { configFile.delete();//from w ww . jav a 2 s . c o m } final String classPath = File.separator + fileName; try { final InputStream fileStream = Cfg.class.getResourceAsStream(classPath); FileUtils.saveFile(fileStream, configFileName); } catch (Exception e) { LOG.error("Unable to create default configuration.", e); } } } }
From source file:com.github.dactiv.fear.commons.Apis.java
/** * {@link ValueEnum} ?? class ???/* w ww . j av a 2s . c o m*/ * * @param enumClass class * @param ignore ? * * @return key value ? Map ? */ public static List<Map<String, Object>> getConfigList(Class<? extends Enum<? extends ValueEnum<?>>> enumClass, List ignore) { List<Map<String, Object>> result = new ArrayList<>(); Enum<? extends ValueEnum<?>>[] values = enumClass.getEnumConstants(); for (Enum<? extends ValueEnum<?>> o : values) { ValueEnum<?> ve = (ValueEnum<?>) o; Object value = ve.getValue(); if (ignore != null && !ignore.contains(value)) { Map<String, Object> dictionary = new LinkedHashMap<>(); dictionary.put(DEFAULT_VALUE_NAME, value); dictionary.put(DEFAULT_KEY_NAME, ve.getName()); result.add(dictionary); } } return result; }
From source file:com.struts2ext.json.JSONUtil.java
/** * Recursive method to visit all the interfaces of a class (and its * superclasses and super-interfaces) if they haven't already been visited. * <p/>/*from w ww .j a v a2s .c o m*/ * Always visits itself if it hasn't already been visited * * @param thisClass * the current class to visit (if not already done so) * @param classesVisited * classes already visited * @param visitor * this vistor is called for each class/interface encountered * @return true if recursion can continue, false if it should be aborted */ private static boolean visitUniqueInterfaces(Class<?> thisClass, ClassVisitor visitor, List<Class<?>> classesVisited) { boolean okayToContinue = true; if (!classesVisited.contains(thisClass)) { classesVisited.add(thisClass); okayToContinue = visitor.visit(thisClass); if (okayToContinue) { Class<?>[] interfaces = thisClass.getInterfaces(); int index = 0; while ((index < interfaces.length) && (okayToContinue)) { okayToContinue = visitUniqueInterfaces(interfaces[index++], visitor, classesVisited); } if (okayToContinue) { Class<?> superClass = thisClass.getSuperclass(); if ((superClass != null) && (!Object.class.equals(superClass))) { okayToContinue = visitUniqueInterfaces(superClass, visitor, classesVisited); } } } } return okayToContinue; }
From source file:Alias2.java
public static void verifyAtLeast(List output, List expected) { verifyLength(output.size(), expected.size(), Test.AT_LEAST); if (!output.containsAll(expected)) { ListIterator it = expected.listIterator(); while (output.contains(it.next())) { }//from ww w . j a va2 s. co m throw new SimpleTestException("expected: <" + it.previous().toString() + ">"); } }