List of usage examples for java.util SortedSet contains
boolean contains(Object o);
From source file:de.shadowhunt.sonar.plugins.ignorecode.model.IssuePatternTest.java
@Test public void testAddLines() throws Exception { final SortedSet<Integer> lines = new TreeSet<>(); IssuePattern.addLines(lines, 2, 2);//from w w w .j a va 2 s .co m IssuePattern.addLines(lines, 4, 6); final IssuePattern pattern = new IssuePattern("resourcePattern", "rulePattern", lines); final SortedSet<Integer> full = pattern.getLines(); Assert.assertNotNull("SortedSet must not be null", full); Assert.assertEquals("SortedSet must contain the exact number of entries", 4, full.size()); Assert.assertTrue("SortedSet must contain line 2", full.contains(2)); Assert.assertTrue("SortedSet must contain line 4", full.contains(4)); Assert.assertTrue("SortedSet must contain line 5", full.contains(5)); Assert.assertTrue("SortedSet must contain line 6", full.contains(6)); }
From source file:de.shadowhunt.sonar.plugins.ignorecode.model.IssuePatternTest.java
@Test public void testParseLineRange() throws Exception { final IssuePattern pattern = IssuePattern.parseLine("resourcePattern;rulePattern;[2-6]"); Assert.assertEquals("resourcePattern name must match", "resourcePattern", pattern.getResourcePattern()); Assert.assertEquals("rulePattern name must match", "rulePattern", pattern.getRulePattern()); final SortedSet<Integer> full = pattern.getLines(); Assert.assertNotNull("SortedSet must not be null", full); Assert.assertEquals("SortedSet must contain the exact number of entries", 5, full.size()); Assert.assertTrue("SortedSet must contain line 2", full.contains(2)); Assert.assertTrue("SortedSet must contain line 3", full.contains(3)); Assert.assertTrue("SortedSet must contain line 4", full.contains(4)); Assert.assertTrue("SortedSet must contain line 5", full.contains(5)); Assert.assertTrue("SortedSet must contain line 6", full.contains(6)); }
From source file:org.LexGrid.LexBIG.example.ScoreTerm.java
/** * Returns a score providing a relative comparison of the first set of words * against the second./*w w w . j a v a 2s . com*/ * <p> * Currently the score is evaluated as a simple percentage based on number * of words in the first set that are also in the second (order * independent). This could be enhanced to take order into account, etc. * * @param wordsToCompare * @param wordsToCompareAgainst * @return The score (a percentage); a higher value indicates a stronger * match. */ protected float score(SortedSet wordsToCompare, SortedSet wordsToCompareAgainst) { int totalWords = wordsToCompare.size(); int matchWords = 0; for (Iterator words = wordsToCompare.iterator(); words.hasNext();) { String word = words.next().toString(); if (wordsToCompareAgainst.contains(word)) matchWords++; } return ((float) matchWords / (float) totalWords) * 100; }
From source file:org.jraf.android.cinetoday.mobile.api.Api.java
@VisibleForTesting static void parseMovieList(@NonNull SortedSet<Movie> movies, String jsonStr, String theaterName, int position, Date date) throws ParseException { try {//from ww w. j a va 2s.co m JSONObject jsonRoot = new JSONObject(jsonStr); JSONObject jsonFeed = jsonRoot.getJSONObject("feed"); JSONArray jsonTheaterShowtimes = jsonFeed.getJSONArray("theaterShowtimes"); JSONObject jsonTheaterShowtime = jsonTheaterShowtimes.getJSONObject(0); JSONArray jsonMovieShowtimes = jsonTheaterShowtime.optJSONArray("movieShowtimes"); if (jsonMovieShowtimes == null) return; int len = jsonMovieShowtimes.length(); for (int i = 0; i < len; i++) { JSONObject jsonMovieShowtime = jsonMovieShowtimes.getJSONObject(i); JSONObject jsonOnShow = jsonMovieShowtime.getJSONObject("onShow"); JSONObject jsonMovie = jsonOnShow.getJSONObject("movie"); Movie movie = new Movie(); // Movie (does not include showtimes, only the movie details) MovieCodec.get().fill(movie, jsonMovie); // See if the movie was already in the set, if yes use this one, so the showtimes are merged if (movies.contains(movie)) { // Already in the set: find it for (Movie m : movies) { if (m.equals(movie)) { // Found it: discard the new one, use the old one instead movie = m; break; } } } // Showtimes ShowtimeCodec.get().fill(movie, jsonMovieShowtime, theaterName, position, date); // If there is no showtimes for today, skip the movie if (movie.todayShowtimes == null || movie.todayShowtimes.size() == 0) { Log.w("Movie %s has no showtimes: skip it", movie.id); } else { movies.add(movie); } } } catch (JSONException e) { throw new ParseException(e); } }
From source file:de.shadowhunt.sonar.plugins.ignorecode.model.CoveragePatternTest.java
@Test public void testParse() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintWriter writer = new PrintWriter(baos); writer.println("# comment"); writer.println();//from www . j av a2 s . co m writer.println("resourcePattern;[2,4-6]"); writer.close(); final InputStream is = new ByteArrayInputStream(baos.toByteArray()); try { final List<CoveragePattern> lines = CoveragePattern.parse(is); Assert.assertNotNull("List must not be null", lines); Assert.assertEquals("List must contain the exact number of entries", 1, lines.size()); final CoveragePattern pattern = lines.get(0); final SortedSet<Integer> full = pattern.getLines(); Assert.assertNotNull("SortedSet must not be null", full); Assert.assertEquals("SortedSet must contain the exact number of entries", 4, full.size()); Assert.assertTrue("SortedSet must contain line 2", full.contains(2)); Assert.assertTrue("SortedSet must contain line 4", full.contains(4)); Assert.assertTrue("SortedSet must contain line 5", full.contains(5)); Assert.assertTrue("SortedSet must contain line 6", full.contains(6)); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(baos); } }
From source file:de.shadowhunt.sonar.plugins.ignorecode.model.IssuePatternTest.java
@Test public void testParse() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintWriter writer = new PrintWriter(baos); writer.println("# comment"); writer.println();//from w ww . ja v a2 s.c o m writer.println("resourcePattern;rulePattern;[2,4-6]"); writer.close(); final InputStream is = new ByteArrayInputStream(baos.toByteArray()); try { final List<IssuePattern> lines = IssuePattern.parse(is); Assert.assertNotNull("List must not be null", lines); Assert.assertEquals("List must contain the exact number of entries", 1, lines.size()); final IssuePattern pattern = lines.get(0); Assert.assertEquals("resourcePattern name must match", "resourcePattern", pattern.getResourcePattern()); Assert.assertEquals("rulePattern name must match", "rulePattern", pattern.getRulePattern()); final SortedSet<Integer> full = pattern.getLines(); Assert.assertNotNull("SortedSet must not be null", full); Assert.assertEquals("SortedSet must contain the exact number of entries", 4, full.size()); Assert.assertTrue("SortedSet must contain line 2", full.contains(2)); Assert.assertTrue("SortedSet must contain line 4", full.contains(4)); Assert.assertTrue("SortedSet must contain line 5", full.contains(5)); Assert.assertTrue("SortedSet must contain line 6", full.contains(6)); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(baos); } }
From source file:org.zanata.client.commands.pull.RawPullCommand.java
@Override public void run() throws IOException { PullCommand.logOptions(log, getOpts()); if (getOpts().isDryRun()) { log.info("DRY RUN: no permanent changes will be made"); }//from w ww .j a va 2s . com log.warn("Using EXPERIMENTAL project type 'file'."); LocaleList locales = getOpts().getLocaleMapList(); if (locales == null) { throw new ConfigException("no locales specified"); } RawPullStrategy strat = new RawPullStrategy(); strat.setPullOptions(getOpts()); List<String> docNamesForModule = getQualifiedDocNamesForCurrentModuleFromServer(); SortedSet<String> localDocNames = new TreeSet<String>(docNamesForModule); SortedSet<String> docsToPull = localDocNames; if (getOpts().getFromDoc() != null) { if (!localDocNames.contains(getOpts().getFromDoc())) { log.error("Document with id {} not found, unable to start pull from unknown document. Aborting.", getOpts().getFromDoc()); // FIXME should this be throwing an exception to properly abort? // need to see behaviour with modules return; } docsToPull = localDocNames.tailSet(getOpts().getFromDoc()); int numSkippedDocs = localDocNames.size() - docsToPull.size(); log.info("Skipping {} document(s) before {}.", numSkippedDocs, getOpts().getFromDoc()); } // TODO compare docNamesForModule with localDocNames, offer to delete // obsolete translations from filesystem if (docsToPull.isEmpty()) { log.info("No documents in remote module: {}; nothing to do", getOpts().getCurrentModule()); return; } else { log.info("Source documents on server:"); for (String docName : localDocNames) { if (docsToPull.contains(docName)) { log.info(" {}", docName); } else { log.info("(to skip) {}", docName); } } } log.info("Pulling {} of {} docs for this module from the server", docsToPull.size(), localDocNames.size()); log.debug("Doc names: {}", localDocNames); PushPullType pullType = getOpts().getPullType(); boolean pullSrc = pullType == PushPullType.Both || pullType == PushPullType.Source; boolean pullTarget = pullType == PushPullType.Both || pullType == PushPullType.Trans; if (needToGetStatistics(pullTarget)) { log.info( "Setting minimum document completion percentage may potentially increase the processing time."); } if (pullSrc) { log.warn("Pull Type set to '" + pullType + "': existing source-language files may be overwritten/deleted"); confirmWithUser( "This will overwrite/delete any existing documents and translations in the above directories.\n"); } else { confirmWithUser("This will overwrite/delete any existing translations in the above directory.\n"); } Optional<Map<String, Map<LocaleId, TranslatedPercent>>> optionalStats = prepareStatsIfApplicable(pullTarget, locales); for (String qualifiedDocName : docsToPull) { // TODO add filtering by file type? e.g. pull all dtd documents // only. try { String localDocName = unqualifiedDocName(qualifiedDocName); if (pullSrc) { Response response; try { response = fileResourceClient.downloadSourceFile(getOpts().getProj(), getOpts().getProjectVersion(), FileResource.FILETYPE_RAW_SOURCE_DOCUMENT, qualifiedDocName); InputStream srcDoc = response.readEntity(InputStream.class); if (srcDoc != null) { try { strat.writeSrcFile(localDocName, srcDoc); } finally { srcDoc.close(); } } } catch (ResponseProcessingException e) { if (e.getResponse().getStatus() == 404) { log.warn("No source document file is available for [{}]. Skipping.", qualifiedDocName); } else { throw e; } } } if (pullTarget) { String fileExtension; if (getOpts().getIncludeFuzzy()) { fileExtension = FileResource.FILETYPE_TRANSLATED_APPROVED_AND_FUZZY; } else { fileExtension = FileResource.FILETYPE_TRANSLATED_APPROVED; } List<LocaleId> skippedLocales = Lists.newArrayList(); for (LocaleMapping locMapping : locales) { LocaleId locale = new LocaleId(locMapping.getLocale()); if (shouldPullThisLocale(optionalStats, localDocName, locale)) { pullDocForLocale(strat, qualifiedDocName, localDocName, fileExtension, locMapping, locale); } else { skippedLocales.add(locale); } } if (!skippedLocales.isEmpty()) { log.info( "Translation file for document {} for locales {} are skipped due to insufficient completed percentage", localDocName, skippedLocales); } } } catch (IOException | RuntimeException e) { log.error( "Operation failed: " + e.getMessage() + "\n\n" + " To retry from the last document, please add the option: {}\n", getOpts().buildFromDocArgument(qualifiedDocName)); throw new RuntimeException(e.getMessage(), e); } } }
From source file:hu.bme.mit.sette.common.tasks.TestSuiteRunner.java
private String getLineDivClass(int i, SortedSet<Integer> full, SortedSet<Integer> partial, SortedSet<Integer> not) { if (full.contains(i)) { return "line green"; } else if (partial.contains(i)) { return "line yellow"; } else if (not.contains(i)) { return "line red"; } else {//from ww w .j a va2s. c o m return "line"; } }
From source file:com.redhat.rhn.manager.user.CreateUserCommand.java
/** * Private helper method to validate the user's prefix. Puts errors into the * errors list.// ww w .j av a 2 s. c o m */ private void validatePrefix() { String prefix = user.getPrefix(); if (prefix != null) { // Make sure whether prefix is valid, if it is set SortedSet validPrefixes = LocalizationService.getInstance().availablePrefixes(); if (prefix.isEmpty()) { user.setPrefix(" "); } if (!validPrefixes.contains(user.getPrefix())) { errors.add(new ValidatorError("error.user_invalid_prefix", prefix, validPrefixes.toString())); } } }
From source file:org.jclouds.rackspace.cloudfiles.CloudFilesClientLiveTest.java
@Test public void testCDNOperations() throws Exception { final long minimumTTL = 60 * 60; // The minimum TTL is 1 hour // Create two new containers for testing final String containerNameWithCDN = getContainerName(); final String containerNameWithoutCDN = getContainerName(); try {//from w w w .j a v a 2s.co m try { context.getApi().disableCDN(containerNameWithCDN); context.getApi().disableCDN(containerNameWithoutCDN); } catch (Exception e) { } ContainerCDNMetadata cdnMetadata = null; // Enable CDN with PUT for one container final URI cdnUri = context.getApi().enableCDN(containerNameWithCDN); assertTrue(cdnUri != null); // Confirm CDN is enabled via HEAD request and has default TTL cdnMetadata = context.getApi().getCDNMetadata(containerNameWithCDN); assertTrue(cdnMetadata.isCDNEnabled()); assertEquals(cdnMetadata.getCDNUri(), cdnUri); final long initialTTL = cdnMetadata.getTTL(); try { cdnMetadata = context.getApi().getCDNMetadata(containerNameWithoutCDN); assert cdnMetadata == null || !cdnMetadata.isCDNEnabled() : containerNameWithoutCDN + " should not have metadata"; } catch (ContainerNotFoundException e) { } catch (HttpResponseException e) { } try { cdnMetadata = context.getApi().getCDNMetadata("DoesNotExist"); assert false : "should not exist"; } catch (ContainerNotFoundException e) { } catch (HttpResponseException e) { } // List CDN metadata for containers, and ensure all CDN info is available for enabled // container SortedSet<ContainerCDNMetadata> cdnMetadataList = context.getApi().listCDNContainers(); assertTrue(cdnMetadataList.size() >= 1); assertTrue(cdnMetadataList .contains(new ContainerCDNMetadata(containerNameWithCDN, true, initialTTL, cdnUri))); // Test listing with options cdnMetadataList = context.getApi().listCDNContainers(ListCdnContainerOptions.Builder.enabledOnly()); assertTrue(Iterables.all(cdnMetadataList, new Predicate<ContainerCDNMetadata>() { public boolean apply(ContainerCDNMetadata cdnMetadata) { return cdnMetadata.isCDNEnabled(); } })); cdnMetadataList = context.getApi() .listCDNContainers(ListCdnContainerOptions.Builder .afterMarker(containerNameWithCDN.substring(0, containerNameWithCDN.length() - 1)) .maxResults(1)); assertEquals(cdnMetadataList.size(), 1); // Enable CDN with PUT for the same container, this time with a custom TTL long ttl = 4000; context.getApi().enableCDN(containerNameWithCDN, ttl); cdnMetadata = context.getApi().getCDNMetadata(containerNameWithCDN); assertTrue(cdnMetadata.isCDNEnabled()); assertEquals(cdnMetadata.getTTL(), ttl); // Check POST by updating TTL settings ttl = minimumTTL; context.getApi().updateCDN(containerNameWithCDN, minimumTTL); cdnMetadata = context.getApi().getCDNMetadata(containerNameWithCDN); assertTrue(cdnMetadata.isCDNEnabled()); assertEquals(cdnMetadata.getTTL(), minimumTTL); // Confirm that minimum allowed value for TTL is 3600, lower values are ignored. context.getApi().updateCDN(containerNameWithCDN, 3599L); cdnMetadata = context.getApi().getCDNMetadata(containerNameWithCDN); assertEquals(cdnMetadata.getTTL(), minimumTTL); // Note that TTL is 3600 here, not 3599 // Disable CDN with POST assertTrue(context.getApi().disableCDN(containerNameWithCDN)); cdnMetadata = context.getApi().getCDNMetadata(containerNameWithCDN); assertEquals(cdnMetadata.isCDNEnabled(), false); } finally { recycleContainer(containerNameWithCDN); recycleContainer(containerNameWithoutCDN); } }