List of usage examples for java.util HashSet size
public int size()
From source file:fr.lip6.segmentations.ProcessHTML5.java
public void run() { //ArrayList<String> s1 = new ArrayList<String>(); //ArrayList<String> s2= new ArrayList<String>();; String s1 = ""; String s2 = ""; try {//from w ww . j a v a 2s .c om Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection( "jdbc:mysql://" + Config.mysqlHost + "/" + Config.mysqlDatabase + "", Config.mysqlUser, Config.mysqlPassword); Statement st2 = con.createStatement(); ResultSet rs = st2.executeQuery("select * from html5repo where descriptorbom<>''"); while (rs.next()) { s1 = ""; s2 = ""; String d1 = rs.getString("descriptor"); String d2 = rs.getString("descriptorbom"); int dsize = d1.split(",").length; int d2size = d2.split(",").length; for (String s : d1.split(",")) { String[] part = s.split("="); if (!part[0].equals("PAGE")) { if (part[1].equals("SECTION")) s1 += "S"; if (part[1].equals("ARTICLE")) s1 += "A"; if (part[1].equals("ASIDE")) s1 += "D"; if (part[1].equals("HEADER")) s1 += "H"; if (part[1].equals("FOOTER")) s1 += "F"; if (part[1].equals("NAV")) s1 += "N"; } } for (String s : d2.split(",")) { String[] part = s.split("="); if (!part[0].equals("PAGE")) { if (part[1].equals("SECTION")) s2 += "S"; if (part[1].equals("ARTICLE")) s2 += "A"; if (part[1].equals("ASIDE")) s2 += "D"; if (part[1].equals("HEADER")) s2 += "H"; if (part[1].equals("FOOTER")) s2 += "F"; if (part[1].equals("NAV")) s2 += "N"; } } int ed = StringUtils.getLevenshteinDistance(s1.toString(), s2.toString()); int edtotal = Math.max(s1.length(), s2.length()); HashSet<Character> h1 = new HashSet<Character>(), h2 = new HashSet<Character>(); for (int i = 0; i < s1.length(); i++) { h1.add(s1.charAt(i)); } for (int i = 0; i < s2.length(); i++) { h2.add(s2.charAt(i)); } h1.retainAll(h2); int inter = h1.size(); char[] code1 = s1.toCharArray(); char[] code2 = s2.toCharArray(); Set set1 = new HashSet(); for (char c : code1) { set1.add(c); } Set set2 = new HashSet(); for (char c : code2) { set2.add(c); } int total = set1.size(); System.out.println(set1); System.out.println(set2); System.out.println(s1); System.out.println(s2); System.out.println(rs.getString("id") + ". " + rs.getString("datafolder") + "=" + ed + "/" + edtotal + "=" + ((double) ed / edtotal) + "," + inter + " of " + total + " Prec:(" + ((double) inter / total) + ")"); Statement st3 = con.createStatement(); //base=distancemax st3.execute("update html5repo set distance='" + ed + "',base='" + edtotal + "',found='" + inter + "', expected='" + total + "' where datafolder='" + rs.getString("datafolder") + "'"); File f = new File("/home/sanojaa/Documents/00_Tesis/work/dataset/dataset/data/" + rs.getString("datafolder") + "/" + rs.getString("datafolder") + ".5.html"); if (!f.exists()) { f.createNewFile(); } FileOutputStream fop = new FileOutputStream(f); fop.write(rs.getString("src").getBytes()); fop.flush(); fop.close(); } } catch (SQLException ex) { Logger.getLogger(SeleniumWrapper.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(HTML5Bom.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ProcessHTML5.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ProcessHTML5.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.commonjava.maven.cartographer.agg.DefaultGraphAggregator.java
@Override public void connectIncomplete(final RelationshipGraph graph, final AggregationOptions config) throws CartoDataException { if (graph != null && config.isDiscoveryEnabled()) { final Set<ProjectVersionRef> missing = new HashSet<ProjectVersionRef>(); logger.debug("Loading existing cycle participants..."); // final Set<ProjectVersionRef> cycleParticipants = loadExistingCycleParticipants( net ); final Set<ProjectVersionRef> seen = new HashSet<ProjectVersionRef>(); logger.debug("Loading initial set of GAVs to be resolved..."); final List<DiscoveryTodo> pending = loadInitialPending(graph, seen); final HashSet<DiscoveryTodo> done = new HashSet<DiscoveryTodo>(); int pass = 0; while (!pending.isEmpty()) { // final HashSet<DiscoveryTodo> current = new HashSet<DiscoveryTodo>( pending ); // pending.clear(); final HashSet<DiscoveryTodo> current = new HashSet<DiscoveryTodo>(MAX_BATCHSIZE); while (!pending.isEmpty() && current.size() < MAX_BATCHSIZE) { current.add(pending.remove(0)); }//from ww w . j a v a 2 s.com done.addAll(current); logger.debug("{}. {} in next batch of TODOs:\n {}", pass, current.size(), new JoinString("\n ", current)); final Set<DiscoveryTodo> newTodos = discover(current, config, /*cycleParticipants,*/missing, seen, pass); if (newTodos != null) { logger.debug("{}. Uncovered new batch of TODOs:\n {}", pass, new JoinString("\n ", newTodos)); for (final DiscoveryTodo todo : newTodos) { if (!done.contains(todo) && !pending.contains(todo)) { logger.debug("+= {}", todo); pending.add(todo); } } } pass++; } logger.info("Discovery complete. {} seen, {} missing in {} passes.", seen.size(), missing.size(), pass - 1); } }
From source file:org.apache.cocoon.core.container.spring.avalon.PoolableFactoryBean.java
/** * Create a PoolableComponentHandler which manages a pool of Components * created by the specified factory object. * * @param name The name of the bean which should be pooled. *//*w w w . jav a 2 s .c o m*/ public PoolableFactoryBean(String name, String className, String poolMaxString, Settings settings) throws Exception { String value = poolMaxString; if (settings != null) { value = PropertyHelper.replace(poolMaxString, settings); } int poolMax = Integer.valueOf(value).intValue(); this.name = name; this.max = (poolMax <= 0 ? Integer.MAX_VALUE : poolMax); this.beanClass = Class.forName(className); final HashSet workInterfaces = new HashSet(); // Get *all* interfaces this.guessWorkInterfaces(this.beanClass, workInterfaces); // Add AvalonPoolable workInterfaces.add(AvalonPoolable.class); this.interfaces = (Class[]) workInterfaces.toArray(new Class[workInterfaces.size()]); // Create the pool lists. this.ready = new LinkedList(); }
From source file:org.droidparts.persist.sql.EntityManager.java
protected String[] getEagerForeignKeyColumnNames() { if (eagerForeignKeyColumnNames == null) { HashSet<String> eagerColumnNames = new HashSet<String>(); for (FieldSpec<ColumnAnn> spec : getTableColumnSpecs(cls)) { if (spec.ann.eager) { eagerColumnNames.add(spec.ann.name); }//from w w w. jav a 2s . co m } eagerForeignKeyColumnNames = eagerColumnNames.toArray(new String[eagerColumnNames.size()]); } return eagerForeignKeyColumnNames; }
From source file:it.iit.genomics.cru.simsearch.bundle.utils.AnnotationsFromTrack.java
public int getNumberOfMatchings(String annotationType) { HashSet<String> matching = new HashSet<>(); matching.addAll(matchingMappedByAnnotationType.get(annotationType)); return matching.size(); }
From source file:net.ontopia.topicmaps.nav.context.ThemeCategorizer.java
/** * Generate a ordered list of theme classes. * The themes which are found in the collection of selectedThemes use * their own stringifier <code>stringifierSelectedTheme</code>. * Note: In every theme class there are at least one theme. *///from w w w . jav a 2 s.c o m public String generateThemeList(HashMap themeClassMap, Collection selectedThemes, StringifierIF stringifierThemeClass, StringifierIF stringifierTheme, StringifierIF stringifierSelectedTheme) { if (themeClassMap == null || stringifierThemeClass == null || stringifierTheme == null) return ""; StringBuilder strBuf = new StringBuilder(); // ----- loop over all themes classes List themeClassList = new ArrayList(themeClassMap.keySet()); Collections.sort(themeClassList, lexicalComparator); Iterator itThemeClasses = themeClassList.iterator(); String actThemeClass; HashSet actSet; List themeList; Iterator itRelThemes; TopicIF actTheme; while (itThemeClasses.hasNext()) { actThemeClass = (String) itThemeClasses.next(); actSet = (HashSet) themeClassMap.get(actThemeClass); // only proceed if category name has related themes if (actSet.size() > 0) { // append string representation for theme class strBuf.append(stringifierThemeClass.toString(actThemeClass)); themeList = new ArrayList(actSet); Collections.sort(themeList, topicComparator); itRelThemes = themeList.iterator(); while (itRelThemes.hasNext()) { actTheme = (TopicIF) itRelThemes.next(); // append string representation for theme if (selectedThemes != null && stringifierSelectedTheme != null) { if (selectedThemes.contains(actTheme)) strBuf.append(stringifierSelectedTheme.toString(actTheme)); else strBuf.append(stringifierTheme.toString(actTheme)); } else { strBuf.append(stringifierTheme.toString(actTheme)); } } // while itRelThemes } } // while itThemeClasses return strBuf.toString(); }
From source file:com.linuxbox.enkive.permissions.SpringContextPermissionService.java
@Override public boolean canReadMessage(String userId, MessageSummary message) throws CannotGetPermissionsException { if (isAdmin()) { return true; }/*from w w w . j a v a2s. c o m*/ Collection<String> canReadAddresses = canReadAddresses(userId); HashSet<String> originalMessageAddresses = new HashSet<String>(); originalMessageAddresses.addAll(message.getTo()); originalMessageAddresses.addAll(message.getCc()); originalMessageAddresses.addAll(message.getBcc()); originalMessageAddresses.addAll(message.getFrom()); originalMessageAddresses.add(message.getMailFrom()); originalMessageAddresses.addAll(message.getRcptTo()); HashSet<String> normalizedMessageAddresses = new HashSet<String>(originalMessageAddresses.size()); com.linuxbox.util.CollectionUtils.addAllMapped(normalizedMessageAddresses, originalMessageAddresses, emailAddressNormalizer); return CollectionUtils.containsAny(normalizedMessageAddresses, canReadAddresses); }
From source file:thingynet.hierarchy.HierarchyTest.java
@Test public void getDescendantsWithLevelShouldReturnExpectedHierarchies() { Hierarchy parent = hierarchyService.createRoot(PARENT, null); Hierarchy child = hierarchyService.createChild(parent, CHILD, null); hierarchyService.createChild(parent, SIBLING, null); Hierarchy grandChild = hierarchyService.createChild(child, GRAND_CHILD, null); Hierarchy greatGrandChild = hierarchyService.createChild(grandChild, GREAT_GRAND_CHILD, null); hierarchyService.createChild(greatGrandChild, CHILD, null); HashSet<String> expectedIds = new HashSet<>(); expectedIds.add(grandChild.getPath()); expectedIds.add(greatGrandChild.getPath()); Iterable<Hierarchy> actual = hierarchyService.getDescendants(child, 2); while (actual.iterator().hasNext()) { Hierarchy descendant = actual.iterator().next(); assertThat(expectedIds.remove(descendant.getPath()), is(true)); }//from w w w .j a v a 2s. c om assertThat(expectedIds.size(), is(0)); }
From source file:org.commonjava.cartographer.INTERNAL.graph.agg.DefaultGraphAggregator.java
@Override public void connectIncomplete(final RelationshipGraph graph, final AggregationOptions config) throws CartoDataException { if (graph != null && config.isDiscoveryEnabled()) { final Set<ProjectVersionRef> missing = new HashSet<ProjectVersionRef>(); logger.debug("Loading existing cycle participants..."); // final Set<ProjectVersionRef> cycleParticipants = loadExistingCycleParticipants( net ); final Map<ProjectVersionRef, Set<ProjectRef>> seen = new HashMap<>(); logger.debug("Loading initial set of GAVs to be resolved..."); final List<DiscoveryTodo> pending = loadInitialPending(graph, seen); final HashSet<DiscoveryTodo> done = new HashSet<DiscoveryTodo>(); int pass = 0; while (!pending.isEmpty()) { // final HashSet<DiscoveryTodo> current = new HashSet<DiscoveryTodo>( pending ); // pending.clear(); final HashSet<DiscoveryTodo> current = new HashSet<DiscoveryTodo>(MAX_BATCHSIZE); while (!pending.isEmpty() && current.size() < MAX_BATCHSIZE) { current.add(pending.remove(0)); }//from www. j av a 2 s. co m done.addAll(current); logger.debug("{}. {} in next batch of TODOs:\n {}", pass, current.size(), new JoinString("\n ", current)); final Set<DiscoveryTodo> newTodos = discover(current, config, /*cycleParticipants,*/missing, seen, pass); if (newTodos != null) { logger.debug("{}. Uncovered new batch of TODOs:\n {}", pass, new JoinString("\n ", newTodos)); for (final DiscoveryTodo todo : newTodos) { if (!done.contains(todo) && !pending.contains(todo)) { logger.debug("+= {}", todo); pending.add(todo); } } } pass++; } logger.info("Discovery complete. {} seen, {} missing in {} passes.", seen.size(), missing.size(), pass); } }
From source file:br.fapesp.myutils.MyUtils.java
/** * Compute the Minimum Spanning Tree (MST) using Prim's algorithm - O(n^2). * /* w ww .j a v a 2s .c o m*/ * @deprecated * @param data points in R^n * @return a 2-d array listing the edges of the MST. */ public static int[][] computeMinimumSpanningTreePrim(double[][] data) { int N = data.length; int[][] mst = new int[N - 1][2]; double[][] D = getEuclideanMatrix(data); // euclidean dissimilarity matrix double minw; int ichosen = -1, v_to_add = -1; int k = 0; HashSet<Integer> vin = new HashSet<Integer>(); HashSet<Integer> vout = new HashSet<Integer>(); for (int i = 1; i < N; i++) vout.add(i); // put all vertices on the out set, except the first vin.add(0); // add the first vertex while (vout.size() > 0) { // find the edge with minimum weight to add: minw = Double.MAX_VALUE; for (int i : vin) for (int j : vout) { if (D[i][j] < minw) { ichosen = i; minw = D[i][j]; v_to_add = j; } } vout.remove(v_to_add); vin.add(v_to_add); mst[k][0] = ichosen; mst[k][1] = v_to_add; k++; } return mst; }