Example usage for java.util SortedSet add

List of usage examples for java.util SortedSet add

Introduction

In this page you can find the example usage for java.util SortedSet add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:com.jd.survey.service.settings.SurveySettingsService.java

@Transactional(readOnly = false)
public Question question_updateRowLabels(Question question) {
    Long questionId = question.getId();
    Question q = questionDAO.findById(questionId);
    questionRowLabelDAO.deleteByQuestionId(questionId);
    SortedSet<QuestionRowLabel> options = new TreeSet<QuestionRowLabel>();
    for (QuestionRowLabel rowLabel : question.getRowLabelsList()) {

        if (rowLabel.getLabel() != null && rowLabel.getLabel().trim().length() > 0) {
            QuestionRowLabel questionRowLabel = new QuestionRowLabel(q, rowLabel.getOrder(),
                    rowLabel.getLabel());
            questionRowLabel = questionRowLabelDAO.merge(questionRowLabel);
            options.add(questionRowLabel);
        }//from   w  w  w. j av a 2s  .  c o m
    }
    q.setRowLabels(options);
    return questionDAO.merge(q);
}

From source file:com.devnexus.ting.web.controller.admin.AdminController.java

@RequestMapping("/s/admin/{eventKey}/download-rejected-speakers")
public void downloadRejectedSpeakersForEvent(@PathVariable("eventKey") String eventKey,
        HttpServletResponse response) throws IOException {

    final Event event = businessService.getEventByEventKey(eventKey);

    final String csvFileName = event.getEventKey() + "-rejected-speakers.csv";

    response.setContentType("text/csv");

    final String headerKey = "Content-Disposition";
    final String headerValue = String.format("attachment; filename=\"%s\"", csvFileName);
    response.setHeader(headerKey, headerValue);

    final List<CfpSubmission> cfpSubmissions = businessService.getCfpSubmissions(event.getId());
    final SortedSet<CsvRejectedSpeakerBean> rejectedSpeakers = new TreeSet<>();

    final List<Presentation> presentations = businessService
            .getPresentationsForEventOrderedByName(event.getId());

    for (CfpSubmission cfpSubmission : cfpSubmissions) {

        if (CfpSubmissionStatusType.REJECTED.equals(cfpSubmission.getStatus())) {

            for (CfpSubmissionSpeaker cfpSubmissionSpeaker : cfpSubmission.getCfpSubmissionSpeakers()) {

                boolean speakerAlreadyAccepted = speakerAlreadyAccepted(presentations, cfpSubmissionSpeaker);

                if (!speakerAlreadyAccepted) {

                    final CsvRejectedSpeakerBean rejectedSpeaker = new CsvRejectedSpeakerBean();
                    rejectedSpeaker.setEmail(cfpSubmissionSpeaker.getEmail().trim().toLowerCase());
                    rejectedSpeaker.setFirstName(cfpSubmissionSpeaker.getFirstName().trim().toLowerCase());
                    rejectedSpeaker.setLastName(cfpSubmissionSpeaker.getLastName().trim().toLowerCase());
                    rejectedSpeaker.setLocation(cfpSubmissionSpeaker.getLocation());
                    rejectedSpeaker.setPhone(cfpSubmissionSpeaker.getPhone());
                    rejectedSpeaker.setReimburseTravel(cfpSubmissionSpeaker.isMustReimburseTravelCost());
                    rejectedSpeaker.setTwitterId(cfpSubmissionSpeaker.getTwitterId());

                    rejectedSpeakers.add(rejectedSpeaker);
                }//from  ww w. j a v a  2s  .c  om

            }

        }

    }

    ICsvBeanWriter beanWriter = null;
    try {
        beanWriter = new CsvBeanWriter(response.getWriter(), CsvPreference.STANDARD_PREFERENCE);

        final String[] header = new String[] { "firstName", "lastName", "email", "twitterId", "phone",
                "reimburseTravel", "location" };

        final CellProcessor[] processors = CsvRejectedSpeakerBean.getProcessors();

        beanWriter.writeHeader(header);

        for (final CsvRejectedSpeakerBean rejectedSpeaker : rejectedSpeakers) {
            beanWriter.write(rejectedSpeaker, header, processors);
        }

    } finally {
        if (beanWriter != null) {
            beanWriter.close();
        }
    }
}

From source file:com.jd.survey.service.settings.SurveySettingsService.java

