List of usage examples for java.util Set size
int size();
From source file:common.Utilities.java
public static double getJaccardFloatSim(Map<Integer, Double> targetMap, Map<Integer, Double> nMap) { Set<Integer> unionSet = new HashSet<Integer>(targetMap.keySet()); Set<Integer> intersectSet = new HashSet<Integer>(targetMap.keySet()); unionSet.addAll(nMap.keySet());//from ww w .j av a 2 s .c o m intersectSet.retainAll(nMap.keySet()); return (double) intersectSet.size() / (double) unionSet.size(); }
From source file:dk.statsbiblioteket.util.Logs.java
protected static void expand(StringWriter writer, Set set, int maxLength, int maxDepth) { writer.append(Integer.toString(set.size())); if (maxDepth == 0) { writer.append("(...)"); return;//from w ww . jav a 2 s . c om } int num = set.size() <= maxLength + 1 ? set.size() : Math.max(1, maxLength); writer.append("("); int counter = 0; for (Object object : set) { expand(writer, object, maxLength, maxDepth - 1); if (counter++ < num - 1) { writer.append(", "); } else { break; } } if (num < set.size()) { writer.append(", ..."); } writer.append(")"); }
From source file:io.cloudslang.maven.compiler.CloudSlangMavenCompiler.java
protected static String[] getSourceFiles(CompilerConfiguration config) { Set<String> sources = new HashSet<>(); for (String sourceLocation : config.getSourceLocations()) { sources.addAll(getSourceFilesForSourceRoot(config, sourceLocation)); }//www . j ava2 s . c om return sources.toArray(new String[sources.size()]); }
From source file:grails.plugin.searchable.internal.compass.mapping.CompassMappingUtils.java
/** * Get the mapping aliases for the given user-defined domain classes any * @param compass Compass instance//from w w w . j a v a2 s . c om * @param clazzes the user-defined domain classes * @return the Compass aliases for the hierarchy */ public static String[] getMappingAliases(Compass compass, Collection clazzes) { Set aliases = new HashSet(); for (Iterator iter = clazzes.iterator(); iter.hasNext();) { Class clazz = (Class) iter.next(); aliases.add(getMappingAlias(compass, clazz)); } return (String[]) aliases.toArray(new String[aliases.size()]); }
From source file:net.audumla.climate.ClimateDataFactory.java
/** * Replaces the climate observation with a readonly version. * * @param cd the existing climate data bean * @return the climate data/*from w w w .j av a 2 s.c om*/ */ public static ClimateObservation convertToReadOnlyClimateObservation(ClimateObservation cd) { if (cd == null) { return null; } Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>(); interfaces.addAll(ClassUtils.getAllInterfaces(cd.getClass())); interfaces.remove(WritableClimateObservation.class); return BeanUtils.convertBean(cd, interfaces.toArray(new Class<?>[interfaces.size()])); }
From source file:net.sf.jasperreports.samples.wizards.SampleNewWizard.java
private static void addSourceFolders(Set<String> cpaths, IJavaProject project, IProgressMonitor monitor) { if (cpaths.isEmpty()) return;//from w w w. j ava2s.c o m try { IClasspathEntry[] cpentries = project.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[cpentries.length + cpaths.size()]; System.arraycopy(cpentries, 0, newEntries, 0, cpentries.length); int i = cpentries.length; for (String cp : cpaths) { newEntries[i] = JavaCore.newSourceEntry(project.getProject().getFile(cp).getFullPath()); i++; if (monitor.isCanceled()) return; } project.setRawClasspath(newEntries, monitor); } catch (JavaModelException e) { e.printStackTrace(); } }
From source file:de.citec.sc.matoll.utils.visualizeSPARQL.java
private static String findRoot(List<List<String>> relations) { String head = ""; Set<String> subj_list = new HashSet<>(); Set<String> obj_list = new HashSet<>(); relations.stream().map((list) -> { subj_list.add(list.get(0));//from ww w . jav a 2 s . c o m return list; }).forEach((list) -> { obj_list.add(list.get(1)); }); obj_list.removeAll(subj_list); if (obj_list.size() == 1) { return obj_list.toString().replace("[", "").replace("]", ""); } else { return null; } }
From source file:net.sf.jasperreports.samples.wizards.SampleNewWizard.java
private static void addLibraries(Set<String> lpaths, IJavaProject project, IProgressMonitor monitor) { if (lpaths.isEmpty()) return;// ww w. ja v a 2 s . c om try { IClasspathEntry[] cpentries = project.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[cpentries.length + lpaths.size()]; System.arraycopy(cpentries, 0, newEntries, 0, cpentries.length); int i = cpentries.length; for (String cp : lpaths) { newEntries[i] = JavaCore.newLibraryEntry(project.getProject().getFile(cp).getFullPath(), null, null); i++; if (monitor.isCanceled()) return; } project.setRawClasspath(newEntries, monitor); } catch (JavaModelException e) { e.printStackTrace(); } }
From source file:com.silverpeas.scheduleevent.control.ScheduleEventSessionController.java
private static String[] getContributorsUserIds(Set<Contributor> contributors) { Set<String> result = new HashSet<String>(contributors.size()); for (Contributor subscriber : contributors) { if (subscriber.getUserId() != -1) { result.add(String.valueOf(subscriber.getUserId())); }//from w w w . jav a 2 s.co m } return (String[]) result.toArray(new String[result.size()]); }
From source file:Main.java
/** * Writes a DOM document to a stream. The precise output format is not * guaranteed but this method will attempt to indent it sensibly. * * <p class="nonnormative"><b>Important</b>: There might be some problems * with <code><![CDATA[ ]]></code> sections in the DOM tree you pass * into this method. Specifically, some CDATA sections my not be written as * CDATA section or may be merged with other CDATA section at the same * level. Also if plain text nodes are mixed with CDATA sections at the same * level all text is likely to end up in one big CDATA section. * <br>//ww w . ja v a2s . co m * For nodes that only have one CDATA section this method should work fine. * </p> * * @param doc DOM document to be written * @param out data sink * @param enc XML-defined encoding name (for example, "UTF-8") * @throws IOException if JAXP fails or the stream cannot be written to */ public static void write(Document doc, OutputStream out, String enc) throws IOException { if (enc == null) { throw new NullPointerException( "You must set an encoding; use \"UTF-8\" unless you have a good reason not to!"); // NOI18N } Document doc2 = normalize(doc); ClassLoader orig = Thread.currentThread().getContextClassLoader(); Thread.currentThread() .setContextClassLoader(AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { // #195921 @Override public ClassLoader run() { return new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { @Override public InputStream getResourceAsStream(String name) { if (name.startsWith("META-INF/services/")) { return new ByteArrayInputStream(new byte[0]); // JAXP #6723276 } return super.getResourceAsStream(name); } }; } })); try { TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT))); DocumentType dt = doc2.getDoctype(); if (dt != null) { String pub = dt.getPublicId(); if (pub != null) { t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pub); } String sys = dt.getSystemId(); if (sys != null) { t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, sys); } } t.setOutputProperty(OutputKeys.ENCODING, enc); try { t.setOutputProperty(ORACLE_IS_STANDALONE, "yes"); } catch (IllegalArgumentException x) { // fine, introduced in JDK 7u4 } // See #123816 Set<String> cdataQNames = new HashSet<String>(); collectCDATASections(doc2, cdataQNames); if (cdataQNames.size() > 0) { StringBuilder cdataSections = new StringBuilder(); for (String s : cdataQNames) { cdataSections.append(s).append(' '); //NOI18N } t.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, cdataSections.toString()); } Source source = new DOMSource(doc2); Result result = new StreamResult(out); t.transform(source, result); } catch (javax.xml.transform.TransformerException | RuntimeException e) { // catch anything that happens throw new IOException(e); } finally { Thread.currentThread().setContextClassLoader(orig); } }