List of usage examples for java.util Set size
int size();
From source file:edu.harvard.med.screensaver.io.libraries.WellDeprecator.java
@Transactional private static int updateWells(CommandLineApplication app, GenericEntityDAO dao) throws ParseException, IOException { String comments = app.getCommandLineOptionValue("c"); Integer approvedByAdminId = app.getCommandLineOptionValue("aa", Integer.class); LocalDate dateApproved = app.getCommandLineOptionValue("d", DateTimeFormat.forPattern(CommandLineApplication.DEFAULT_DATE_PATTERN)).toLocalDate(); AdministratorUser performedBy = app.findAdministratorUser(); AdministratorUser approvedBy = dao.findEntityById(AdministratorUser.class, approvedByAdminId); if (approvedBy == null) { throw new IllegalArgumentException("no administrator user found with User ID=" + approvedByAdminId); }/*from w ww . ja v a2 s . c o m*/ final AdministrativeActivity activity = new AdministrativeActivity(performedBy, approvedBy, dateApproved, AdministrativeActivityType.WELL_DEPRECATION); activity.setComments(comments); final int[] _sizeRead = new int[1]; final LibrariesDAO librariesDao = (LibrariesDAO) app.getSpringBean("librariesDao"); final Set<WellKey> wellKeys = readWellsFromFile(app); for (WellKey wellKey : wellKeys) { Well well = librariesDao.findWell(wellKey); if (well == null) { throw new DAOTransactionRollbackException("no such well " + wellKey); } else { if (well.getDeprecationActivity() != null) { throw new DAOTransactionRollbackException("well " + wellKey + " is already deprecated"); } well.setDeprecationActivity(activity); } } log.info("WellDeprecator read in and added comments for " + wellKeys.size() + " wells."); return wellKeys.size(); }
From source file:org.ttrssreader.utils.Utils.java
public static String separateItems(Set<?> att, String separator) { if (att == null) return ""; String ret;/*from w w w . ja va 2 s . co m*/ StringBuilder sb = new StringBuilder(); for (Object s : att) { sb.append(s); sb.append(separator); } if (att.size() > 0) { ret = sb.substring(0, sb.length() - separator.length()); } else { ret = sb.toString(); } return ret; }
From source file:playground.johannes.socialnets.GraphStatistics.java
static public Histogram createDegreeHistogram(Graph g, int min, int max, int ignoreWave) { Set<Vertex> vertices = new HashSet<Vertex>(); for (Object o : g.getVertices()) { if (((Vertex) o).getUserDatum(UserDataKeys.ANONYMOUS_KEY) == null) vertices.add((Vertex) o);/*from w w w .ja va 2 s .co m*/ } DoubleArrayList values = new DoubleArrayList(vertices.size()); DoubleArrayList weights = new DoubleArrayList(vertices.size()); try { BufferedWriter writer = IOUtils.getBufferedWriter(outputDir + ignoreWave + ".weights.txt"); for (Vertex v : vertices) { int k = v.degree(); values.add(k); writer.write(String.valueOf(k)); writer.write("\t"); Integer wave = (Integer) v.getUserDatum(UserDataKeys.SAMPLED_KEY); double w = 1; if (wave == null || k == 0) weights.add(1); else { // w = 1 / (1 - Math.pow((1 - fracVertices),k)); w = 1;// / (Double)v.getUserDatum(UserDataKeys.SAMPLE_PROBA_KEY); weights.add(w); } writer.write(String.valueOf(w)); writer.newLine(); writer.flush(); } writer.close(); } catch (Exception e) { e.printStackTrace(); } if (min < 0 && max < 0) { DoubleArrayList copy = values.copy(); copy.sort(); min = (int) copy.get(0); max = (int) copy.get(values.size() - 1); } Histogram hist = new Histogram(1.0, 0, max); for (int i = 0; i < values.size(); i++) { hist.add(values.get(i), weights.get(i)); } System.out.println("Gamma exponent is estimated to " + estimatePowerLawExponent(values)); return hist; }
From source file:org.apache.ambari.server.controller.ganglia.GangliaPropertyProvider.java
/** * Get a comma delimited string from the given set of strings or * an empty string if the size of the given set is greater than * the given limit./*from w w w. ja v a 2s. co m*/ * * @param set the set of strings * @param limit the upper size limit for the list * * @return a comma delimited string of strings */ private static String getSetString(Set<String> set, int limit) { StringBuilder sb = new StringBuilder(); if (limit == -1 || set.size() <= limit) { for (String cluster : set) { if (sb.length() > 0) { sb.append(','); } sb.append(cluster); } } return sb.toString(); }
From source file:edu.umass.cs.gigapaxos.testing.TESTPaxosConfig.java
/** * @param groupID//from w w w. j a v a 2s. co m * @param members */ public static void setGroup(String groupID, Set<Integer> members) { int[] array = new int[members.size()]; int j = 0; for (int id : members) array[j++] = id; groups.put(groupID, array); }
From source file:org.jdbcluster.JDBClusterUtil.java
/** * returns the corresponding cluster id for a dao class * /*ww w.j a v a 2 s. c om*/ * @param clazz * the dao class * @return the cluster id. Can be {@code null} */ static synchronized public String getClusterId(Class<? extends Dao> clazz) { if (dao2clusterId == null) { fillDao2ClusterId(); } Set<String> clusterIds = dao2clusterId.get(clazz); if (clusterIds == null || clusterIds.isEmpty()) { return null; } else if (clusterIds.size() == 1) { return clusterIds.iterator().next(); } else { throw new ConfigurationException( "several clusters defined using this dao [" + clazz.getName() + "]. Not supported yet"); } }
From source file:com.aurel.track.admin.customize.category.filter.execute.loadItems.LoadItemLinksUtil.java
/** * //from www .j av a 2 s .com * @param baseWorkItemBeanList * @param archived * @param deleted * @param allItemIDSet * @return */ private static Set<Integer> loadAncestorDescendantAndDirectLinkedItems(List<TWorkItemBean> baseWorkItemBeanList, Integer archived, Integer deleted, Set<Integer> allItemIDSet) { Set<Integer> originalItemIDSet = GeneralUtils.createIntegerSetFromBeanList(baseWorkItemBeanList); LOGGER.debug("Number of items in filter " + originalItemIDSet.size()); Set<Integer> ancestorWorkItemIDsSet = getParentHierarchy(baseWorkItemBeanList, archived, deleted); LOGGER.debug("Number of ascendent items " + ancestorWorkItemIDsSet.size()); allItemIDSet.addAll(originalItemIDSet); allItemIDSet.addAll(ancestorWorkItemIDsSet); Set<Integer> descendantItemIDSet = ItemBL.getChildHierarchy( GeneralUtils.createIntArrFromIntegerCollection(allItemIDSet), PARENT_CHILD_EXPRESSION.ALL_CHILDREN, archived, deleted, null); LOGGER.debug("Total number of descendent items " + descendantItemIDSet.size()); allItemIDSet.addAll(descendantItemIDSet); //gather the MSProject link types MsProjectLinkType msProjectLinkType = MsProjectLinkType.getInstance(); List<Integer> msProjectLinkTypes = LinkTypeBL.getLinkTypesByPluginClass(msProjectLinkType); //although Msproject link is unidirectional, we have to load also the predecessors in order to avoid moving back the successor items Map<Integer, SortedSet<Integer>> linkDependencyMap = ItemLinkBL.loadByWorkItemsAndLinkType( GeneralUtils.createIntegerListFromCollection(allItemIDSet), msProjectLinkTypes, msProjectLinkType.getPossibleDirection(), true, archived, deleted); Set<Integer> linkedItemIDsSet = getFlatItems(linkDependencyMap); LOGGER.debug("Number of linked items from hierarchy " + linkedItemIDsSet.size()); linkedItemIDsSet.removeAll(allItemIDSet); LOGGER.debug("Number of extended linked items " + linkedItemIDsSet.size()); allItemIDSet.addAll(linkedItemIDsSet); return linkedItemIDsSet; }
From source file:com.haulmont.cuba.web.gui.components.WebComponentsHelper.java
/** * Add actions to vaadin action container. * * @param container any {@link Action.Container} * @param actions map of actions//from w ww.ja v a 2s .co m */ public static void setActions(Action.Container container, Map<Action, Runnable> actions) { container.addActionHandler(new Action.Handler() { @Override public Action[] getActions(Object target, Object sender) { Set<Action> shortcuts = actions.keySet(); return shortcuts.toArray(new Action[shortcuts.size()]); } @Override public void handleAction(Action action, Object sender, Object target) { Runnable runnable = actions.get(action); if (runnable != null) { runnable.run(); } } }); }
From source file:weka.core.ChartUtils.java
/** * Creates and writes a combined chart for a nominal attribute given its * summary attribute information and an output stream to write to * //w ww . j a v a 2s . c om * @param summaryAtt the summary attribute for the attribute to process * @param attName the name of the attribute * @param dos the output stream to write to * @param width the width of the chart * @param height the height of the chart * @throws IOException if a problem occurs */ public static void createAttributeChartNominal(Attribute summaryAtt, String attName, OutputStream dos, int width, int height) throws IOException { NominalStats stats = NominalStats.attributeToStats(summaryAtt); Set<String> labels = stats.getLabels(); String[] labs = new String[labels.size() + 1]; double[] freqs = new double[labs.length]; int count = 0; for (String l : labels) { labs[count] = l; freqs[count++] = stats.getCount(l); } freqs[count] = stats.getNumMissing(); labs[count] = "*missing*"; int[] sortedIndices = Utils.sort(freqs); // we want the top 7 values plus missing, and // any other values collapsed into an "other" // category String[] finalLabs; double[] finalFreqs; if (labs.length <= 8) { finalLabs = new String[labs.length]; finalFreqs = new double[labs.length]; count = 0; for (int i = sortedIndices.length - 1; i >= 0; i--) { finalLabs[count] = labs[sortedIndices[i]]; finalFreqs[count++] = freqs[sortedIndices[i]]; } } else { finalLabs = new String[9]; finalFreqs = new double[9]; finalLabs[8] = "*missing*"; finalFreqs[8] = stats.getNumMissing(); count = 0; for (int i = sortedIndices.length - 1; i >= 0; i--) { if (labs[sortedIndices[i]].equals("*missing*")) { continue; } if (count == 7) { if (labs.length > 9) { finalLabs[count] = "*other*"; } else { finalLabs[count] = labs[sortedIndices[i]]; } finalFreqs[count] += freqs[sortedIndices[i]]; continue; } finalLabs[count] = labs[sortedIndices[i]]; finalFreqs[count++] = freqs[sortedIndices[i]]; } } List<String> values = Arrays.asList(finalLabs); List<Double> freqL = new ArrayList<Double>(); for (double d : finalFreqs) { freqL.add(d); } List<String> opts = new ArrayList<String>(); opts.add("-title=" + attName); try { BufferedImage chart = ChartUtils.renderCombinedPieAndHistogramFromSummaryData(width, height, values, freqL, opts); try { ChartUtils.writeImage(chart, dos); } finally { if (dos != null) { dos.close(); } } } catch (Exception e) { throw new IOException(e); } }
From source file:org.eclipse.virgo.ide.runtime.core.ServerUtils.java
/** * Returns the targeted runtimes of the given project * @param project the project to return the target runtimes for *///from w w w . ja va2 s . c o m public static IRuntime[] getTargettedRuntimes(IProject project) { final Set<org.eclipse.wst.server.core.IRuntime> targetedServerRuntimes = new LinkedHashSet<org.eclipse.wst.server.core.IRuntime>(); ServerRuntimeUtils.execute(project, new ServerRuntimeUtils.ServerRuntimeCallback() { public boolean doWithRuntime(ServerRuntime runtime) { targetedServerRuntimes.add(runtime.getRuntime()); return true; } }); return targetedServerRuntimes.toArray(new IRuntime[targetedServerRuntimes.size()]); }