@Transactional(readOnly = false)
public Question question_updateColumnLabels(Question question) {
    Long questionId = question.getId();
    Question q = questionDAO.findById(questionId);
    questionColumnLabelDAO.deleteByQuestionId(questionId);
    SortedSet<QuestionColumnLabel> options = new TreeSet<QuestionColumnLabel>();
    for (QuestionColumnLabel columnLabel : question.getColumnLabelsList()) {

        if (columnLabel.getLabel() != null && columnLabel.getLabel().trim().length() > 0) {
            QuestionColumnLabel questionColumnLabel = new QuestionColumnLabel(q, columnLabel.getOrder(),
                    columnLabel.getLabel());
            questionColumnLabel = questionColumnLabelDAO.merge(questionColumnLabel);
            options.add(questionColumnLabel);
        }/* w w w. ja v a 2  s  .co  m*/
    }
    q.setColumnLabels(options);
    return questionDAO.merge(q);
}

From source file:com.jd.survey.service.settings.SurveySettingsService.java

@Transactional(readOnly = false)
public SurveyDefinitionPage surveyDefinitionPage_merge(SurveyDefinitionPage surveyDefinitionPage) {
    SortedSet<SurveyDefinitionPage> updatedSurveyDefinitionPages = new TreeSet<SurveyDefinitionPage>();
    Long AppTypeId = surveyDefinitionPage.getSurveyDefinition().getId();
    SurveyDefinition surveyDefinition = surveyDefinitionDAO.findById(AppTypeId);
    surveyDefinitionPage.setSurveyDefinition(surveyDefinition);
    Short order = surveyDefinition.updateSet(surveyDefinition.getPages(), surveyDefinitionPage).getOrder();
    for (SurveyDefinitionPage atp : surveyDefinition.getPages()) {
        updatedSurveyDefinitionPages.add(surveyDefinitionPageDAO.merge(atp));
    }//from ww  w.j  av a2s.  c om
    surveyDefinition.setPages(updatedSurveyDefinitionPages);
    surveyDefinition = surveyDefinitionDAO.merge(surveyDefinition);
    return surveyDefinition.getElement(surveyDefinition.getPages(), order);
}

From source file:com.atlassian.connector.eclipse.internal.subclipse.ui.SubclipseTeamUiResourceConnector.java

@NotNull
public SortedSet<ICustomChangesetLogEntry> getLatestChangesets(@NotNull String repositoryUrl, int limit,
        IProgressMonitor monitor) throws CoreException {

    SubMonitor submonitor = SubMonitor.convert(monitor, "Retrieving changesets for " + repositoryUrl, 8);

    ISVNRepositoryLocation location = getRepositoryLocation(repositoryUrl, submonitor.newChild(1));
    if (location == null) {
        throw new CoreException(new Status(IStatus.ERROR, AtlassianSubclipseCorePlugin.PLUGIN_ID,
                NLS.bind("Could not get repository location for {0}", repositoryUrl)));
    }/*from   w  ww .  j a  va 2s .co m*/

    SortedSet<ICustomChangesetLogEntry> changesets = new TreeSet<ICustomChangesetLogEntry>();
    ISVNRemoteFolder rootFolder = location.getRootFolder();

    if (limit > 0) { //do not retrieve unlimited revisions
        GetLogsCommand getLogsCommand = new GetLogsCommand(rootFolder, SVNRevision.HEAD, SVNRevision.HEAD,
                new SVNRevision.Number(0), false, limit, null, true);
        try {
            getLogsCommand.run(submonitor.newChild(5));

            ILogEntry[] logEntries = getLogsCommand.getLogEntries();

            submonitor.setWorkRemaining(logEntries.length);
            for (ILogEntry logEntry : logEntries) {
                LogEntryChangePath[] logEntryChangePaths = logEntry.getLogEntryChangePaths();
                String[] changed = new String[logEntryChangePaths.length];
                for (int i = 0; i < logEntryChangePaths.length; i++) {
                    changed[i] = logEntryChangePaths[i].getPath();

                }
                ICustomChangesetLogEntry customEntry = new CustomChangeSetLogEntry(logEntry.getComment(),
                        logEntry.getAuthor(), logEntry.getRevision().toString(), logEntry.getDate(), changed,
                        getRepository(repositoryUrl, submonitor.newChild(1)));
                changesets.add(customEntry);
            }
        } catch (SVNException e) {
            if (e.getMessage().contains("Unable to load default SVN Client")) {
                throw new CoreException(new Status(IStatus.ERROR, AtlassianSubclipseCorePlugin.PLUGIN_ID,
                        NLS.bind("Subclipse doesn't have a default client installed", repositoryUrl), e));
            } else {
                throw new CoreException(new Status(IStatus.ERROR, AtlassianSubclipseCorePlugin.PLUGIN_ID,
                        NLS.bind("Subclipse client failed with an exception", repositoryUrl), e));
            }
        }
    } else {
        throw new CoreException(new Status(IStatus.ERROR, AtlassianSubclipseCorePlugin.PLUGIN_ID,
                "Getting all changesets is not supported"));
    }
    return changesets;
}

