List of usage examples for java.util SortedSet size
int size();
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 w ww . j a v a2s . c o 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:org.tonguetied.datatransfer.importing.CsvImporterTest.java
/** * Test method for/* w ww . j a va 2 s . c o m*/ * {@link CsvImporter#importData(ImportParameters)}. */ public final void testImportWithIllegalAttributes() throws Exception { final String fileName = "CsvImporterTestWithIllegalAttributes"; File file = new File(TEST_DATA_DIR, fileName + "." + FormatType.csv.getDefaultFileExtension()); byte[] input = FileUtils.readFileToByteArray(file); final Importer importer = ImporterFactory.getImporter(FormatType.csv, keywordService, transferRepository); TranslationState expectedState = TranslationState.VERIFIED; ImportParameters parameters = new ImportParameters(); parameters.setData(input); parameters.setTranslationState(expectedState); parameters.setFileName(fileName); try { importer.importData(parameters); fail(); } catch (ImportException ie) { List<ImportErrorCode> errorCodes = ie.getErrorCodes(); assertEquals(3, errorCodes.size()); assertTrue(errorCodes.contains(ImportErrorCode.illegalCountry)); assertTrue(errorCodes.contains(ImportErrorCode.illegalLanguage)); assertTrue(errorCodes.contains(ImportErrorCode.illegalTranslationState)); } Keyword actual = keywordService.getKeyword("import.test.one"); assertNotNull(actual); SortedSet<Translation> translations = actual.getTranslations(); assertEquals(1, translations.size()); Object[] actualTranslations = actual.getTranslations().toArray(); Translation actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(TranslationState.UNVERIFIED, actualTranslation.getState()); assertEquals("Value 1", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.two"); assertNull(actual); actual = keywordService.getKeyword("import.test.six"); assertNull(actual); }
From source file:org.tonguetied.datatransfer.importing.CsvImporterTest.java
/** * Test method for//from w ww . j a va 2 s. c o m * {@link CsvImporter#importData(ImportParameters)}. */ public final void testImportWithUnknownAttributes() throws Exception { final String fileName = "CsvImporterTestWithUnknownAttributes"; File file = new File(TEST_DATA_DIR, fileName + "." + FormatType.csv.getDefaultFileExtension()); byte[] input = FileUtils.readFileToByteArray(file); final Importer importer = ImporterFactory.getImporter(FormatType.csv, keywordService, transferRepository); TranslationState expectedState = TranslationState.VERIFIED; ImportParameters parameters = new ImportParameters(); parameters.setData(input); parameters.setTranslationState(expectedState); parameters.setFileName(fileName); try { importer.importData(parameters); fail(); } catch (ImportException ie) { List<ImportErrorCode> errorCodes = ie.getErrorCodes(); assertEquals(3, errorCodes.size()); assertTrue(errorCodes.contains(ImportErrorCode.unknownBundle)); assertTrue(errorCodes.contains(ImportErrorCode.unknownCountry)); assertTrue(errorCodes.contains(ImportErrorCode.unknownLanguage)); } Keyword actual = keywordService.getKeyword("import.test.one"); assertNotNull(actual); SortedSet<Translation> translations = actual.getTranslations(); assertEquals(1, translations.size()); Object[] actualTranslations = actual.getTranslations().toArray(); Translation actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(TranslationState.UNVERIFIED, actualTranslation.getState()); assertEquals("Value 1", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.two"); assertNull(actual); actual = keywordService.getKeyword("import.test.six"); assertNull(actual); }
From source file:com.appeligo.showfiles.FilesByTime.java
/** * @param request// w w w. j a v a 2 s . c o m * @param out * @param path */ private void listFiles(HttpServletRequest request, PrintWriter out, String path, int limit) { header(out); Comparator<File> comparator = new Comparator<File>() { public int compare(File leftFile, File rightFile) { long leftMod = leftFile.lastModified(); long rightMod = rightFile.lastModified(); if (leftMod < rightMod) { return -1; } else if (leftMod > rightMod) { return 1; } else { return leftFile.getPath().compareTo(rightFile.getPath()); } } }; SortedSet<File> fileSet = new TreeSet<File>(comparator); addFile(fileSet, new File(path)); log.info("Total files in tree is " + fileSet.size()); if (limit > 0 && fileSet.size() > limit) { log.info("Trimming tree to limit " + limit); Iterator<File> iter = fileSet.iterator(); int toDrop = fileSet.size() - limit; for (int i = 0; i < toDrop; i++) { iter.next(); } File first = iter.next(); fileSet = fileSet.tailSet(first); } int suggestedLimit = 1000; if (limit == 0 && fileSet.size() > suggestedLimit) { out.println("That's a lot of files! There are " + fileSet.size() + " files to return.<br/>"); out.println("How about just the <a href=\"" + request.getRequestURI() + "?" + suggestedLimit + "\">last " + suggestedLimit + "</a>.<br/>"); out.println("If you really want them all, <a href=\"" + request.getRequestURI() + "?" + (fileSet.size() + suggestedLimit) + "\">click here</a>.<br/>"); } else { DateFormat dateFormat = SimpleDateFormat.getDateInstance(); DateFormat timeFormat = SimpleDateFormat.getTimeInstance(); Calendar lastDay = Calendar.getInstance(); Calendar day = Calendar.getInstance(); boolean first = true; for (File file : fileSet) { Date fileDate = new Date(file.lastModified()); day.setTime(fileDate); if (first || lastDay.get(Calendar.DAY_OF_YEAR) != day.get(Calendar.DAY_OF_YEAR)) { out.print("<b>" + dateFormat.format(fileDate) + "</b><br/>"); } String servlet = "/ShowFile"; if (file.getPath().endsWith(".flv")) { servlet = "/ShowFlv"; } out.print(timeFormat.format(fileDate) + " <a href=\"" + request.getContextPath() + servlet + file.getPath().substring(documentRoot.length()) + "\">" + file.getPath() + "</a>"); out.println("<br/>"); lastDay.setTime(fileDate); first = false; } } footer(out); }
From source file:edu.cornell.mannlib.vitro.webapp.freemarker.loader.FreemarkerTemplateLoaderTest.java
/** * @param searchTerm/* www . j av a 2s .c om*/ * template we are looking for * @param expectedHowMany * How many matches do we expect? * @param expectedBestFit * What should the best match turn out to be? * @throws IOException */ private void assertMatches(String searchTerm, int expectedHowMany, String expectedBestFitString) { Path expectedBestFit = (expectedBestFitString == null) ? null : Paths.get(expectedBestFitString); SortedSet<PathPieces> matches = runTheVisitor(searchTerm); int actualHowMany = matches.size(); Path actualBestFit = matches.isEmpty() ? null : matches.last().path; if (expectedHowMany != actualHowMany) { fail("How many results: expected " + expectedHowMany + ", but was " + actualHowMany + ": " + matches); } assertEquals("Best result", expectedBestFit, actualBestFit); }
From source file:ch.silviowangler.dox.export.DoxExporterImpl.java
private Set<DocumentClass> processDocumentClasses(Set<ch.silviowangler.dox.api.DocumentClass> documentClasses) { Set<DocumentClass> docClasses = new HashSet<>(documentClasses.size()); for (ch.silviowangler.dox.api.DocumentClass documentClass : documentClasses) { logger.debug("Processing document class {}", documentClass); try {// ww w .j av a2 s. c o m SortedSet<ch.silviowangler.dox.api.Attribute> attributes = documentService .findAttributes(documentClass); Set<Attribute> exportAttributes = Sets.newHashSetWithExpectedSize(attributes.size()); for (ch.silviowangler.dox.api.Attribute attribute : attributes) { Attribute exportAttribute = new Attribute(); BeanUtils.copyProperties(attribute, exportAttribute, new String[] { "domain" }); if (attribute.containsDomain()) { Domain domain = new Domain(attribute.getDomain().getShortName()); for (String domainValue : attribute.getDomain().getValues()) { domain.getValues().add(domainValue); } exportAttribute.setDomain(domain); } exportAttributes.add(exportAttribute); } docClasses.add(new DocumentClass(exportAttributes, documentClass.getShortName())); } catch (DocumentClassNotFoundException e) { logger.error("Unexpected error. That document class must exist {}", documentClass, e); } } return docClasses; }
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 ww w . ja v a 2s .com 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:pivotal.au.se.gemfirexdweb.controller.CreateIndexController.java
@RequestMapping(value = "/createindex", method = RequestMethod.POST) public String createIndexAction(@ModelAttribute("indexAttribute") NewIndex indexAttribute, Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {//from w w w .j av a 2s . c o m Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } logger.debug("Received request to action an event for create index"); String tabName = indexAttribute.getTableName(); String schema = indexAttribute.getSchemaName(); String unique = indexAttribute.getUnique(); String idxName = indexAttribute.getIndexName(); String submit = request.getParameter("pSubmit"); String[] selectedColumns = request.getParameterValues("selected_column[]"); String[] indexOrder = request.getParameterValues("idxOrder[]"); String[] position = request.getParameterValues("position[]"); logger.debug("selectedColumns = " + Arrays.toString(selectedColumns)); logger.debug("indexOrder = " + Arrays.toString(indexOrder)); logger.debug("position = " + Arrays.toString(position)); IndexDAO indexDAO = GemFireXDWebDAOFactory.getIndexDAO(); List<IndexColumn> columns = indexDAO.retrieveIndexColumns(schema, tabName, (String) session.getAttribute("user_key")); StringBuffer createIndex = new StringBuffer(); if (unique.equalsIgnoreCase("Y")) { createIndex.append("create unique index " + idxName + " on " + schema + "." + tabName + " "); } else { createIndex.append("create index " + idxName + " on " + schema + "." + tabName + " "); } createIndex.append("("); if (selectedColumns != null) { int i = 0; Map<String, IndexDefinition> cols = new HashMap<String, IndexDefinition>(); for (String column : selectedColumns) { String columnName = column.substring(0, column.indexOf("_")); String index = column.substring(column.indexOf("_") + 1); String pos = position[Integer.parseInt(index) - 1]; if (pos.trim().length() == 0) { pos = "" + i; } logger.debug("Column = " + columnName + ", indexOrder = " + indexOrder[Integer.parseInt(index) - 1] + ", position = " + pos); IndexDefinition idxDef = new IndexDefinition(columnName, indexOrder[Integer.parseInt(index) - 1]); cols.put("" + pos, idxDef); i++; } // sort map and create index now SortedSet<String> keys = new TreeSet<String>(cols.keySet()); int length = keys.size(); i = 0; for (String key : keys) { IndexDefinition idxDefTemp = cols.get(key); if (i == (length - 1)) { createIndex.append(idxDefTemp.getColumnName() + " " + idxDefTemp.getOrderType() + ")"); } else { createIndex.append(idxDefTemp.getColumnName() + " " + idxDefTemp.getOrderType() + ", "); } i++; } } if (!checkIfParameterEmpty(request, "caseSensitive")) { createIndex.append(" " + request.getParameter("caseSensitive") + "\n"); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating index as -> " + createIndex.toString()); result = GemFireXDWebDAOUtil.runCommand(createIndex.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); model.addAttribute("tabName", tabName); model.addAttribute("tableSchemaName", schema); model.addAttribute("columns", columns); model.addAttribute("schema", schema); session.removeAttribute("numColumns"); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Index SQL as follows as -> " + createIndex.toString()); model.addAttribute("sql", createIndex.toString()); model.addAttribute("tabName", tabName); model.addAttribute("tableSchemaName", schema); model.addAttribute("columns", columns); model.addAttribute("schema", schema); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, idxName)); ServletOutputStream out = response.getOutputStream(); out.println(createIndex.toString()); out.close(); return null; } // This will resolve to /WEB-INF/jsp/create-index.jsp return "create-index"; }
From source file:org.bibsonomy.recommender.tags.meta.TagsFromFirstWeightedBySecondTagRecommender.java
@Override protected void addRecommendedTagsInternal(final Collection<RecommendedTag> recommendedTags, final Post<? extends Resource> post) { if (firstTagRecommender == null || secondTagRecommender == null) { throw new IllegalArgumentException("No tag recommenders available."); }/*w w w. j av a 2s . co m*/ /* * Get recommendation from first recommender. */ final SortedSet<RecommendedTag> firstRecommendedTags = firstTagRecommender.getRecommendedTags(post); log.debug("got " + firstRecommendedTags.size() + " recommendations from " + firstTagRecommender); if (log.isDebugEnabled()) { log.debug(firstRecommendedTags); } /* * Get recommendation from second tag recommender. * * Since we need to get the scores from this recommender for the tags from the first * recommender, we use the TopTagsMapBackedSet, such that we can easily get tags by their name. * Additionally, we might need to fill up the tags with the top tags (according to * the RecommendedTagComparator) from the second recommender. We get those from the * TopTagsMapBackedSet, too. */ final TopTagsMapBackedSet secondRecommendedTags = new TopTagsMapBackedSet(numberOfTagsToRecommend); secondTagRecommender.addRecommendedTags(secondRecommendedTags, post); log.debug("got " + secondRecommendedTags.size() + " recommendations from " + secondTagRecommender); /* * The scores from the tags in the next 'fill up round' should be lower * as the scores from this 'round'. Thus, we find the smallest value */ final double minScore = doFirstRound(recommendedTags, firstRecommendedTags, secondRecommendedTags); log.debug("used " + recommendedTags.size() + " tags from the first recommender which occured in second recommender"); final int ctr = doSecondRound(recommendedTags, firstRecommendedTags, secondRecommendedTags, minScore); log.debug("used another " + ctr + " tags from the first recommender "); /* * If we have not enough tags, yet, add tags from second until set is complete. */ if (recommendedTags.size() < numberOfTagsToRecommend) { /* * we want to get the top tags, not ordered alphabetically! */ final SortedSet<RecommendedTag> topRecommendedTags = secondRecommendedTags.getTopTags(); doThirdRound(recommendedTags, topRecommendedTags, minScore, recommendedTags.size()); } if (log.isDebugEnabled()) { log.debug("final recommendation: " + recommendedTags); } }
From source file:org.tonguetied.datatransfer.importing.CsvImporterTest.java
/** * Test method for//from ww w . j av a 2 s . c o m * {@link CsvImporter#importData(ImportParameters)}. */ public final void testImportData() throws Exception { final String fileName = "CsvImporterTest"; File file = new File(TEST_DATA_DIR, fileName + "." + FormatType.csv.getDefaultFileExtension()); byte[] input = FileUtils.readFileToByteArray(file); final Importer importer = ImporterFactory.getImporter(FormatType.csv, keywordService, transferRepository); TranslationState expectedState = TranslationState.VERIFIED; ImportParameters parameters = new ImportParameters(); parameters.setData(input); parameters.setTranslationState(expectedState); parameters.setFileName(fileName); importer.importData(parameters); Keyword actual = keywordService.getKeyword("import.test.one"); assertNotNull(actual); SortedSet<Translation> translations = actual.getTranslations(); assertEquals(1, translations.size()); Object[] actualTranslations = actual.getTranslations().toArray(); Translation actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(TranslationState.UNVERIFIED, actualTranslation.getState()); assertEquals("Value 1", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.two"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(TranslationState.UNVERIFIED, actualTranslation.getState()); assertNull(actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.three"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(TranslationState.UNVERIFIED, actualTranslation.getState()); assertEquals("new value 3", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.four"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(TranslationState.UNVERIFIED, actualTranslation.getState()); assertEquals("a line break\nin the value", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.five"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(2, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(TranslationState.UNVERIFIED, actualTranslation.getState()); assertEquals("some text, with ! reserved chars # \"all, good\"", actualTranslation.getValue()); }