List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:de.unidue.inf.is.ezdl.gframedl.EzDL.java
private static void checkJavaVersion() { Set<String> lafNames = new HashSet<String>(); for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { lafNames.add(info.getName());/* ww w .j ava 2 s . co m*/ } if (!lafNames.contains("Nimbus")) { String message = "<html>Please install a recent version of Java 1.6 (http://www.java.com)!<br /><br /> Detected version: " + System.getProperty("java.version"); JOptionPane.showMessageDialog(null, message, "No appropriate Java version detected!", JOptionPane.ERROR_MESSAGE); System.exit(0); } }
From source file:org.openmrs.module.hospitalcore.util.RadiologyUtil.java
private static TestModel generateModel(Order order, RadiologyTest test, Map<Concept, Set<Concept>> testTreeMap) { TestModel tm = new TestModel(); tm.setStartDate(sdf.format(order.getStartDate())); tm.setPatientIdentifier(order.getPatient().getPatientIdentifier().getIdentifier()); tm.setPatientName(PatientUtils.getFullName(order.getPatient())); tm.setGender(order.getPatient().getGender()); tm.setAge(PatientUtils.estimateAge(order.getPatient())); tm.setTestName(order.getConcept().getName().getName()); tm.setOrderId(order.getOrderId());//from ww w . j a va 2s .c o m // if the test is an x-ray test, then turn on this flag if (getXrayConcepts(testTreeMap).contains(order.getConcept())) { tm.setXray(true); } else { tm.setXray(false); } if (test != null) { tm.setStatus(test.getStatus()); tm.setTestId(test.getId()); if (test.getForm() != null) { tm.setGivenFormId(test.getForm().getId()); } if (test.getEncounter() != null) { tm.setGivenEncounterId(test.getEncounter().getEncounterId()); } tm.setAcceptedDate(sdf.format(test.getDate())); } else { tm.setStatus(null); } // get investigation from test tree map if (testTreeMap != null) { for (Concept investigationConcept : testTreeMap.keySet()) { Set<Concept> set = testTreeMap.get(investigationConcept); if (set.contains(order.getConcept())) { tm.setInvestigation(getConceptName(investigationConcept)); } } } return tm; }
From source file:com.joyent.manta.client.MantaObjectDepthComparatorTest.java
private static void assertOrdering(final List<MantaObject> sorted) { Set<String> parentDirs = new LinkedHashSet<>(); int index = 0; for (MantaObject obj : sorted) { if (obj.isDirectory()) { String parentDir = Paths.get(obj.getPath()).getParent().toString(); Assert.assertFalse(parentDirs.contains(parentDir), "The parent of this directory was encountered before " + "this directory [index=" + index + "]."); parentDirs.remove(obj.getPath()); } else {//w w w . j a v a 2s . c o m String fileParentDir = Paths.get(obj.getPath()).getParent().toString(); Assert.assertFalse(parentDirs.contains(fileParentDir), "Parent directory path was returned before file path. " + "Index [" + index + "] was out of order. " + "Actual sorting:\n" + StringUtils.join(sorted, "\n")); } index++; } }
From source file:org.apache.edgent.connectors.http.HttpResponders.java
/** * Return the input tuple on specified codes. * Function that returns null (no output) if the HTTP response * is not one of {@code codes}, otherwise it returns the input tuple. * The HTTP entity in the response is consumed and discarded. * @param <T> Type of input tuple. * @param codes HTTP status codes to result in output * @return Function that returns the input tuple on matching codes. *///from w w w.j a v a2 s .co m public static <T> BiFunction<T, CloseableHttpResponse, T> inputOn(Integer... codes) { Set<Integer> uniqueCodes = new HashSet<>(Arrays.asList(codes)); return (t, resp) -> { int sc = resp.getStatusLine().getStatusCode(); try { EntityUtils.consume(resp.getEntity()); } catch (Exception e) { ; } return uniqueCodes.contains(sc) ? t : null; }; }
From source file:com.esri.squadleader.model.GeoPackageReader.java
private static List<Layer> getTablesAsLayers(List<GeopackageFeatureTable> tables, Set<Geometry.Type> types, Renderer renderer) {/*from w w w . j a va 2 s . c om*/ List<Layer> layers = new ArrayList<Layer>(tables.size()); for (GeopackageFeatureTable table : tables) { if (types.contains(table.getGeometryType())) { final FeatureLayer layer = new FeatureLayer(table); JSONObject jsonObject = new JSONObject(); JSONArray fieldsArray = new JSONArray(); try { for (Field field : table.getFields()) { fieldsArray.put(new JSONObject(Field.toJson(field))); } jsonObject.put("fields", fieldsArray); LayerServiceInfo layerInfo = LayerServiceInfo .fromJson(new JsonFactory().createJsonParser(jsonObject.toString())); layer.getPopupInfo(0).setLayer(layerInfo); } catch (Exception e) { Log.e(TAG, "Could not create LayerServiceInfo for FeatureLayer for table " + table.getTableName(), e); } layer.setRenderer(renderer); layer.setName(table.getTableName()); layers.add(layer); } } return layers; }
From source file:FileHelper.java
public static void synchronize(File source, File destination, boolean smart, long chunkSize) throws IOException { if (chunkSize <= 0) { System.out.println("Chunk size must be positive: using default value."); chunkSize = DEFAULT_COPY_BUFFER_SIZE; }/* w w w . ja v a2s. c o m*/ if (source.isDirectory()) { if (!destination.exists()) { if (!destination.mkdirs()) { throw new IOException("Could not create path " + destination); } } else if (!destination.isDirectory()) { throw new IOException("Source and Destination not of the same type:" + source.getCanonicalPath() + " , " + destination.getCanonicalPath()); } String[] sources = source.list(); Set<String> srcNames = new HashSet<String>(Arrays.asList(sources)); String[] dests = destination.list(); //delete files not present in source for (String fileName : dests) { if (!srcNames.contains(fileName)) { delete(new File(destination, fileName)); } } //copy each file from source for (String fileName : sources) { File srcFile = new File(source, fileName); File destFile = new File(destination, fileName); synchronize(srcFile, destFile, smart, chunkSize); } } else { if (destination.exists() && destination.isDirectory()) { delete(destination); } if (destination.exists()) { long sts = source.lastModified() / FAT_PRECISION; long dts = destination.lastModified() / FAT_PRECISION; //do not copy if smart and same timestamp and same length if (!smart || sts == 0 || sts != dts || source.length() != destination.length()) { copyFile(source, destination, chunkSize); } } else { copyFile(source, destination, chunkSize); } } }
From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.util.CharacterNGramIdfValuesGenerator.java
@SuppressWarnings("unchecked") public static void computeIdfScores(Dataset dataset, int n) throws Exception { File outputFile = new File(UTILS_DIR + "/character-ngrams-idf/" + n + "/" + dataset.toString() + ".txt"); System.out.println("Computing character " + n + "-grams"); if (outputFile.exists()) { System.out.println(" - skipping, already exists"); } else {// ww w.j a v a2s.co m System.out.println(" - this may take a while..."); CollectionReader reader = ColingUtils.getCollectionReader(dataset); // Tokenization AnalysisEngineDescription seg = createPrimitiveDescription(BreakIteratorSegmenter.class); AggregateBuilder builder = new AggregateBuilder(); builder.add(seg, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_1); builder.add(seg, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_2); AnalysisEngine aggr_seg = builder.createAggregate(); // Output Writer AnalysisEngine writer = createPrimitive(CharacterNGramIdfValuesGeneratorWriter.class, CharacterNGramIdfValuesGeneratorWriter.PARAM_OUTPUT_FILE, outputFile.getAbsolutePath()); SimplePipeline.runPipeline(reader, aggr_seg, writer); // We now have plain text format List<String> lines = FileUtils.readLines(outputFile); Map<String, Double> idfValues = new HashMap<String, Double>(); CharacterNGramMeasure measure = new CharacterNGramMeasure(n, new HashMap<String, Double>()); // Get n-gram representations of texts List<Set<String>> docs = new ArrayList<Set<String>>(); for (String line : lines) { Set<String> ngrams = measure.getNGrams(line); docs.add(ngrams); } // Get all ngrams Set<String> allNGrams = new HashSet<String>(); for (Set<String> doc : docs) allNGrams.addAll(doc); // Compute idf values for (String ngram : allNGrams) { double count = 0; for (Set<String> doc : docs) { if (doc.contains(ngram)) count++; } idfValues.put(ngram, count); } // Compute the idf for (String lemma : idfValues.keySet()) { double idf = Math.log10(lines.size() / idfValues.get(lemma)); idfValues.put(lemma, idf); } // Store persistently StringBuilder sb = new StringBuilder(); for (String key : idfValues.keySet()) { sb.append(key + "\t" + idfValues.get(key) + LF); } FileUtils.writeStringToFile(outputFile, sb.toString()); System.out.println(" - done"); } }
From source file:net.sf.jasperreports.engine.util.JRFontUtil.java
/** * *///from w w w.j a v a 2 s .co m public static void checkAwtFont(String name, boolean ignoreMissingFont) { if (!JRGraphEnvInitializer.isAwtFontAvailable(name)) { if (ignoreMissingFont) { Set<String> missingFontNames = threadMissingFontsCache.get(); if (!missingFontNames.contains(name)) { missingFontNames.add(name); if (log.isWarnEnabled()) { log.warn("Font '" + name + "' is not available to the JVM. For more details, see http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/util/JRFontNotFoundException.html"); } } } else { throw new JRFontNotFoundException(name); } } }
From source file:de.uniko.west.winter.core.serializing.JSONResultProcessor.java
public static Map<String, Set<Object>> processResultsMultiVarFilter(String results, Set<String> varFilter) { try {// w w w .j a va 2s . co m JSONObject jsonResultObject = new JSONObject(results); Map<String, Set<Object>> resultsMap = convertJson2Map(jsonResultObject); for (String key : resultsMap.keySet()) { if (!varFilter.contains(key)) { resultsMap.remove(key); } } return resultsMap; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:FileHelper.java
public static boolean areInSync(File source, File destination) throws IOException { if (source.isDirectory()) { if (!destination.exists()) { return false; } else if (!destination.isDirectory()) { throw new IOException("Source and Destination not of the same type:" + source.getCanonicalPath() + " , " + destination.getCanonicalPath()); }/*from w w w . ja v a 2s . com*/ String[] sources = source.list(); Set<String> srcNames = new HashSet<String>(Arrays.asList(sources)); String[] dests = destination.list(); // check for files in destination and not in source for (String fileName : dests) { if (!srcNames.contains(fileName)) { return false; } } boolean inSync = true; for (String fileName : sources) { File srcFile = new File(source, fileName); File destFile = new File(destination, fileName); if (!areInSync(srcFile, destFile)) { inSync = false; break; } } return inSync; } else { if (destination.exists() && destination.isFile()) { long sts = source.lastModified() / FAT_PRECISION; long dts = destination.lastModified() / FAT_PRECISION; return sts == dts; } else { return false; } } }