From source file:org.jahia.tools.maven.plugins.LegalArtifactAggregator.java

private void processPOM(boolean lookForNotice, boolean lookForLicense, String jarFilePath,
        JarMetadata contextJarMetadata, Set<JarMetadata> embeddedJarNames, int level,
        InputStream pomInputStream, boolean processingSources) throws IOException {
    MavenXpp3Reader reader = new MavenXpp3Reader();
    final String indent = getIndent(level);
    try {/* w  ww .  j a va 2 s.  c om*/
        final Model model = reader.read(pomInputStream);
        final Parent parent = model.getParent();
        String parentGroupId = null;
        String parentVersion = null;
        if (parent != null) {
            parentGroupId = parent.getGroupId();
            parentVersion = parent.getVersion();
        }

        if (model.getInceptionYear() != null) {
            contextJarMetadata.setInceptionYear(model.getInceptionYear());
        }

        if (model.getOrganization() != null) {
            if (model.getOrganization().getName() != null) {
                contextJarMetadata.setOrganizationName(model.getOrganization().getName());
            }
            if (model.getOrganization().getUrl() != null) {
                contextJarMetadata.setOrganizationUrl(model.getOrganization().getUrl());
            }
        }

        if (model.getUrl() != null) {
            contextJarMetadata.setProjectUrl(model.getUrl());
        }

        if (model.getLicenses() != null && model.getLicenses().size() > 0) {
            for (License license : model.getLicenses()) {
                output(indent, "Found license in POM for " + model.getId());
                String licenseName = license.getName();
                // let's try to resolve the license by name
                KnownLicense knownLicense = getKnowLicenseByName(licenseName);
                if (knownLicense != null) {
                    SortedSet<LicenseFile> licenseFiles = knownLicensesFound.get(knownLicense);
                    if (licenseFiles == null) {
                        licenseFiles = new TreeSet<>();
                    }
                    LicenseFile licenseFile = new LicenseFile(jarFilePath,
                            FilenameUtils.getBaseName(jarFilePath), jarFilePath, knownLicense.getTextToUse());
                    licenseFile.getKnownLicenses().add(knownLicense);
                    licenseFile.getKnownLicenseKeys().add(knownLicense.getId());
                    licenseFiles.add(licenseFile);
                    knownLicensesFound.put(knownLicense, licenseFiles);
                    // found a license for this project, let's see if we can resolve it
                    Map<String, LicenseFile> projectLicenseFiles = contextJarMetadata.getLicenseFiles();
                    if (projectLicenseFiles == null) {
                        projectLicenseFiles = new TreeMap<>();
                    }
                    projectLicenseFiles.put("pom.xml", licenseFile);
                } else if (license.getUrl() != null) {
                    try {
                        URL licenseURL = new URL(license.getUrl());
                        String licenseText = IOUtils.toString(licenseURL);
                        if (StringUtils.isNotBlank(licenseText)) {
                            // found a license for this project, let's see if we can resolve it
                            Map<String, LicenseFile> licenseFiles = contextJarMetadata.getLicenseFiles();
                            if (licenseFiles == null) {
                                licenseFiles = new TreeMap<>();
                            }
                            LicenseFile newLicenseFile = new LicenseFile(jarFilePath,
                                    FilenameUtils.getBaseName(jarFilePath), jarFilePath, licenseText);
                            if (licenseFiles.containsValue(newLicenseFile)) {
                                for (LicenseFile licenseFile : licenseFiles.values()) {
                                    if (licenseFile.equals(newLicenseFile)) {
                                        newLicenseFile = licenseFile;
                                        break;
                                    }
                                }
                            }
                            resolveKnownLicensesByText(newLicenseFile);
                            licenseFiles.put("pom.xml", newLicenseFile);
                        }
                    } catch (MalformedURLException mue) {
                        output(indent, "Invalid license URL : " + license.getUrl() + ": " + mue.getMessage());
                    }
                } else {
                    // couldn't resolve the license
                }
            }
        } else {
            if (parent != null) {
                Artifact parentArtifact = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(),
                        "pom", parent.getVersion());
                Artifact resolvedParentArtifact = resolveArtifact(parentArtifact, level);
                if (resolvedParentArtifact != null) {
                    output(indent, "Processing parent POM " + parentArtifact + "...");
                    processPOM(lookForNotice, lookForLicense, jarFilePath, contextJarMetadata, embeddedJarNames,
                            level + 1, new FileInputStream(resolvedParentArtifact.getFile()),
                            processingSources);
                } else {
                    output(indent, "Couldn't resolve parent POM " + parentArtifact + " !");
                }
            }
        }

        String scmConnection = null;
        if (model.getScm() != null) {
            scmConnection = model.getScm().getDeveloperConnection();
            if (scmConnection == null) {
                model.getScm().getConnection();
            }
            if (scmConnection == null) {
                // @todo let's try to resolve in the parent hierarcy
            }
        }

        /*
        if (scmManager != null && scmConnection != null) {
        ScmProvider scmProvider;
        File checkoutDir = new File(outputDirectory, "source-checkouts");
        checkoutDir.mkdirs();
        File wcDir = new File(checkoutDir, model.getArtifactId());
        wcDir.mkdirs();
        try {
            scmProvider = scmManager.getProviderByUrl(scmConnection);
            ScmRepository scmRepository = scmManager.makeScmRepository(scmConnection);
            CheckOutScmResult scmResult = scmProvider.checkOut(scmRepository, new ScmFileSet(wcDir));
            if (!scmResult.isSuccess()) {
            }
        } catch (ScmRepositoryException e) {
            e.printStackTrace();
        } catch (NoSuchScmProviderException e) {
            e.printStackTrace();
        } catch (ScmException e) {
            e.printStackTrace();
        }
        }
        */
        if (!embeddedJarNames.isEmpty()) {
            final List<Dependency> dependencies = model.getDependencies();
            Map<String, Dependency> artifactToDep = new HashMap<String, Dependency>(dependencies.size());
            for (Dependency dependency : dependencies) {
                artifactToDep.put(dependency.getArtifactId(), dependency);
            }

            for (JarMetadata jarName : embeddedJarNames) {
                final Dependency dependency = artifactToDep.get(jarName.name);
                if (dependency != null) {
                    File jarFile = getArtifactFile(new DefaultArtifact(dependency.getGroupId(),
                            dependency.getArtifactId(), null, "jar", jarName.version), level);
                    if (jarFile != null && jarFile.exists()) {
                        FileInputStream jarInputStream = new FileInputStream(jarFile);
                        processJarFile(jarInputStream, jarFile.getPath(), null, true, level, true, true,
                                processingSources);
                        IOUtils.closeQuietly(jarInputStream);
                    } else {
                        output(indent, "Couldn't find dependency for embedded JAR " + jarName, true, false);
                    }
                }
            }
        }

        if (!processingSources && (lookForLicense || lookForNotice)) {
            final String groupId = model.getGroupId() != null ? model.getGroupId() : parentGroupId;
            final String version = model.getVersion() != null ? model.getVersion() : parentVersion;
            final Artifact artifact = new DefaultArtifact(groupId, model.getArtifactId(), "sources", "jar",
                    version);

            File sourceJar = getArtifactFile(artifact, level);
            if (sourceJar != null && sourceJar.exists()) {
                FileInputStream sourceJarInputStream = new FileInputStream(sourceJar);
                processJarFile(sourceJarInputStream, sourceJar.getPath(), contextJarMetadata, false, level,
                        lookForNotice, lookForLicense, true);
                IOUtils.closeQuietly(sourceJarInputStream);
            }
        }
    } catch (XmlPullParserException e) {
        throw new IOException(e);
    }
}

