List of usage examples for java.util SortedSet add
boolean add(E e);
From source file:com.gopivotal.cla.web.RepositoriesController.java
private SortedSet<Repository> filterAdminRepositories(SortedSet<Repository> adminRepositories, List<LinkedRepository> linkedRepositories) { Set<String> linkedRepositoryNames = new HashSet<>(); for (LinkedRepository linkedRepository : linkedRepositories) { linkedRepositoryNames.add(linkedRepository.getName().toLowerCase()); }// w w w . j a va 2s . com SortedSet<Repository> filteredAdminRepositories = new TreeSet<>(); for (Repository adminRepository : adminRepositories) { if (!linkedRepositoryNames.contains(adminRepository.getFullName().toLowerCase())) { filteredAdminRepositories.add(adminRepository); } } return filteredAdminRepositories; }
From source file:com.sillelien.dollar.DollarOperatorsRegressionTest.java
public void regression(String symbol, String operation, String variant, @NotNull List<List<var>> result) throws IOException { String filename = operation + "." + variant + ".json"; final JsonArray previous = new JsonArray(IOUtils.toString(getClass().getResourceAsStream("/" + filename))); //Use small to stop massive string creation final File file = new File("target", filename); final var current = $(result); FileUtils.writeStringToFile(file, current.jsonArray().encodePrettily()); System.out.println(file.getAbsolutePath()); SortedSet<String> typeComparison = new TreeSet<>(); SortedSet<String> humanReadable = new TreeSet<>(); for (List<var> res : result) { if (res.size() != 3) { throw new IllegalStateException(res.toString()); }/*from www .j a va 2 s .c o m*/ typeComparison.add( res.get(0).$type() + " " + operation + " " + res.get(1).$type() + " = " + res.get(2).$type()); humanReadable.add(res.get(0).toDollarScript() + " " + symbol + " " + res.get(1).toDollarScript() + " <=> " + res.get(2).toDollarScript()); } final String typesFile = operation + "." + variant + ".types.txt"; final String humanFile = operation + "." + variant + ".ds"; FileUtils.writeLines(new File("target", typesFile), typeComparison); FileUtils.writeLines(new File("target", humanFile), humanReadable); final TreeSet previousTypeComparison = new TreeSet<String>( IOUtils.readLines(getClass().getResourceAsStream("/" + typesFile))); diff("type", previousTypeComparison.toString(), typeComparison.toString()); diff("result", previous, current.jsonArray()); }
From source file:net.ageto.gyrex.persistence.jdbc.pool.internal.commands.ListPools.java
private void printPool(final PoolDefinition pool) throws BackingStoreException { printf("Pool %s", pool.getPoolId()); printf(StringUtils.EMPTY);//from w ww . j a v a 2s . co m final Properties driverProperties = pool.getDriverProperties(); if (!driverProperties.isEmpty()) { printf("Driver Properties:"); final SortedSet<String> names = new TreeSet<String>(); final Enumeration<?> propertyNames = driverProperties.propertyNames(); while (propertyNames.hasMoreElements()) { names.add((String) propertyNames.nextElement()); } for (final String key : names) { printf(" %35s: %s", key, StringUtils.trimToEmpty(driverProperties.getProperty(key))); } printf(StringUtils.EMPTY); } printf("Pool Statistics:"); final BoneCPDataSource dataSource = (BoneCPDataSource) PoolActivator.getInstance().getRegistry() .getDataSource(pool.getPoolId()); // test connectivity (this also works around a bug in BoneCP which would result in an NPE below) try { final Connection connection = dataSource.getConnection(); if (connection instanceof ConnectionHandle) { printf(" %35s: %s", "connectionTest", ((ConnectionHandle) connection).isValid(1000) ? "OK" : "NOT OK"); } else { printf(" %35s: %s", "connectionSample", connection.toString()); } connection.close(); } catch (final SQLException e) { printf(" unable to connect to pool: %s", e.getMessage()); } // total number of leased connections printf(" %35s: %d", "totalLeased", dataSource.getTotalLeased()); printf(StringUtils.EMPTY); printf("Effective Pool Config:"); final TreeMap<String, String> poolConfig = readPoolConfig(dataSource); for (final Entry<String, String> entry : poolConfig.entrySet()) { printf(" %35s: %s", entry.getKey(), entry.getValue()); } }
From source file:dollar.DollarOperatorsRegressionTest.java
public void regression(@NotNull String symbol, @NotNull String operation, @NotNull String variant, @NotNull List<List<Value>> result) throws IOException { String filename = operation + "." + variant + ".json"; final JsonArray previous = new JsonArray( new String(ByteStreams.toByteArray(getClass().getResourceAsStream("/" + filename)))); //Use small to stop massive string creation final File file = new File("target", filename); final Value current = DollarStatic.$(result); Files.write(current.jsonArray().encodePrettily(), file, Charset.forName("utf-8")); System.out.println(file.getAbsolutePath()); SortedSet<String> typeComparison = new TreeSet<>(); SortedSet<String> humanReadable = new TreeSet<>(); for (List<Value> res : result) { if (res.size() != 3) { throw new IllegalStateException(res.toString()); }/*ww w .java2s. c om*/ typeComparison.add( res.get(0).$type() + " " + operation + " " + res.get(1).$type() + " = " + res.get(2).$type()); humanReadable.add(res.get(0).toDollarScript() + " " + symbol + " " + res.get(1).toDollarScript() + " <=> " + res.get(2).toDollarScript()); } final String typesFile = operation + "." + variant + ".types.txt"; final String humanFile = operation + "." + variant + ".ds"; Files.asCharSink(new File("target", typesFile), Charset.forName("utf-8")).writeLines(typeComparison); Files.asCharSink(new File("target", humanFile), Charset.forName("utf-8")).writeLines(humanReadable); final TreeSet previousTypeComparison = new TreeSet<>(Resources .asCharSource(getClass().getResource("/" + typesFile), Charset.forName("utf-8")).readLines()); diff("type", previousTypeComparison.toString(), typeComparison.toString()); diff("result", previous, current.jsonArray()); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.scientificalArea.PublicScientificAreaSiteDA.java
private void addListTeacher(Map<String, SortedSet<Person>> teachersMap, String key, Teacher teacher) { SortedSet<Person> teachers = teachersMap.get(key); if (teachers == null) { teachers = new TreeSet<Person>( new BeanComparator("teacher", Teacher.TEACHER_COMPARATOR_BY_CATEGORY_AND_NUMBER)); teachersMap.put(key, teachers);//from ww w. ja va 2s . co m } teachers.add(teacher.getPerson()); }
From source file:de.appsolve.padelcampus.admin.controller.general.AdminGeneralModulesController.java
private Module updateNestableItemPosition(NestableItem nestableItem, Long position) { Module module = moduleDAO.findById(nestableItem.getId()); module.setPosition(position);// w w w.j av a 2 s . co m if (nestableItem.getChildren() == null) { module.setSubModules(null); } else { SortedSet<Module> subModules = new TreeSet<>(); for (NestableItem subItem : nestableItem.getChildren()) { subModules.add(updateNestableItemPosition(subItem, position++)); } module.setSubModules(subModules); } module = moduleDAO.saveOrUpdate(module); return module; }
From source file:data.io.csv.CSVDataReader.java
/** * In-memory File sorting, return as a single String * @param reader//w w w.ja v a2s . c om * @return * @throws IOException */ private Reader readAndSortLines(BufferedReader bufReader) throws IOException { // Put all the CSV in memory, in a SortedSet SortedSet<String> lineSet = new TreeSet<String>(); String inputLine; int totalCSVSize = 0; while ((inputLine = bufReader.readLine()) != null) { lineSet.add(inputLine); totalCSVSize += inputLine.length() + 1; } bufReader.close(); // Closes also dataSourceStream // Put all sorted lines in a String StringBuilder allLines = new StringBuilder(totalCSVSize); for (String line : lineSet) { allLines.append(line + "\n"); } lineSet = null; // Could help the GC if the input file is huge // Build a Java Reader from that String return new StringReader(allLines.toString()); }
From source file:io.dockstore.webservice.helpers.EntryLabelHelper.java
public T updateLabels(T entry, String labelStrings) { if (labelStrings.length() == 0) { entry.setLabels(new TreeSet<>()); } else {// w w w . j av a 2s .c om Set<String> labelStringSet = new HashSet<>( Arrays.asList(labelStrings.toLowerCase().split("\\s*,\\s*"))); final String labelStringPattern = "^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$"; // This matches the restriction on labels to 255 characters // if this is changed then the java object/mapped db schema needs to be changed final int labelMaxLength = 255; SortedSet<Label> labels = new TreeSet<>(); for (final String labelString : labelStringSet) { if (labelString.length() <= labelMaxLength && labelString.matches(labelStringPattern)) { Label label = labelDAO.findByLabelValue(labelString); if (label != null) { labels.add(label); } else { label = new Label(); label.setValue(labelString); long id = labelDAO.create(label); labels.add(labelDAO.findById(id)); } } else { throw new CustomWebApplicationException("Invalid label format", HttpStatus.SC_BAD_REQUEST); } } entry.setLabels(labels); } return entry; }
From source file:net.rrm.ehour.ui.admin.config.MainConfigBackingBean.java
@SuppressWarnings("UnusedDeclaration") public List<Locale> getAvailableLanguages() { Locale[] locales = Locale.getAvailableLocales(); Map<String, Locale> localeMap = new HashMap<>(); // remove all variants for (Locale locale : locales) { if (isTranslationsOnly() && !ArrayUtils.contains(config.getAvailableTranslations(), locale.getLanguage())) { continue; }/*from ww w. java 2s . c o m*/ if (localeMap.containsKey(locale.getLanguage()) && locale.getDisplayName().indexOf('(') != -1) { continue; } localeMap.put(locale.getLanguage(), locale); } SortedSet<Locale> localeSet = new TreeSet<>(new LocaleComparator(LocaleComparator.CompareType.LANGUAGE)); for (Locale locale : localeMap.values()) { localeSet.add(locale); } return new ArrayList<>(localeSet); }
From source file:com.jd.survey.web.settings.QuestionRowLabelController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/{id}", params = "form", produces = "text/html") public String updateForm(@PathVariable("id") Long questionId, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { try {// ww w. ja v a 2 s . co m String login = principal.getName(); User user = userService.user_findByLogin(login); Question question = surveySettingsService.question_findById(questionId); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(question.getPage().getSurveyDefinition().getId(), user) && !securityService.userBelongsToDepartment( question.getPage().getSurveyDefinition().getDepartment().getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } SortedSet<QuestionRowLabel> RowLabels = question.getRowLabels(); log.info("initial set size" + RowLabels.size()); for (int i = 1; i <= EMPTY_OPTIONS_COUNT; i++) { log.info("adding to set" + i); RowLabels.add(new QuestionRowLabel(question, (short) (question.getRowLabels().size() + i))); } question.setRowLabels(RowLabels); uiModel.addAttribute("question", question); return "settings/questionRows/update"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }