List of usage examples for java.util Set equals
boolean equals(Object o);
From source file:org.jax.haplotype.data.BinaryMultiGroupHaplotypeDataSource.java
/** * Bit-pack the input data and write a bunch of output files to the given * directory/*from w w w. j a v a 2 s. c om*/ * @param parser * the parser to use * @param inputCsvFile * the input csv file * @param outputDirectory * the output directory * @throws IOException * if we run into trouble reading or writing data * @throws IllegalFormatException * if an existing strain file in the directory has bad formatting */ public static void writeHMMStatesAsBinaryData(HiddenMarkovModelStateParser parser, File inputCsvFile, File outputDirectory) throws IOException, IllegalFormatException { if (!outputDirectory.exists()) { if (!outputDirectory.mkdirs()) { throw new IOException("Failed to create directory: " + outputDirectory.getAbsolutePath()); } } else if (!outputDirectory.isDirectory()) { throw new IOException(outputDirectory.getAbsolutePath() + " is not a valid directory"); } // // read the states from CSV // BufferedReader hmmFileReader = // new BufferedReader(new FileReader(inputCsvFile)); // Map<Integer, List<MultiPartitionedInterval>> states = parser.parseHMMStatesFromReader( // hmmFileReader, // null); // hmmFileReader.close(); // // // read the strains from CSV // BufferedInputStream strainNameInStream = // new BufferedInputStream(new FileInputStream(inputCsvFile)); // Set<String> strainSet = parser.parseAvailableStrainsFromStream( // strainNameInStream); // strainNameInStream.close(); // String[] strains = strainSet.toArray(new String[strainSet.size()]); // Arrays.sort(strains); // // // write the states to binary // for(Entry<Integer, List<MultiPartitionedInterval>> hmmStatesEntry: // states.entrySet()) // { // Integer currChr = hmmStatesEntry.getKey(); // File chrDir = new File( // outputDirectory, // CHROMOSOME_DIR_PREFIX + currChr.toString()); // chrDir.mkdir(); // // List<MultiPartitionedInterval> currHMMStates = // hmmStatesEntry.getValue(); // for(int i = 0; i < strains.length; i++) // { // String strain = strains[i]; // try // { // File strainFile = new File( // chrDir, // URL_CODEC.encode(strain) + // HMM_STATE_STREAM_FILTER.getEndingString()); // // if(strainFile.exists()) // { // throw new IOException( // "Refusing to overwrite file: " + // strainFile.getAbsolutePath() + // ". Please manually delete files or choose an empty " + // "export directory."); // } // else // { // ObjectOutputStream oos = new ObjectOutputStream( // new BufferedOutputStream(new FileOutputStream( // strainFile))); // // for(MultiPartitionedInterval currHMMInterval: currHMMStates) // { // oos.writeShort(currHMMInterval.get) // } // // oos.flush(); // oos.close(); // } // } // catch(EncoderException ex) // { // // hide it and throw it. we shouldn't run into this // // exception but i want it to hurt if we do // throw new RuntimeException(ex); // } // } // } //////////////////////////////////////////////////////////////////////////////// // read the strains from CSV BufferedInputStream strainNameInStream = new BufferedInputStream(new FileInputStream(inputCsvFile)); Set<String> strainSet = parser.parseAvailableStrainsFromStream(strainNameInStream); strainNameInStream.close(); String[] strains = strainSet.toArray(new String[strainSet.size()]); Arrays.sort(strains); File strainNamesOutputFile = new File(outputDirectory, STRAIN_NAMES_FILENAME); if (strainNamesOutputFile.exists()) { // confirm that the strain names match up FlatFileReader ffr = new FlatFileReader(new FileReader(strainNamesOutputFile), CommonFlatFileFormat.CSV_UNIX); Set<String> existingStrains = new HashSet<String>(Arrays.asList(ffr.readRow())); if (!strainSet.equals(existingStrains)) { throw new IOException("Strain sets should match across all chromosome " + "files, but [" + SequenceUtilities.toString(strainSet, ", ") + "] does not match [" + SequenceUtilities.toString(existingStrains, ", ") + "]."); } } else { // write the strains to CSV FlatFileWriter ffw = new FlatFileWriter(new FileWriter(strainNamesOutputFile), CommonFlatFileFormat.CSV_UNIX); ffw.writeRow(strains); ffw.flush(); ffw.close(); } }
From source file:Main.java
static <E> Set<E> ungrowableSet(final Set<E> s) { return new Set<E>() { @Override/* w w w . j a v a2 s. com*/ public int size() { return s.size(); } @Override public boolean isEmpty() { return s.isEmpty(); } @Override public boolean contains(Object o) { return s.contains(o); } @Override public Object[] toArray() { return s.toArray(); } @Override public <T> T[] toArray(T[] a) { return s.toArray(a); } @Override public String toString() { return s.toString(); } @Override public Iterator<E> iterator() { return s.iterator(); } @Override public boolean equals(Object o) { return s.equals(o); } @Override public int hashCode() { return s.hashCode(); } @Override public void clear() { s.clear(); } @Override public boolean remove(Object o) { return s.remove(o); } @Override public boolean containsAll(Collection<?> coll) { return s.containsAll(coll); } @Override public boolean removeAll(Collection<?> coll) { return s.removeAll(coll); } @Override public boolean retainAll(Collection<?> coll) { return s.retainAll(coll); } @Override public boolean add(E o) { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends E> coll) { throw new UnsupportedOperationException(); } }; }
From source file:ca.uhn.fhir.rest.server.RestfulServerUtils.java
public static void configureResponseParser(RequestDetails theRequestDetails, IParser parser) { // Pretty print boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theRequestDetails.getServer(), theRequestDetails);/* w w w. j av a2 s. c om*/ parser.setPrettyPrint(prettyPrint); parser.setServerBaseUrl(theRequestDetails.getFhirServerBase()); // Summary mode Set<SummaryEnum> summaryMode = RestfulServerUtils.determineSummaryMode(theRequestDetails); // _elements Set<String> elements = ElementsParameter.getElementsValueOrNull(theRequestDetails); if (elements != null && summaryMode != null && !summaryMode.equals(Collections.singleton(SummaryEnum.FALSE))) { throw new InvalidRequestException("Cannot combine the " + Constants.PARAM_SUMMARY + " and " + Constants.PARAM_ELEMENTS + " parameters"); } Set<String> elementsAppliesTo = null; if (elements != null && isNotBlank(theRequestDetails.getResourceName())) { elementsAppliesTo = Collections.singleton(theRequestDetails.getResourceName()); } if (summaryMode != null) { if (summaryMode.contains(SummaryEnum.COUNT)) { parser.setEncodeElements(Collections.singleton("Bundle.total")); } else if (summaryMode.contains(SummaryEnum.TEXT)) { parser.setEncodeElements(TEXT_ENCODE_ELEMENTS); } else { parser.setSuppressNarratives(summaryMode.contains(SummaryEnum.DATA)); parser.setSummaryMode(summaryMode.contains(SummaryEnum.TRUE)); } } if (elements != null && elements.size() > 0) { Set<String> newElements = new HashSet<String>(); for (String next : elements) { newElements.add("*." + next); } parser.setEncodeElements(newElements); parser.setEncodeElementsAppliesToResourceTypes(elementsAppliesTo); } }
From source file:com.streamsets.datacollector.validation.ValidationUtil.java
/** * Validate given stage configuration./*from ww w.j av a2s . c o m*/ */ public static boolean validateStageConfiguration(StageLibraryTask stageLibrary, boolean shouldBeSource, StageConfiguration stageConf, boolean notOnMainCanvas, IssueCreator issueCreator, boolean isPipelineFragment, Map<String, Object> constants, List<Issue> issues) { boolean preview = true; StageDefinition stageDef = stageLibrary.getStage(stageConf.getLibrary(), stageConf.getStageName(), false); if (stageDef == null) { // stage configuration refers to an undefined stage definition issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0006, stageConf.getLibrary(), stageConf.getStageName(), stageConf.getStageVersion())); preview = false; } else { if (shouldBeSource) { if (stageDef.getType() != StageType.SOURCE && !isPipelineFragment) { // first stage must be a Source issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0003)); preview = false; } } else { if (!stageLibrary.isMultipleOriginSupported() && stageDef.getType() == StageType.SOURCE) { // no stage other than first stage can be a Source issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0004)); preview = false; } } if (!stageConf.isSystemGenerated() && !TextUtils.isValidName(stageConf.getInstanceName())) { // stage instance name has an invalid name (it must match '[0-9A-Za-z_]+') issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0016, TextUtils.VALID_NAME)); preview = false; } // Hidden stages can't appear on the main canvas if (!notOnMainCanvas && !stageDef.getHideStage().isEmpty()) { issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0037)); preview = false; } for (String lane : stageConf.getInputLanes()) { if (!TextUtils.isValidName(lane)) { // stage instance input lane has an invalid name (it must match '[0-9A-Za-z_]+') issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0017, lane, TextUtils.VALID_NAME)); preview = false; } } for (String lane : stageConf.getOutputLanes()) { if (!TextUtils.isValidName(lane)) { // stage instance output lane has an invalid name (it must match '[0-9A-Za-z_]+') issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0018, lane, TextUtils.VALID_NAME)); preview = false; } } for (String lane : stageConf.getEventLanes()) { if (!TextUtils.isValidName(lane)) { // stage instance output lane has an invalid name (it must match '[0-9A-Za-z_]+') issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0100, lane, TextUtils.VALID_NAME)); preview = false; } } // Validate proper input/output lane configuration switch (stageDef.getType()) { case SOURCE: if (!stageConf.getInputLanes().isEmpty()) { // source stage cannot have input lanes issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0012, stageDef.getType(), stageConf.getInputLanes())); preview = false; } if (!stageDef.isVariableOutputStreams()) { // source stage must match the output stream defined in StageDef if (stageDef.getOutputStreams() != stageConf.getOutputLanes().size()) { issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0015, stageDef.getOutputStreams(), stageConf.getOutputLanes().size())); } } else if (stageConf.getOutputLanes().isEmpty()) { // source stage must have at least one output lane issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0032)); } break; case PROCESSOR: if (!notOnMainCanvas && stageConf.getInputLanes().isEmpty() && !isPipelineFragment) { // processor stage must have at least one input lane issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0014, "Processor")); preview = false; } if (!notOnMainCanvas) { if (!stageDef.isVariableOutputStreams()) { // processor stage must match the output stream defined in StageDef if (stageDef.getOutputStreams() != stageConf.getOutputLanes().size()) { issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0015, stageDef.getOutputStreams(), stageConf.getOutputLanes().size())); } } else if (stageConf.getOutputLanes().isEmpty()) { // processor stage must have at least one output lane issues.add( issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0032)); } } break; case EXECUTOR: case TARGET: // Normal target stage must have at least one input lane if (!notOnMainCanvas && stageConf.getInputLanes().isEmpty() && !isPipelineFragment) { issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0014, "Target")); preview = false; } // Error/Stats/Pipeline lifecycle must not have an input lane if (notOnMainCanvas && !stageConf.getInputLanes().isEmpty()) { issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0012, "Error/Stats/Lifecycle", stageConf.getInputLanes())); preview = false; } if (!stageConf.getOutputLanes().isEmpty()) { // target stage cannot have output lanes issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0013, stageDef.getType(), stageConf.getOutputLanes())); preview = false; } if (notOnMainCanvas && !stageConf.getEventLanes().isEmpty()) { issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0036, stageDef.getType(), stageConf.getEventLanes())); preview = false; } break; default: throw new IllegalStateException("Unexpected stage type " + stageDef.getType()); } // Validate proper event configuration if (stageConf.getEventLanes().size() > 1) { issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0101)); preview = false; } if (!stageDef.isProducingEvents() && stageConf.getEventLanes().size() > 0) { issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0102)); preview = false; } // Validate stage owns configuration preview &= validateComponentConfigs(stageConf, stageDef.getConfigDefinitions(), stageDef.getConfigDefinitionsMap(), stageDef.getHideConfigs(), stageDef.hasPreconditions(), constants, issueCreator, issues); // Validate service definitions Set<String> expectedServices = stageDef.getServices().stream() .map(service -> service.getService().getName()).collect(Collectors.toSet()); Set<String> configuredServices = stageConf.getServices().stream() .map(service -> service.getService().getName()).collect(Collectors.toSet()); if (!expectedServices.equals(configuredServices)) { issues.add(issueCreator.create(stageConf.getInstanceName(), ValidationError.VALIDATION_0200, StringUtils.join(expectedServices, ","), StringUtils.join(configuredServices, ","))); preview = false; } else { // Validate all services for (ServiceConfiguration serviceConf : stageConf.getServices()) { ServiceDefinition serviceDef = stageLibrary.getServiceDefinition(serviceConf.getService(), false); preview &= validateComponentConfigs(serviceConf, serviceDef.getConfigDefinitions(), serviceDef.getConfigDefinitionsMap(), Collections.emptySet(), false, constants, issueCreator.forService(serviceConf.getService().getName()), issues); } } } return preview; }
From source file:com.cgrunge.ParameterValidator.java
public boolean isSetEmpty(Set<Object> obj) { return obj.equals(Collections.<Object>emptySet()); }
From source file:edu.umich.flowfence.service.NamespaceSharedPrefs.java
public static NamespaceSharedPrefs get(SharedPreferences basePrefs, String taintSetNamespace, String... taintNamespaces) { Objects.requireNonNull(taintSetNamespace); taintNamespaces = ArrayUtils.nullToEmpty(taintNamespaces); if (taintNamespaces.length == 0) { throw new IllegalArgumentException("Need at least one taint namespace!"); }/*ww w. j ava2 s .c om*/ Set<String> taintNamespaceSet = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(taintNamespaces))); if (taintNamespaceSet.contains(taintSetNamespace)) { throw new IllegalArgumentException("Taint set namespace also a taint namespace"); } synchronized (g_mPrefsLookup) { NamespaceSharedPrefs prefsStrong = null; WeakReference<NamespaceSharedPrefs> prefsWeak = g_mPrefsLookup.get(basePrefs); if (prefsWeak != null) { prefsStrong = prefsWeak.get(); } if (prefsStrong != null) { if (!taintSetNamespace.equals(prefsStrong.mTaintSetNamespace) || !taintNamespaceSet.equals(prefsStrong.mTaintNamespaces)) { Log.w(TAG, String.format( "Inconsistent initialization: " + "initialized with TS=%s T=%s, retrieved with TS=%s T=%s", prefsStrong.mTaintSetNamespace, prefsStrong.mTaintNamespaces, taintSetNamespace, taintNamespaceSet)); } } else { prefsStrong = new NamespaceSharedPrefs(basePrefs, taintSetNamespace, taintNamespaceSet); prefsWeak = new WeakReference<>(prefsStrong); g_mPrefsLookup.put(basePrefs, prefsWeak); } return prefsStrong; } }
From source file:edu.umass.cs.reconfiguration.reconfigurationutils.ConsistentNodeConfig.java
private synchronized boolean refresh() { Set<NodeIDType> curActives = this.nodeConfig.getNodeIDs(); if (curActives.equals(this.nodes)) return false; this.nodes = (curActives); this.CH.refresh(curActives); return true;//from w ww . j a v a 2 s .com }
From source file:org.gradle.api.internal.project.antbuilder.AntBuilderDelegate.java
private void taskdef(Map<String, String> args) { Set<String> argNames = args.keySet(); if (argNames.equals(ImmutableSet.of("name", "classname"))) { try {/*from w w w. ja va2 s. co m*/ String name = args.get("name"); String className = args.get("classname"); addTaskDefinition(name, className); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } } else if (argNames.equals(Collections.singleton("resource"))) { InputStream instr = antlibClassLoader.getResourceAsStream(args.get("resource")); try { Node xml = new XmlParser().parse(instr); for (Object taskdefObject : (NodeList) xml.get("taskdef")) { Node taskdef = (Node) taskdefObject; String name = (String) taskdef.get("@name"); String className = (String) taskdef.get("@classname"); addTaskDefinition(name, className); } } catch (Exception ex) { throw UncheckedException.throwAsUncheckedException(ex); } finally { IOUtils.closeQuietly(instr); } } else { throw new RuntimeException("Unsupported parameters for taskdef(): " + args); } }
From source file:edu.uci.ics.asterix.optimizer.rules.typecast.StaticTypeCastUtil.java
/** * Determine if two types are compatible * /* w w w . ja va 2s . c o m*/ * @param reqType * the required type * @param inputType * the input type * @return true if the two types are compatible; false otherwise */ public static boolean compatible(IAType reqType, IAType inputType) { if (reqType.getTypeTag() == ATypeTag.ANY || inputType.getTypeTag() == ATypeTag.ANY) { return true; } if (reqType.getTypeTag() != ATypeTag.UNION && inputType.getTypeTag() != ATypeTag.UNION) { if (reqType.equals(inputType)) { return true; } else { return false; } } Set<IAType> reqTypePossible = new HashSet<IAType>(); Set<IAType> inputTypePossible = new HashSet<IAType>(); if (reqType.getTypeTag() == ATypeTag.UNION) { AUnionType unionType = (AUnionType) reqType; reqTypePossible.addAll(unionType.getUnionList()); } else { reqTypePossible.add(reqType); } if (inputType.getTypeTag() == ATypeTag.UNION) { AUnionType unionType = (AUnionType) inputType; inputTypePossible.addAll(unionType.getUnionList()); } else { inputTypePossible.add(inputType); } return reqTypePossible.equals(inputTypePossible); }
From source file:ubic.pubmedgate.resolve.depreciated.BagOfWordsResolver.java
public boolean matches(String a, String b) { Set<String> aBagOfWords = makeBagOfWords(a); Set<String> bBagOfWords = makeBagOfWords(b); return aBagOfWords.equals(bBagOfWords); }