From source file:biz.wolschon.fileformats.gnucash.jwsdpimpl.GnucashFileImpl.java

/**
 *
 * @param id//w  w w  .  j  a v  a 2  s  .c  o  m
 *            if null, gives all account that have no parent
 * @return the sorted collection of children of that account
 */
public Collection getAccountsByParentID(final String id) {
    if (accountid2account == null) {
        throw new IllegalStateException("no root-element loaded");
    }

    SortedSet retval = new TreeSet();

    for (Object element : accountid2account.values()) {
        GnucashAccount account = (GnucashAccount) element;

        String parent = account.getParentAccountId();
        if (parent == null) {
            if (id == null) {
                retval.add(account);
            }
        } else {
            if (parent.equals(id)) {
                retval.add(account);
            }
        }
    }

    return retval;
}

From source file:com.jd.survey.service.settings.SurveySettingsService.java

@Transactional(readOnly = false)
public Question question_merge(Question question) {

    Long dataSetId = null;/*from  w w  w. j  av a  2  s.  c  o m*/
    if (question.getPage().getSurveyDefinition().getStatus().equals(SurveyDefinitionStatus.I)) {
        if (question.getType().getIsDataSet()) {
            dataSetId = question.getDataSetId();
            question.setType(QuestionType.SINGLE_CHOICE_DROP_DOWN);
            question.setDataSetId(null);
        }

        //Deleting options from question that do not support options
        if (!question.getSuportsOptions()) {
            questionOptionDAO.deleteByQuestionId(question.getId());
        }
        SortedSet<Question> updatedQuestions = new TreeSet<Question>();
        Long pageId = question.getPage().getId();
        SurveyDefinitionPage surveyDefinitionPage = surveyDefinitionPageDAO.findById(pageId);
        question.setPage(surveyDefinitionPage);

        question.setDataSetId(null);

        Short order = surveyDefinitionPage.updateSet(surveyDefinitionPage.getQuestions(), question).getOrder();
        for (Question q : surveyDefinitionPage.getQuestions()) {
            updatedQuestions.add(questionDAO.merge(q));
        }
        surveyDefinitionPage.setQuestions(updatedQuestions);
        surveyDefinitionPage = surveyDefinitionPageDAO.merge(surveyDefinitionPage);

        Question updatedquestion = surveyDefinitionPage.getElement(surveyDefinitionPage.getQuestions(), order);

        if (dataSetId != null) {
            Short o = 1;
            for (DataSetItem dataSetItem : dataSetItemDAO.findByDataSetId(dataSetId)) {
                questionOptionDAO.merge(
                        new QuestionOption(updatedquestion, o, dataSetItem.getValue(), dataSetItem.getText()));
                o++;
            }
        }

        return updatedquestion;
    } else {

        Question dbQuestion = questionDAO.findById(question.getId());
        dbQuestion.setTip(question.getTip());
        dbQuestion.setQuestionText(question.getQuestionText());
        return questionDAO.merge(dbQuestion);
    }

}

