List of usage examples for java.util Set size
int size();
From source file:com.jims.oauth2.common.utils.OAuthUtils.java
private static boolean isEmpty(Set<String> missingParams) { if (missingParams == null || missingParams.size() == 0) { return true; }//from www .jav a 2s.co m return false; }
From source file:edu.wpi.checksims.algorithm.similaritymatrix.SimilarityMatrix.java
/** * Generate a Similarity Matrix with archive submissions. * * The result is not a square matrix. Only the input submissions are on the X axis, but the Y axis contains both * input and archive submissions.//from ww w. j a v a2s . c o m * * @param inputSubmissions Submissions used to generate matrix * @param archiveSubmissions Archive submissions - only compared to input submissions, not to each other * @param results Results used to build matrix * @return Similarity matrix built from given results * @throws InternalAlgorithmError Thrown on missing results, or results containing a submission not in the input */ public static SimilarityMatrix generateMatrix(Set<Submission> inputSubmissions, Set<Submission> archiveSubmissions, Set<AlgorithmResults> results) throws InternalAlgorithmError { checkNotNull(inputSubmissions); checkNotNull(archiveSubmissions); checkNotNull(results); checkArgument(!inputSubmissions.isEmpty(), "Must provide at least 1 submission to build matrix from"); checkArgument(!results.isEmpty(), "Must provide at least 1 AlgorithmResults to build matrix from!"); Set<Submission> setOfBoth = new HashSet<>(); setOfBoth.addAll(inputSubmissions); setOfBoth.addAll(archiveSubmissions); checkArgument(setOfBoth.size() == (archiveSubmissions.size() + inputSubmissions.size()), "Some submissions were found in both archive and input submissions!"); // If there are no archive submissions, just generate using the other function if (archiveSubmissions.isEmpty()) { return generateMatrix(inputSubmissions, results); } List<Submission> xSubmissions = Ordering.natural().immutableSortedCopy(inputSubmissions); List<Submission> ySubmissions = new ArrayList<>(); ySubmissions.addAll(Ordering.natural().immutableSortedCopy(inputSubmissions)); ySubmissions.addAll(Ordering.natural().immutableSortedCopy(archiveSubmissions)); MatrixEntry[][] matrix = new MatrixEntry[xSubmissions.size()][ySubmissions.size()]; // Generate the matrix // First, handle identical submissions for (Submission xSub : xSubmissions) { // Get the X index int xIndex = xSubmissions.indexOf(xSub); int yIndex = ySubmissions.indexOf(xSub); matrix[xIndex][yIndex] = new MatrixEntry(xSub, xSub, xSub.getNumTokens()); } // Now iterate through all given algorithm results for (AlgorithmResults result : results) { int aXCoord = xSubmissions.indexOf(result.a); int bXCoord = xSubmissions.indexOf(result.b); if (aXCoord == -1 && bXCoord == -1) { throw new InternalAlgorithmError("Neither submission \"" + result.a.getName() + "\" nor \"" + result.b.getName() + "\" were found in input submissions!"); } if (aXCoord != -1) { int bYCoord = ySubmissions.indexOf(result.b); matrix[aXCoord][bYCoord] = new MatrixEntry(result.a, result.b, result.identicalTokensA); } if (bXCoord != -1) { int aYCoord = ySubmissions.indexOf(result.a); matrix[bXCoord][aYCoord] = new MatrixEntry(result.b, result.a, result.identicalTokensB); } } // Verification pass - ensure we built a matrix with no nulls for (int x = 0; x < xSubmissions.size(); x++) { for (int y = 0; y < ySubmissions.size(); y++) { if (matrix[x][y] == null) { throw new InternalAlgorithmError("Missing Algorithm Results for comparison of submissions \"" + xSubmissions.get(x).getName() + "\" and \"" + ySubmissions.get(y).getName() + "\""); } } } return new SimilarityMatrix(matrix, xSubmissions, ySubmissions, results); }
From source file:de.tudarmstadt.ukp.wikipedia.api.CategoryGraphManager.java
public static CategoryGraph getCategoryGraph(Wikipedia wiki, Set<Integer> pageIds, boolean serialize) throws WikiApiException { if (catGraphMap == null) { catGraphMap = new HashMap<String, CategoryGraph>(); }//w w w. jav a 2 s. c om String wikiID = wiki.getWikipediaId(); if (catGraphMap.containsKey(wikiID)) { return catGraphMap.get(wikiID); } String size = ""; if (pageIds != null) { size = new Integer(pageIds.size()).toString(); } CategoryGraph catGraph; if (serialize) { catGraph = tryToLoadCategoryGraph(wiki, wikiID, size); if (catGraph != null) { catGraphMap.put(wikiID, catGraph); return catGraph; } } // could not be loaded (= no serialized category graph was written so far) => create it if (pageIds != null) { catGraph = new CategoryGraph(wiki, pageIds); } else { catGraph = new CategoryGraph(wiki); } catGraphMap.put(wikiID, catGraph); if (serialize) { saveCategoryGraph(catGraph, wikiID, size); } return catGraph; }
From source file:edu.byu.nlp.data.app.AnnotationStream2Annotators.java
public static double[][][] aggregateAnnotatorParameterClusters(double[][][] annotatorParameters, int[] clusterAssignments) { // group clustered parameters Map<Integer, Set<double[][]>> clusterMap = Maps.newHashMap(); for (int i = 0; i < clusterAssignments.length; i++) { int clusterAssignment = clusterAssignments[i]; if (!clusterMap.containsKey(clusterAssignment)) { clusterMap.put(clusterAssignment, Sets.<double[][]>newIdentityHashSet()); }/*from ww w .java 2 s. c om*/ clusterMap.get(clusterAssignment).add(annotatorParameters[i]); } // aggregate clustered parameters List<double[][]> clusteredAnnotatorParameters = Lists.newArrayList(); for (Set<double[][]> cluster : clusterMap.values()) { double[][][] clusterTensor = cluster.toArray(new double[][][] {}); double[][] averagedConfusions = Matrices.sumOverFirst(clusterTensor); Matrices.divideToSelf(averagedConfusions, cluster.size()); clusteredAnnotatorParameters.add(averagedConfusions); } // re-assign confusions return clusteredAnnotatorParameters.toArray(new double[][][] {}); }
From source file:biz.netcentric.cq.tools.actool.helper.AccessControlUtils.java
/** Retrieves the {@link Privilege}s from the specified privilege names. * * @param accessControlManager The access control manager. * @param privilegeNames The privilege names. * @return An array of privileges./* w w w.j ava 2 s . co m*/ * @throws RepositoryException If an error occurs or if {@code privilegeNames} contains an unknown/invalid privilege name. */ public static Privilege[] privilegesFromNames(AccessControlManager accessControlManager, String... privilegeNames) throws RepositoryException { final Set<Privilege> privileges = new HashSet<Privilege>(privilegeNames.length); for (final String privName : privilegeNames) { privileges.add(accessControlManager.privilegeFromName(privName)); } return privileges.toArray(new Privilege[privileges.size()]); }
From source file:net.lldp.checksims.algorithm.similaritymatrix.SimilarityMatrix.java
/** * Generate a Similarity Matrix with archive submissions. * * The result is not a square matrix. Only the input submissions are on the X axis, but the Y axis contains both * input and archive submissions./*from w w w. ja v a 2 s. c om*/ * * @param inputSubmissions Submissions used to generate matrix * @param archiveSubmissions Archive submissions - only compared to input submissions, not to each other * @param results Results used to build matrix * @return Similarity matrix built from given results * @throws InternalAlgorithmError Thrown on missing results, or results containing a submission not in the input */ public static SimilarityMatrix generateMatrix(Set<Submission> inputSubmissions, Set<Submission> archiveSubmissions, Set<AlgorithmResults> results) throws InternalAlgorithmError { checkNotNull(inputSubmissions); checkNotNull(archiveSubmissions); checkNotNull(results); checkArgument(!inputSubmissions.isEmpty(), "Must provide at least 1 submission to build matrix from"); checkArgument(!results.isEmpty(), "Must provide at least 1 AlgorithmResults to build matrix from!"); Set<Submission> setOfBoth = new HashSet<>(); setOfBoth.addAll(inputSubmissions); setOfBoth.addAll(archiveSubmissions); checkArgument(setOfBoth.size() == (archiveSubmissions.size() + inputSubmissions.size()), "Some submissions were found in both archive and input submissions!"); // If there are no archive submissions, just generate using the other function if (archiveSubmissions.isEmpty()) { return generateMatrix(inputSubmissions, results); } List<Submission> xSubmissions = Ordering.natural().immutableSortedCopy(inputSubmissions); List<Submission> ySubmissions = new ArrayList<>(); ySubmissions.addAll(Ordering.natural().immutableSortedCopy(inputSubmissions)); ySubmissions.addAll(Ordering.natural().immutableSortedCopy(archiveSubmissions)); AlgorithmResults[][] matrix = new AlgorithmResults[xSubmissions.size()][ySubmissions.size()]; // Generate the matrix // First, handle identical submissions for (Submission xSub : xSubmissions) { // Get the X index int xIndex = xSubmissions.indexOf(xSub); int yIndex = ySubmissions.indexOf(xSub); matrix[xIndex][yIndex] = new AlgorithmResults(Pair.of(xSub, xSub), Real.ONE, Real.ONE); } // Now iterate through all given algorithm results for (AlgorithmResults result : results) { int aXCoord = xSubmissions.indexOf(result.a); int bXCoord = xSubmissions.indexOf(result.b); if (aXCoord == -1 && bXCoord == -1) { throw new InternalAlgorithmError("Neither submission \"" + result.a.getName() + "\" nor \"" + result.b.getName() + "\" were found in input submissions!"); } if (aXCoord != -1) { int bYCoord = ySubmissions.indexOf(result.b); matrix[aXCoord][bYCoord] = result.inverse(); } if (bXCoord != -1) { int aYCoord = ySubmissions.indexOf(result.a); matrix[bXCoord][aYCoord] = result; } } // Verification pass - ensure we built a matrix with no nulls for (int x = 0; x < xSubmissions.size(); x++) { for (int y = 0; y < ySubmissions.size(); y++) { if (matrix[x][y] == null) { throw new InternalAlgorithmError("Missing Algorithm Results for comparison of submissions \"" + xSubmissions.get(x).getName() + "\" and \"" + ySubmissions.get(y).getName() + "\""); } } } return new SimilarityMatrix(matrix, xSubmissions, ySubmissions, results); }
From source file:net.sf.morph.util.ListOrderedSet.java
/** * Factory method to create an ordered set specifying the list and set to use. * <p>/*w ww . j a v a2s.c o m*/ * The list and set must both be empty. * * @param set the set to decorate, must be empty and not null * @param list the list to decorate, must be empty and not null * @throws IllegalArgumentException if set or list is null * @throws IllegalArgumentException if either the set or list is not empty * @since Commons Collections 3.1 */ public static ListOrderedSet decorate(Set set, List list) { if (set == null) { throw new IllegalArgumentException("Set must not be null"); } if (list == null) { throw new IllegalArgumentException("List must not be null"); } if (set.size() > 0 || list.size() > 0) { throw new IllegalArgumentException("Set and List must be empty"); } return new ListOrderedSet(set, list); }
From source file:com.sapienter.jbilling.server.metafields.MetaFieldHelper.java
/** * Set the values of meta fields (as specified by {@code metaFieldNames}) on {@code entity} with values * found in {@code metaFields}.//from w w w . j a v a 2 s . co m * * @param metaFieldNames These MetaFields will get their values set * @param entity * @param metaFields New values for MetaFields */ public static void fillMetaFieldsFromWS(Set<MetaField> metaFieldNames, CustomizedEntity entity, MetaFieldValueWS[] metaFields) { Map<String, MetaField> metaFieldMap = new HashMap<String, MetaField>(metaFieldNames.size() * 2); for (MetaField metaField : metaFieldNames) { metaFieldMap.put(metaField.getName(), metaField); } if (metaFields != null) { for (MetaFieldValueWS fieldValue : metaFields) { MetaField metaField = metaFieldMap.get(fieldValue.getFieldName()); if (metaField == null) { throw new SessionInternalError( "MetaField [" + fieldValue.getFieldName() + "] does not exist for entity " + entity); } entity.setMetaField(metaField, fieldValue.getValue()); } } }
From source file:com.google.uzaygezen.core.BoundedRollupTest.java
private static <V, K> Set<MapNode<K, V>> toIdentitySet(List<MapNode<K, V>> list) { Set<MapNode<K, V>> set = Collections.newSetFromMap(new IdentityHashMap<MapNode<K, V>, Boolean>()); set.addAll(list);//from w ww .j a v a 2 s . c o m Assert.assertEquals(list.size(), set.size()); return set; }
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 w w .ja va 2s . c o m } // 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); } } }