List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:Main.java
/** * Sorts objects in the given collection into different types by Class. * @param <E> the element type/*from ww w .j a v a 2 s . c o m*/ * @param objects a Collection of objects * @param inherit if true, objects are put into all their class's superclasses as well, except * Object - the original Collection can be used in that case * @return a Map from Class to List of objects in that class */ public static <E> Map<Class<?>, List<E>> groupByClass(Collection<E> objects, boolean inherit) { Map<Class<?>, List<E>> retval = new HashMap<Class<?>, List<E>>(); for (E o : objects) { Class<?> c = o.getClass(); if (inherit) { Set<Class<?>> done = new HashSet<Class<?>>(); done.add(Object.class); Stack<Class<?>> todo = new Stack<Class<?>>(); todo.push(c); while (!todo.empty()) { c = todo.pop(); if ((c != null) && !done.contains(c)) { done.add(c); List<E> l = retval.get(c); if (l == null) { l = new ArrayList<E>(); retval.put(c, l); } l.add(o); todo.push(c.getSuperclass()); Class<?>[] classes = c.getInterfaces(); for (int i = 0; i < classes.length; i++) { todo.push(classes[i]); } } } } else { List<E> l = retval.get(c); if (l == null) { l = new ArrayList<E>(); retval.put(c, l); } l.add(o); } } return retval; }
From source file:com.flexive.cmis.spi.SPIUtils.java
/** * Return true if the given tree node should be treated as a folder, even * though it is (in flexive terms) a document. * * @param folderTypeIds the folder type IDs (as returned by {@link SPIUtils#getFolderTypeIds()}) * @param context the connection context * @param child the tree node to be examined * @return true if the given tree node should be treated as a folder *//*from w ww . ja v a 2 s. c o m*/ static boolean treatDocumentAsFolder(Set<Long> folderTypeIds, FlexiveConnection.Context context, FxTreeNode child) { return folderTypeIds.contains(child.getReferenceTypeId()) // check if documents-as-folders connection parameter is set || context.getConnectionConfig().isDocumentsAsFolders() && child.getDirectChildCount() > 0; }
From source file:BackupRestoreTest.java
private static void checkCollectionIn(final Collection<String> repoPatern, final List<String> contentRepo) { Set<String> contentRepoSet = new HashSet<>(contentRepo); for (String s : repoPatern) { Assert.assertTrue("Not found element: '" + s + "'", contentRepoSet.contains(s)); }// w ww . j a v a 2 s . co m }
From source file:net.solarnetwork.node.dao.jdbc.derby.DerbyCustomFunctionsInitializer.java
private static void registerBitwiseFunctions(final Connection con, String schema) throws SQLException { DatabaseMetaData dbMeta = con.getMetaData(); ResultSet rs = dbMeta.getFunctions(null, null, null); Set<String> functionNames = new HashSet<String>(Arrays.asList(BITWISE_AND, BITWISE_OR)); while (rs.next()) { String schemaName = rs.getString(2); String functionName = rs.getString(3).toUpperCase(); if (schema.equalsIgnoreCase(schemaName) && functionNames.contains(functionName)) { functionNames.remove(functionName); }/*from w ww. j a v a 2s . c om*/ } // at this point, functionNames contains the functions we need to create if (functionNames.size() > 0) { final String sqlTemplate = "CREATE FUNCTION %s.%s( parm1 INTEGER, param2 INTEGER ) " + "RETURNS INTEGER LANGUAGE JAVA DETERMINISTIC PARAMETER STYLE JAVA NO SQL " + "EXTERNAL NAME 'net.solarnetwork.node.dao.jdbc.derby.ext.DerbyBitwiseFunctions.%s'"; if (functionNames.contains(BITWISE_AND)) { final String sql = String.format(sqlTemplate, schema, BITWISE_AND, "bitwiseAnd"); con.createStatement().execute(sql); } if (functionNames.contains(BITWISE_OR)) { final String sql = String.format(sqlTemplate, schema, BITWISE_OR, "bitwiseOr"); con.createStatement().execute(sql); } } }
From source file:com.netflix.config.util.ConfigurationUtils.java
public static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl, Set<String> loaded, String... nextLoadKeys) throws FileNotFoundException { if (loaded.contains(startingUrl.toExternalForm())) { logger.warn(startingUrl + " is already loaded"); return null; }// w w w . j a va 2 s . c om PropertiesConfiguration propConfig = null; try { propConfig = new OverridingPropertiesConfiguration(startingUrl); logger.info("Loaded properties file " + startingUrl); } catch (ConfigurationException e) { Throwable cause = e.getCause(); if (cause instanceof FileNotFoundException) { throw (FileNotFoundException) cause; } else { throw new RuntimeException(e); } } if (nextLoadKeys == null) { return propConfig; } String urlString = startingUrl.toExternalForm(); String base = urlString.substring(0, urlString.lastIndexOf("/")); loaded.add(startingUrl.toString()); loadFromPropertiesFile(propConfig, base, loaded, nextLoadKeys); return propConfig; }
From source file:com.moz.fiji.schema.mapreduce.DistributedCacheJars.java
/** * Takes a list of paths and returns a list of paths with unique filenames. * * @param jarList A list of jars to de-dupe. * @return A de-duplicated list of jars. *//*w ww.j a v a2 s.co m*/ public static List<String> deDuplicateJarNames(List<String> jarList) { Set<String> jarNames = new HashSet<String>(); List<String> jarPaths = new ArrayList<String>(); for (String jar : jarList) { Path path = new Path(jar); String jarName = path.getName(); if (!jarNames.contains(jarName)) { jarNames.add(jarName); jarPaths.add(jar); } else { LOG.warn("Skipping jar at " + jar + " because " + jarName + " already added."); } } return jarPaths; }
From source file:gov.nih.nci.caintegrator.common.AnnotationUtil.java
/** * @param abstractAnnotationValues abstractAnnotationValues * @param dataValues the values from the current upload file * @param filterList the list of display string to filter * @return set of distinct available values *//*w ww . j av a2 s. c o m*/ public static Set<String> getAdditionalValue(Collection<AbstractAnnotationValue> abstractAnnotationValues, List<String> dataValues, Set<String> filterList) { Set<String> results = new HashSet<String>(); for (String dataValue : dataValues) { if (!StringUtils.isBlank(dataValue) && !filterList.contains(dataValue)) { if (NumberUtils.isNumber(dataValue)) { dataValue = NumericUtil.formatDisplay(dataValue); } results.add(dataValue); } } for (AbstractAnnotationValue abstractAnnotationValue : abstractAnnotationValues) { String displayString = abstractAnnotationValue.toString(); if (StringUtils.isNotBlank(displayString) && !filterList.contains(displayString)) { results.add(displayString); } } return results; }
From source file:de.tu_berlin.dima.oligos.Oligos.java
public static ColumnProfiler<?> getProfilerOracle(final String schema, final String table, final String column, final TypeInfo type, final JdbcConnector jdbcConnector, final MetaConnector metaConnector) throws SQLException { ColumnProfiler<?> profiler = null; String typeName = type.getTypeName().toLowerCase(); boolean isEnum = metaConnector.isEnumerated(schema, table, column); if (typeName.equals("number")) { if (type.getScale() == 0) { Parser<BigInteger> p = new BigIntegerParser(); Operator<BigInteger> op = new BigIntegerOperator(); ColumnConnector<BigInteger> connector = new OracleColumnConnector<>(jdbcConnector, schema, table, column, p);//from w w w .ja va2 s . c o m profiler = new ColumnProfiler<BigInteger>(schema, table, column, type, isEnum, connector, op, p); } else { Parser<BigDecimal> p = new BigDecimalParser(); Operator<BigDecimal> op = new BigDecimalOperator(); ColumnConnector<BigDecimal> connector = new OracleColumnConnector<>(jdbcConnector, schema, table, column, p); profiler = new ColumnProfiler<BigDecimal>(schema, table, column, type, isEnum, connector, op, p); } } else if (typeName.equals("date")) { Parser<Date> p = new DateParser(); Operator<Date> op = new DateOperator(); ColumnConnector<Date> connector = new OracleColumnConnector<>(jdbcConnector, schema, table, column, p); profiler = new ColumnProfiler<Date>(schema, table, column, type, isEnum, connector, op, p); } else if (typeName.equals("time")) { Parser<Time> p = new TimeParser(); Operator<Time> op = new TimeOperator(); ColumnConnector<Time> connector = new OracleColumnConnector<>(jdbcConnector, schema, table, column, p); profiler = new ColumnProfiler<Time>(schema, table, column, type, isEnum, connector, op, p); } else if (typeName.equals("timestamp")) { Parser<Timestamp> p = new TimestampParser(); Operator<Timestamp> op = new TimestampOperator(); ColumnConnector<Timestamp> connector = new OracleColumnConnector<>(jdbcConnector, schema, table, column, p); profiler = new ColumnProfiler<Timestamp>(schema, table, column, type, isEnum, connector, op, p); } // treat char as strings, due to Oracle's conversion to numbers no trimming is allowed else if (typeName.equals("varchar2") || typeName.equals("nvarchar2") || typeName.equals("char") || typeName.equals("nchar") || typeName.equals("varchar") || typeName.equals("nvarchar")) { if (type.getLength() == 1) { Parser<Character> p = new CharParser(); Operator<Character> op = new CharOperator(); ColumnConnector<Character> connector = new OracleColumnConnector<>(jdbcConnector, schema, table, column, p); profiler = new ColumnProfiler<Character>(schema, table, column, type, isEnum, connector, op, p); } else { Parser<String> p = new StringParser(); Operator<String> op = new StringOperator(); ColumnConnector<String> connector = new OracleColumnConnector<>(jdbcConnector, schema, table, column, p); Set<Constraint> constraints = connector.getConstraints(); if (constraints.contains(Constraint.UNIQUE) || constraints.contains(Constraint.PRIMARY_KEY)) throw new UnsupportedTypeException(typeName, Constraint.UNIQUE); profiler = new PseudoColumnProfiler(schema, table, column, type, isEnum, connector); } } else { LOGGER.fatal("unsupported column type: " + typeName); } return profiler; }
From source file:com.bstek.dorado.core.io.ResourceUtils.java
/** * ??????/*from w ww. j a v a 2s .co m*/ * * @param resourceLocations * ? * @return ???? * @throws IOException */ public static Set<Resource> getResourceSet(String[] resourceLocations) throws IOException { Context context = Context.getCurrent(); Set<Resource> resourceSet = new LinkedHashSet<Resource>(); for (String resourceLocation : resourceLocations) { Resource[] resourceArray = context.getResources(resourceLocation); for (Resource resource : resourceArray) { if (!resourceSet.contains(resource)) { resourceSet.add(resource); } } } return resourceSet; }
From source file:com.nexmo.client.verify.endpoints.VerifyEndpointTest.java
private static void assertParamMissing(List<NameValuePair> params, String key) { Set<String> keys = new HashSet<>(); for (NameValuePair pair : params) { keys.add(pair.getName());/*from w ww .jav a 2 s . c o m*/ } assertFalse("" + params + " should not contain " + key, keys.contains(key)); }