From source file:org.web4thejob.web.panel.base.AbstractBorderLayoutPanel.java

@Override
public SortedSet<Command> getMergedCommands() {
    SortedSet<Command> mergedCommands = new TreeSet<Command>(super.getCommands());

    if (getCommandRenderer() == null) {
        mergeCommands();//from   w  ww .j a va  2  s. c om
    }

    for (CommandAware commandAware : getCommandRenderer().getCommandOwners()) {
        if (!getCommandRenderer().getPrimaryOwner().equals(commandAware)) {
            SortedSet<Command> commands;
            if (commandAware instanceof CommandMerger) {
                commands = ((CommandMerger) commandAware).getMergedCommands();
            } else {
                commands = commandAware.getCommands();
            }
            for (Command command : commands) {
                if (commandAware instanceof CommandMerger) {
                    //hinto for ToolbarRenderer so that in multiple command mergers scenario
                    //the last merger (panel) can be identified so that it can be correctly mapped
                    //to the correct region and this region settings can be applied (eg NORTH_EXCLUDE_CRUD_COMMANDS)
                    command.setArg(CommandMerger.ATTRIB_COMMAND_MERGER, commandAware);
                }
                mergedCommands.add(command);
            }
        }
    }

    return Collections.unmodifiableSortedSet(mergedCommands);
}

From source file:com.jd.survey.service.settings.SurveySettingsService.java

@Transactional(readOnly = false)
public Question question_updateOptions(Question question) {
    Long questionId = question.getId();
    Question q = questionDAO.findById(questionId);
    questionOptionDAO.deleteByQuestionId(questionId);
    SortedSet<QuestionOption> options = new TreeSet<QuestionOption>();
    for (QuestionOption option : question.getOptionsList2()) {

        if (option.getValue() != null && option.getText() != null && option.getValue().trim().length() > 0
                && option.getText().trim().length() > 0) {
            QuestionOption questionOption = new QuestionOption(q, option.getOrder(), option.getValue(),
                    option.getText());/*from  w  w  w  .  j a v  a 2 s .c o m*/
            questionOption = questionOptionDAO.merge(questionOption);
            options.add(questionOption);
        }
    }
    q.setOptions(options);
    return questionDAO.merge(q);
}