List of usage examples for java.util Set toString
public String toString()
From source file:org.apache.sqoop.connector.idf.TestCSVIntermediateDataFormat.java
public void testSetOfIntegers() { Schema schema = new Schema("test"); schema.addColumn(new org.apache.sqoop.schema.type.Set("1", new FixedPoint("fn", 2L, false))); schema.addColumn(new org.apache.sqoop.schema.type.Text("2")); dataFormat = new CSVIntermediateDataFormat(schema); Set<Integer> givenSet = new HashSet<Integer>(); givenSet.add(1);//from w w w. j a va 2 s . co m givenSet.add(3); // create an array inside the object array Object[] data = new Object[2]; data[0] = givenSet.toArray(); data[1] = "text"; dataFormat.setObjectData(data); Object[] expectedArray = (Object[]) dataFormat.getObjectData()[0]; assertEquals(givenSet.toString(), Arrays.toString(expectedArray)); assertEquals("text", dataFormat.getObjectData()[1]); }
From source file:fr.landel.utils.assertor.AssertorIterableTest.java
/** * Test method for {@link AssertorIterable#contains}. * //w ww . jav a2 s.c o m * @throws IOException * On contain */ @Test public void testDoesNotContainIterable() throws IOException { final String el1 = "element1"; final String el2 = "element2"; final Set<String> set = new HashSet<>(); final Set<String> set2 = new HashSet<>(); set.add(el1); set2.add(el1); set2.add(el2); Assertor.that(set).not().containsAll(set2).orElseThrow("iterable contains the list %s*"); Assertor.that(set, EnumAnalysisMode.STREAM).not().containsAll(set2) .orElseThrow("iterable contains the list %s*"); Assertor.that(set, EnumAnalysisMode.PARALLEL).not().containsAll(set2) .orElseThrow("iterable contains the list %s*"); set2.remove(el1); assertException(() -> { Assertor.that(set).not().containsAll(set2).orElseThrow("iterable contains the list %2$s*"); fail(ERROR); }, IllegalArgumentException.class, "iterable contains the list " + set2.toString()); assertException(() -> { Assertor.that(set).not().containsAll(set2).orElseThrow(new IOException(), true); fail(ERROR); }, IOException.class); assertException(() -> { Assertor.that(set).not().containsAll((Iterable<String>) null).orElseThrow(); fail(ERROR); }, IllegalArgumentException.class, "neither iterables can be null or empty"); assertFalse(Assertor.that(set).not().containsAll(set2).isOK()); assertFalse(Assertor.that(set).not().containsAll(set).isOK()); assertTrue(Assertor.that(set).not().containsAny(set2).isOK()); assertFalse(Assertor.that(set).not().containsAny(set).isOK()); set.clear(); assertException(() -> { Assertor.that((Iterable<String>) null).not().containsAll(set2).orElseThrow(); fail(ERROR); }, IllegalArgumentException.class, "neither iterables can be null or empty"); assertException(() -> { Assertor.that(set).not().containsAll((Iterable<String>) null).orElseThrow(); fail(ERROR); }, IllegalArgumentException.class, "neither iterables can be null or empty"); assertFalse(Assertor.that(set).not().containsAll(set2).isOK()); assertFalse(Assertor.that(set).not().containsAll(set).isOK()); assertFalse(Assertor.that(set).not().containsAny(set2).isOK()); assertFalse(Assertor.that(set).not().containsAny(set).isOK()); }
From source file:com.wizecommerce.hecuba.astyanax.AstyanaxBasedHecubaClientManager.java
@Override public CassandraResultSet<K, String> readAllColumns(Set<K> keys) throws Exception { // This method was added as part of multi-get feature for cache calls. try {//from ww w. ja va 2 s . c o m OperationResult<Rows<K, String>> result = keyspace.prepareQuery(columnFamily).getKeySlice(keys) .execute(); if (isClientAdapterDebugMessagesEnabled) { log.info("Rows retrieved from Cassandra [Astyanax] (for " + keys.size() + " keys). Exec Time " + "(micro-sec) = " + result.getLatency() / 1000 + ", Host used = " + result.getHost()); } return new AstyanaxResultSet<K, String>(result); } catch (ConnectionException e) { log.warn("HecubaClientManager [Astyanax] error while reading multiple keys. Number of keys = " + keys.size() + ", keys = " + keys.toString()); if (log.isDebugEnabled()) { log.debug("Caught Exception while reading for multiple keys", e); logDownedHosts(); } throw e; } }
From source file:org.mxupdate.eclipse.mxadapter.MXAdapter.java
/** * Updates given MX update files in the MX database. If * {@link #PREF_UPDATE_FILE_CONTENT} is set, also the file content is * transfered within the update (e.g. if an update on another server is * done).//from www .j a v a 2 s.c om * * @param _files MxUpdate file which must be updated * @param _compile if <i>true</i> all JPOs are compiled; if <i>false</i> * no JPOs are compiled, only an update is done * @throws Exception if update failed (or included connect) * @see #execMql(CharSequence) */ public void update(final List<IFile> _files, final boolean _compile) throws Exception { if (this.connector == null) { this.connect(); } // update by file content if (this.connector.isUpdateByFileContent()) { final Map<String, String> files = new HashMap<String, String>(); for (final IFile file : _files) { try { final InputStream in = new FileInputStream(file.getLocation().toFile()); final byte[] bytes = new byte[in.available()]; in.read(bytes); in.close(); files.put(file.getLocation().toString(), new String(bytes, file.getCharset())); } catch (final UnsupportedEncodingException e) { this.console.logError(Messages.getString("MXAdapter.ExceptionConvertFileContent", //$NON-NLS-1$ file.getLocation().toString()), e); } catch (final CoreException e) { this.console.logError(Messages.getString("MXAdapter.ExceptionFileCharSet", //$NON-NLS-1$ file.getLocation().toString()), e); } catch (final IOException e) { this.console.logError(Messages.getString("MXAdapter.ExceptionReadFileContentFailed", //$NON-NLS-1$ file.getLocation().toString()), e); } } try { final Map<?, ?> bck = this.executeEncoded(new String[] { "Compile", String.valueOf(_compile) }, "Update", new Object[] { "FileContents", files }); this.console.appendLog((String) bck.get(MXAdapter.RETURN_KEY_LOG)); final Exception ex = (Exception) bck.get(MXAdapter.RETURN_KEY_EXCEPTION); if (ex != null) { this.console.logError(Messages.getString("MXAdapter.ExceptionUpdateFailed", //$NON-NLS-1$ files.keySet().toString()), ex); } } catch (final Exception e) { this.console.logError(Messages.getString("MXAdapter.ExceptionUpdateFailed", //$NON-NLS-1$ files.keySet().toString()), e); } // update by file names } else { final Set<String> fileNames = new HashSet<String>(); for (final IFile file : _files) { fileNames.add(file.getLocation().toString()); } try { final Map<?, ?> bck = this.executeEncoded(new String[] { "Compile", String.valueOf(_compile) }, "Update", new Object[] { "FileNames", fileNames }); this.console.appendLog((String) bck.get(MXAdapter.RETURN_KEY_LOG)); final Exception ex = (Exception) bck.get(MXAdapter.RETURN_KEY_EXCEPTION); if (ex != null) { this.console.logError(Messages.getString("MXAdapter.ExceptionUpdateFailed", //$NON-NLS-1$ fileNames.toString()), ex); } } catch (final Exception e) { this.console.logError(Messages.getString("MXAdapter.ExceptionUpdateFailed", //$NON-NLS-1$ fileNames.toString()), e); } } }
From source file:org.dspace.harvest.OAIHarvester.java
/** * Query the OAI-PMH provider for a specific metadata record. * @param oaiSource the address of the OAI-PMH provider * @param itemOaiId the OAI identifier of the target item * @param metadataPrefix the OAI metadataPrefix of the desired metadata * @return list of JDOM elements corresponding to the metadata entries in the located record. * * @throws IOException//from w w w .ja v a 2s . c om * A general class of exceptions produced by failed or interrupted I/O operations. * @throws ParserConfigurationException XML parsing error * @throws SAXException if XML processing error * @throws TransformerException if XML transformer error * @throws HarvestingException if harvesting error */ protected List<Element> getMDrecord(String oaiSource, String itemOaiId, String metadataPrefix) throws IOException, ParserConfigurationException, SAXException, TransformerException, HarvestingException { GetRecord getRecord = new GetRecord(oaiSource, itemOaiId, metadataPrefix); Set<String> errorSet = new HashSet<String>(); // If the metadata is not available for this item, can the whole thing if (getRecord != null && getRecord.getErrors() != null && getRecord.getErrors().getLength() > 0) { for (int i = 0; i < getRecord.getErrors().getLength(); i++) { String errorCode = getRecord.getErrors().item(i).getAttributes().getNamedItem("code") .getTextContent(); errorSet.add(errorCode); } throw new HarvestingException( "OAI server returned the following errors during getDescMD execution: " + errorSet.toString()); } Document record = db.build(getRecord.getDocument()); Element root = record.getRootElement(); return root.getChild("GetRecord", OAI_NS).getChild("record", OAI_NS).getChild("metadata", OAI_NS) .getChildren(); }
From source file:com.act.reachables.LoadAct.java
private void setMetadata(Long n, Set<Integer> tox, Chemical c, String fulltxt, int fanout, int fanin) { Node.setAttribute(n, "isNative", c.isNative()); Node.setAttribute(n, "fanout", fanout); Node.setAttribute(n, "fanin", fanin); if (c.getCanon() != null) Node.setAttribute(n, "canonical", c.getCanon()); if (c.getInChI() != null) Node.setAttribute(n, "InChI", c.getInChI()); if (c.getSmiles() != null) Node.setAttribute(n, "SMILES", c.getSmiles()); if (c.getShortestName() != null) Node.setAttribute(n, "Name", c.getShortestName()); if (c.getBrendaNames() != null && c.getSynonyms() != null) Node.setAttribute(n, "Synonyms", c.getBrendaNames().toString() + c.getSynonyms().toString()); setXrefs(n, c);// w ww . ja v a 2s .co m if (fulltxt != null) Node.setAttribute(n, "fulltxt", fulltxt); if (tox != null && tox.size() > 0) { Node.setAttribute(n, "toxicity_all", tox.toString()); int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE; for (int i : tox) { max = max < i ? i : max; min = min > i ? i : min; } Node.setAttribute(n, "toxicity_min", min); Node.setAttribute(n, "toxicity_max", max); } }
From source file:gov.nih.nci.firebird.service.protocol.ProtocolServiceBeanHibernateTest.java
@Test public void testUpdateProtocol() throws ValidationException { bean.setSponsorNotificationService(mock(SponsorNotificationService.class)); InvestigatorProfile profile1 = InvestigatorProfileFactory.getInstance().create(); InvestigatorProfile profile2 = InvestigatorProfileFactory.getInstance().create(); save(sponsor, form1572Type, financialDisclosureType, profile1, profile2); Protocol protocol = makeProtocol();/*from w w w .j a v a 2 s .c om*/ AbstractProtocolRegistration registrationSubmitted = RegistrationFactory.getInstance() .createInvestigatorRegistration(profile1, protocol); registrationSubmitted.setStatus(RegistrationStatus.SUBMITTED); protocol.addRegistration(registrationSubmitted); AbstractProtocolRegistration registrationNotStarted = RegistrationFactory.getInstance() .createInvestigatorRegistration(profile2, protocol); registrationNotStarted.setStatus(RegistrationStatus.NOT_STARTED); protocol.addRegistration(registrationNotStarted); save(protocol); Protocol snapshot = protocol.createCopy(); protocol.getRegistrationConfiguration().setInvestigatorOptionality(form1572Type, FormOptionality.OPTIONAL); protocol.getRegistrationConfiguration().setInvestigatorOptionality(financialDisclosureType, FormOptionality.REQUIRED); protocol.getRegistrationConfiguration().setSubinvestigatorOptionality(form1572Type, FormOptionality.REQUIRED); protocol.setProtocolTitle("some new title"); bean.updateProtocol(snapshot, protocol, "change is good"); assertEquals(1, protocol.getRevisionHistory().size()); ProtocolRevision change = protocol.getRevisionHistory().iterator().next(); Set<String> expected = Sets.newHashSet( getPropertyText("protocol.change.title.investigator.message", snapshot.getProtocolTitle(), protocol.getProtocolTitle()), getPropertyText("protocol.change.form.optionality.investigator.investigator.message", FormTypeEnum.FORM_1572.getDisplay(), FormOptionality.REQUIRED.getDisplay(), FormOptionality.OPTIONAL.getDisplay()), getPropertyText("protocol.change.form.optionality.investigator.investigator.message", FormTypeEnum.FINANCIAL_DISCLOSURE_FORM.getDisplay(), FormOptionality.NONE.getDisplay(), FormOptionality.REQUIRED.getDisplay()), getPropertyText("protocol.change.form.optionality.subinvestigator.investigator.message", FormTypeEnum.FORM_1572.getDisplay(), FormOptionality.OPTIONAL.getDisplay(), FormOptionality.REQUIRED.getDisplay())); for (String msg : change.getInvestigatorModificationDescriptions()) { assertTrue("expected " + msg, expected.remove(msg)); } assertTrue(expected.toString(), expected.isEmpty()); assertEquals(RegistrationStatus.PROTOCOL_UPDATED, registrationSubmitted.getStatus()); assertEquals(RegistrationStatus.NOT_STARTED, registrationNotStarted.getStatus()); }
From source file:org.carrot2.source.boss.YSearchResponse.java
/** * Populate {@link SearchEngineResponse} depending on the type of the search result * returned./* www . j a v a 2 s .co m*/ * * @param response * @param requestedLanguage the language requested by the user, mapped from * {@link BossLanguageCodes} to {@link LanguageCode}. */ public void populate(SearchEngineResponse response, LanguageCode requestedLanguage) { if (webResultSet != null) { response.metadata.put(SearchEngineResponse.RESULTS_TOTAL_KEY, webResultSet.deephits); if (webResultSet.results != null) { for (WebResult result : webResultSet.results) { final Document document = new Document(result.title, result.summary, result.url); document.setField(Document.CLICK_URL, result.clickURL); try { document.setField(Document.SIZE, Long.parseLong(result.size)); } catch (NumberFormatException e) { // Ignore if cannot parse. } response.results.add(document); } } } else if (newsResultSet != null) { response.metadata.put(SearchEngineResponse.RESULTS_TOTAL_KEY, newsResultSet.deephits); if (newsResultSet.results != null) { final Set<String> unknownLanguages = Sets.newHashSet(); for (NewsResult result : newsResultSet.results) { final Document document = new Document(result.title, result.summary, result.url); document.setField(Document.CLICK_URL, result.clickURL); if (StringUtils.isNotBlank(result.source)) { document.setField(Document.SOURCES, Lists.newArrayList(result.source)); } // BOSS news returns language name as a string, but there is no list // of supported values in the documentation. It seems that the strings // are parallel to LanguageCode enum names, so we use them here. if (StringUtils.isNotBlank(result.language)) { try { document.setLanguage(LanguageCode.valueOf(result.language)); } catch (IllegalArgumentException ignored) { unknownLanguages.add(result.language); } } response.results.add(document); } // Log unknown languages, if any if (!unknownLanguages.isEmpty()) { org.slf4j.LoggerFactory.getLogger(this.getClass().getName()) .warn("Unknown language: " + unknownLanguages.toString()); } } } else if (imagesResultSet != null) { response.metadata.put(SearchEngineResponse.RESULTS_TOTAL_KEY, imagesResultSet.deephits); if (imagesResultSet.results != null) { for (ImageResult result : imagesResultSet.results) { final Document document = new Document(result.title, result.summary, result.refererURL); // We use the image's referer page as the target click for the title. document.setField(Document.CLICK_URL, result.refererClickURL); // Attach thumbnail URL. document.setField(Document.THUMBNAIL_URL, result.thumbnailURL); response.results.add(document); } } } // If language has not been set based on the response, set it based on the request if (requestedLanguage != null) { for (Document document : response.results) { if (document.getLanguage() == null) { document.setLanguage(requestedLanguage); } } } }
From source file:edu.umd.cs.buildServer.BuildServer.java
/** * Build and run tests on given project submission. * * @param projectSubmission//from w w w .j a va2s . com * the ProjectSubmission * @throws CompileFailureException * if the project can't be compiled * @throws BuilderException * @throws IOException */ private <T extends TestProperties> void buildAndTestProject(ProjectSubmission<T> projectSubmission) throws CompileFailureException, MissingConfigurationPropertyException, IOException, BuilderException { // FIXME Should throw InternalBuildServerException instead of // BuilderException // Need to differentiate between problems with test-setup and bugs in my // servers File buildDirectory = getBuildServerConfiguration().getBuildDirectory(); // Extract test properties and security policy files into build // directory TestPropertiesExtractor testPropertiesExtractor = null; try { testPropertiesExtractor = new TestPropertiesExtractor(projectSubmission.getTestSetup()); testPropertiesExtractor.extract(buildDirectory); } catch (ZipExtractorException e) { throw new BuilderException(e); } // We absolutely have to have test.properties if (!testPropertiesExtractor.extractedTestProperties()) throw new BuilderException("Test setup did not contain test.properties"); T testProperties; try { // Load test.properties File testPropertiesFile = new File(buildDirectory, "test.properties"); testProperties = (T) TestProperties.load(testPropertiesFile); } catch (Exception e) { throw new BuilderException(e.getMessage(), e); } // Set test properties in the ProjectSubmission. projectSubmission.setTestProperties(testProperties); // validate required files Set<String> requiredFiles = testProperties.getRequiredFiles(); Set<String> providedFiles = projectSubmission.getFilesInSubmission(); requiredFiles.removeAll(providedFiles); if (!requiredFiles.isEmpty()) { if (requiredFiles.size() == 1) { String missingFile = requiredFiles.iterator().next(); throw new CompileFailureException("Missing required file " + missingFile, ""); } throw new CompileFailureException("Missing required files", requiredFiles.toString()); } // Create a BuilderAndTesterFactory, based on the language specified // in the test properties file BuilderAndTesterFactory<T> builderAndTesterFactory = projectSubmission.createBuilderAndTesterFactory(); if (getDownloadOnly()) { log.error("Download only; skipping build and test"); builderAndTesterFactory.setDownloadOnly(); } builderAndTesterFactory.buildAndTest(buildDirectory, testPropertiesExtractor); }
From source file:org.sonatype.flexmojos.compiler.SwfMojo.java
@FlexCompatibility(minVersion = "3", maxVersion = "3.1") @IgnoreJRERequirement//from w w w . j av a2s . c om protected void writeResourceBundleFlex30(String[] bundles, String locale, File localePath) throws MojoExecutionException { // Dont break this method in parts, is a work around File output = getRuntimeLocaleOutputFile(locale, SWF); /* * mxmlc -locale=en_US -source-path=locale/{locale} -include-resource-bundles * =FlightReservation2,SharedResources,collections ,containers,controls,core,effects,formatters,skins,styles * -output=src/Resources_en_US.swf */ String bundlesString = Arrays.toString(bundles) // .replace("[", "") // remove start [ .replace("]", "") // remove end ] .replace(", ", ","); // remove spaces ArrayList<File> external = new ArrayList<File>(); ArrayList<File> internal = new ArrayList<File>(); ArrayList<File> merged = new ArrayList<File>(); external.addAll(asList(getGlobalDependency())); external.addAll(asList(getDependenciesPath("external"))); external.addAll(asList(getDependenciesPath("rsl"))); internal.addAll(asList(getDependenciesPath("internal"))); merged.addAll(asList(getDependenciesPath("compile"))); merged.addAll(asList(getDependenciesPath("merged"))); merged.addAll(asList(getResourcesBundles(locale))); Set<String> args = new HashSet<String>(); // args.addAll(Arrays.asList(configs)); args.add("-locale=" + locale); if (localePath != null) { args.add("-source-path=" + localePath.getAbsolutePath()); } args.add("-include-resource-bundles=" + bundlesString); args.add("-output=" + output.getAbsolutePath()); args.add("-compiler.fonts.local-fonts-snapshot=" + getFontsSnapshot().getAbsolutePath()); if (configFile != null) { args.add("-load-config=" + PathUtil.getCanonicalPath(configFile)); } else if (configFiles != null) { String separator = "="; for (File cfg : configFiles) { args.add(" -load-config" + separator + PathUtil.getCanonicalPath(cfg)); separator = "+="; } } else { args.add("-load-config="); } args.add("-external-library-path=" + toString(external)); args.add("-include-libraries=" + toString(internal)); args.add("-library-path=" + toString(merged)); getLog().debug("writeResourceBundle calling mxmlc with args: " + args.toString()); forkMxmlc(args); runMxmlc(args); projectHelper.attachArtifact(project, SWF, locale, output); }