Example usage for java.util SortedSet addAll

List of usage examples for java.util SortedSet addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:net.sourceforge.fenixedu.presentationTier.Action.research.ViewCurriculumDispatchAction.java

private void putInformationOnRequestForGivenExecutionYear(ExecutionYear firstExecutionYear,
        ExecutionYear finaltExecutionYear, Person person, HttpServletRequest request) {

    Set<Advise> final_works = new HashSet<Advise>();
    Set<MasterDegreeThesisDataVersion> guidances = new HashSet<MasterDegreeThesisDataVersion>();
    SortedSet<ExecutionCourse> lectures = new TreeSet<ExecutionCourse>(
            new ReverseComparator(ExecutionCourse.EXECUTION_COURSE_COMPARATOR_BY_EXECUTION_PERIOD_AND_NAME));
    Set<Thesis> orientedThesis = new HashSet<Thesis>();
    Set<PersonFunction> functions = new HashSet<PersonFunction>();
    SortedSet<Career> career = new TreeSet<Career>(Career.CAREER_DATE_COMPARATOR);

    ExecutionYear stoppageYear = finaltExecutionYear.getNextExecutionYear();
    ExecutionYear iteratorYear = firstExecutionYear;
    Teacher teacher = person.getTeacher();

    while (iteratorYear != stoppageYear) {

        if (teacher != null) {
            final_works.addAll(
                    teacher.getAdvisesByAdviseTypeAndExecutionYear(AdviseType.FINAL_WORK_DEGREE, iteratorYear));

            guidances.addAll(teacher.getGuidedMasterDegreeThesisByExecutionYear(iteratorYear));
            lectures.addAll(teacher.getLecturedExecutionCoursesByExecutionYear(iteratorYear));
        }//  www.  j av a  2 s .com

        orientedThesis.addAll(person.getOrientedOrCoorientedThesis(iteratorYear));

        functions.addAll(person.getPersonFuntions(iteratorYear.getBeginDateYearMonthDay(),
                iteratorYear.getEndDateYearMonthDay()));
        iteratorYear = iteratorYear.getNextExecutionYear();
    }

    career.addAll(person.getCareersByTypeAndInterval(CareerType.PROFESSIONAL,
            new Interval(firstExecutionYear.getBeginDateYearMonthDay().toDateTimeAtMidnight(),
                    finaltExecutionYear.getEndDateYearMonthDay().toDateTimeAtMidnight())));

    List<PersonFunction> functionsList = new ArrayList<PersonFunction>(functions);
    Collections.sort(functionsList, new ReverseComparator(new BeanComparator("beginDateInDateType")));
    request.setAttribute("functions", functionsList);
    List<Advise> final_worksList = new ArrayList<Advise>(final_works);
    Collections.sort(final_worksList, new BeanComparator("student.number"));

    request.setAttribute("final_works", final_worksList);
    request.setAttribute("guidances", guidances);
    request.setAttribute("lectures", lectures);
    request.setAttribute("orientedThesis", orientedThesis);
    if (!(guidances.isEmpty() && orientedThesis.isEmpty())) {
        request.setAttribute("secondCycleThesis", true);
    }
    request.setAttribute("career", career);
}

From source file:org.sonar.plugins.groovy.codenarc.Converter.java

private void rule(Class<? extends AbstractRule> ruleClass, String since) throws Exception {
    if (duplications.contains(ruleClass)) {
        System.out.println("Duplicated rule " + ruleClass.getName());
    } else {//from   w  w w .j  ava 2 s.c  o m
        duplications.add(ruleClass);
    }
    AbstractRule rule = ruleClass.newInstance();
    String key = ruleClass.getCanonicalName();
    String configKey = StringUtils.removeEnd(ruleClass.getSimpleName(), "Rule");
    String name = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(configKey), ' ');
    String priorityStr = priority(rule.getPriority());
    String description = props.getProperty(configKey + ".description.html");

    SortedSet<String> params = new TreeSet<String>();

    // extract params
    String[] params1 = StringUtils.substringsBetween(description, "${", "}");
    if (params1 != null) {
        for (String param : params1) {
            description = StringUtils.remove(description, " (${" + param + "})");
            param = StringUtils.removeStart(param, "rule.");
            params.add(param);
        }
    }

    String[] params2 = StringUtils.substringsBetween(description, "<em>", "</em> property");
    if (params2 != null) {
        params.addAll(Arrays.asList(params2));
    }

    String[] params3 = StringUtils.substringsBetween(description, "configured in <em>", "</em>");
    if (params3 != null) {
        params.addAll(Arrays.asList(params3));
    }

    if (StringUtils.contains(description, "length property")) {
        params.add("length");
    }
    if (StringUtils.contains(description, "sameLine property")) {
        params.add("sameLine");
    }

    // output
    if (since != null) {
        out.println("  <!-- since " + since + " -->");
    }
    out.println("  <rule key=\"" + key + "\"" + " priority=\"" + priorityStr + "\">");
    out.println("    <name><![CDATA[" + name + "]]></name>");
    out.println("    <configKey><![CDATA[" + configKey + "]]></configKey>");
    out.println("    <description><![CDATA[" + description + "]]></description>");

    if (params != null) {
        for (String param : params) {
            out.println("    <param key=\"" + param + "\"/>");
        }
    }

    out.println("  </rule>");
    out.println();
    count++;
}

From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Returns a sorted array containing all of the elements for all of the
 * {@link DeviceProtocolInfoSource} {@link Set}s.
 * <p>// w  w  w.j a  v  a2  s.  c  o m
 * The returned array will be "safe" in that no reference to it is
 * maintained. (In other words, this method must allocate a new array). The
 * caller is thus free to modify the returned array.
 *
 * @return An array containing all the {@link ProtocolInfo} instances.
 */
public ProtocolInfo[] toArray() {
    SortedSet<ProtocolInfo> result = new TreeSet<>();
    setsLock.readLock().lock();
    try {
        for (SortedSet<ProtocolInfo> set : protocolInfoSets.values()) {
            if (set != null) {
                result.addAll(set);
            }
        }
    } finally {
        setsLock.readLock().unlock();
    }
    return result.toArray(new ProtocolInfo[result.size()]);
}

From source file:no.abmu.user.service.UserServiceImpl.java

private Collection<PostalAddressReport> getPostalAddresses(String orgTypeName) {

    // Getting postal address data for organisationType of today.
    StopWatch stopWatchPostalAddress = new StopWatch("postalAddress");
    stopWatchPostalAddress.start("postalAddress");

    Date toDay = new Date();
    logger.info("ToDay: " + toDay);
    OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean();
    finderBean.setOrganisationTypeName(orgTypeName);
    finderBean.setActiveDate(toDay);//from w ww .j  av  a 2 s  . c  o m

    PostalAddressFinderSpecification finderSpecification = new PostalAddressFinderSpecification(finderBean);
    Collection<PostalAddressReport> postalAddresses = organisationUnitService.find(finderSpecification);

    stopWatchPostalAddress.stop();
    logger.info(
            "Getting postal addresses tok " + stopWatchPostalAddress.getTotalTimeMillis() + " milliseconds for "
                    + postalAddresses.size() + " elements " + " for organisationType " + orgTypeName);

    Comparator<OrgUnitReport> comparator = new OrgUnitReportCountyAndNameComparator();
    SortedSet<PostalAddressReport> reports = new TreeSet<PostalAddressReport>(comparator);
    reports.addAll(postalAddresses);

    return reports;
}

From source file:se.alingsas.alfresco.repo.utils.byggreda.ByggRedaUtil.java

/**
 * Store a log in Alfresco of the result of the import
 * /*from ww w.  j a va 2s .co m*/
 * @param site
 */

private void logDocuments(SiteInfo site, List<String> globalMessages) {
    NodeRef folderNodeRef = createFolder(logPath, null, null, site);

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String currentDate = formatter.format(new Date());
    formatter = new SimpleDateFormat("yyyy-MM-dd HHmmss");
    String fileName = formatter.format(new Date()) + " Import.log";

    StringBuilder common = new StringBuilder();
    StringBuilder logged = new StringBuilder();

    Iterator<String> globalIt = globalMessages.iterator();
    while (globalIt.hasNext()) {
        String next = globalIt.next();
        logged.append(next + LINE_BREAK);
    }
    int failedCount = 0;
    SortedSet<ByggRedaDocument> sortedDocuments = new TreeSet<ByggRedaDocument>(new ByggRedaOrderComparator());
    sortedDocuments.addAll(documents);
    Iterator<ByggRedaDocument> it = sortedDocuments.iterator();
    while (it.hasNext()) {
        ByggRedaDocument next = it.next();
        if (!next.isReadSuccessfully()) {
            failedCount++;
        }
        if (!next.isReadSuccessfully() || StringUtils.hasText(next.getStatusMsg())) {
            logged.append("#" + next.getLineNumber() + " - " + next.getRecordDisplay() + " - "
                    + next.getBuildingDescription() + ": " + next.getStatusMsg() + LINE_BREAK);
        }
    }
    common.append("Sammastllning av importkrning " + LINE_BREAK);
    common.append("--------------------------" + LINE_BREAK);
    common.append("Datum/tidpunkt: " + currentDate + LINE_BREAK);
    common.append("Antal inlsta dokument frn styrfil: " + documents.size() + LINE_BREAK);
    common.append("Lyckade inlsningar: " + (documents.size() - failedCount) + LINE_BREAK);
    common.append("Misslyckade inlsningar: " + failedCount + LINE_BREAK);
    common.append("--------------------------" + LINE_BREAK + LINE_BREAK);
    if (logged.length() > 0) {
        common.append("Loggmeddelanden:" + LINE_BREAK);
        common.append("--------------------------" + LINE_BREAK);
        common.append(logged);
        common.append("--------------------------" + LINE_BREAK);
    }
    FileInfo fileInfo = fileFolderService.create(folderNodeRef, fileName, AkDmModel.TYPE_AKDM_DOCUMENT);

    logMessage = common.toString();
    try {
        InputStream is = new ByteArrayInputStream(common.toString().getBytes("UTF-8"));
        try {
            final ContentWriter writer = contentService.getWriter(fileInfo.getNodeRef(),
                    ContentModel.PROP_CONTENT, true);

            writer.setMimetype("text/plain");

            writer.putContent(is);
        } finally {
            IOUtils.closeQuietly(is);
        }

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        LOG.error("Error while creating log file, Unsupported Encoding", e);
    }
}

From source file:com.github.FraggedNoob.GitLabTransfer.GitlabRelatedData.java

/**
 * Reads all the data from JSON files except for the hostUrl, projectName,
 * and apiToken./*from ww w. jav  a2  s  .co m*/
 * @param filepath The filepath prefix
 * @return T=success, F=fail
 */
public boolean readAllData(String filepath) {

    ObjectMapper mapper = new ObjectMapper();

    File w;
    String wname = "(none)";

    w = createFileForReading(filepath, "_project");
    if (w == null) {
        return false;
    }

    // Project 
    try {
        this.project = mapper.readValue(w, GitlabProject.class);
        wname = w.getCanonicalPath();
    } catch (IOException e) {
        System.out.printf("Error reading project from %s.\n", wname);
        e.printStackTrace();
        return false;
    }

    System.out.printf("Read project (%s) from %s.\n", this.project.getName(), wname);

    // Users
    w = createFileForReading(filepath, "_users");
    if (w == null) {
        return false;
    }
    try {
        this.users = mapper.readValue(w, new TypeReference<List<GitlabUser>>() {
        });
        wname = w.getCanonicalPath();
    } catch (IOException e) {
        System.out.printf("Error reading from users to %s.\n", wname);
        e.printStackTrace();
        return false;
    }

    System.out.printf("Read %d users from %s.\n", this.users.size(), wname);

    // Milestones
    w = createFileForReading(filepath, "_milestones");
    if (w == null) {
        return false;
    }
    try {
        // Read in as a List first, matches output
        List<GitlabMilestone> ml = mapper.readValue(w, new TypeReference<List<GitlabMilestone>>() {
        });
        this.milestones.addAll(ml);
        // Read directly as Set:
        //this.milestones.clear();
        //JavaType type = mapper.getTypeFactory().constructCollectionType(Set.class, GitlabMilestone.class);
        //this.milestones = mapper.readValue(w,  type);
        wname = w.getCanonicalPath();
    } catch (IOException e) {
        System.out.printf("Error reading milestones from %s.\n", wname);
        e.printStackTrace();
        return false;
    } catch (Exception e) {
        System.out.printf("Error reading milestones from %s - incorrect data.\n", wname);
        e.printStackTrace();
        return false;
    }

    System.out.printf("Read %d milestones from %s.\n", this.milestones.size(), wname);

    // Issues
    w = createFileForReading(filepath, "_issues");
    if (w == null) {
        return false;
    }
    try {
        // Read in as a List first, matches output
        List<GitlabIssue> mi = mapper.readValue(w, new TypeReference<List<GitlabIssue>>() {
        });
        this.issues.addAll(mi);
        wname = w.getCanonicalPath();
    } catch (IOException e) {
        System.out.printf("Error writing to issues to %s.\n", wname);
        e.printStackTrace();
        return false;
    } catch (Exception e) {
        System.out.printf("Error reading issues from %s - incorrect data.\n", wname);
        e.printStackTrace();
        return false;
    }

    System.out.printf("Read %d issues to %s.\n", this.issues.size(), wname);

    // Issue Notes
    w = createFileForReading(filepath, "_inotes");
    if (w == null) {
        return false;
    }
    try {
        this.issueNotes.clear();
        // Read in as a Map of Integer vs. List<GitlabNote>
        JavaType valtype = mapper.getTypeFactory().constructCollectionType(List.class, GitlabNote.class);
        JavaType keytype = mapper.getTypeFactory().constructType(Integer.class);
        JavaType maptype = mapper.getTypeFactory().constructMapType(Map.class, keytype, valtype);
        Map<Integer, List<GitlabNote>> mapList = mapper.readValue(w, maptype);

        for (Integer k : mapList.keySet()) {
            SortedSet<GitlabNote> s = new TreeSet<GitlabNote>(new NoteOrderByID());
            s.addAll(mapList.get(k));
            issueNotes.put(k, s);
        }

        wname = w.getCanonicalPath();
    } catch (IOException e) {
        System.out.printf("Error reading issue notes from %s.\n", wname);
        e.printStackTrace();
        return false;
    } catch (Exception e) {
        System.out.printf("Error reading issues notes from %s - incorrect data.\n", wname);
        e.printStackTrace();
        return false;
    }

    System.out.printf("Read %d sets of issue notes to %s.\n", issueNotes.size(), wname);

    System.out.printf("Reading from files complete.\n");

    return true;
}

From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Ensures that the {@link Set} for the given
 * {@link DeviceProtocolInfoSource} contains all of the elements in the
 * specified collection./*w  w w  . j  a  v a2 s.  co m*/
 *
 * @param type the {@link DeviceProtocolInfoSource} type.
 * @param collection a {@link Collection} containing elements to be added.
 * @return {@code true} if the {@link Set} for {@code type} changed as a
 *         result of the call, {@code false} otherwise.
 *
 * @see #add(DeviceProtocolInfoSource, ProtocolInfo)
 */
public boolean addAll(DeviceProtocolInfoSource<?> type, Collection<? extends ProtocolInfo> collection) {
    setsLock.writeLock().lock();
    try {
        SortedSet<ProtocolInfo> currentSet;
        if (protocolInfoSets.containsKey(type)) {
            currentSet = protocolInfoSets.get(type);
        } else {
            currentSet = new TreeSet<ProtocolInfo>();
            protocolInfoSets.put(type, currentSet);
        }

        if (currentSet.addAll(collection)) {
            updateImageProfiles();
            return true;
        }
        return false;
    } finally {
        setsLock.writeLock().unlock();
    }
}

From source file:com.davidsoergel.trees.htpn.AbstractExtendedHierarchicalTypedPropertyNode.java

public SortedSet<Class> getPluginOptions(Incrementor incrementor) {
    //try/*from   ww  w. j  av a 2  s  . c  om*/
    V value = getValue();

    if (!(value == null || value instanceof GenericFactory || value instanceof Class)) {
        logger.warn("Can't get plugin options for a value " + value + " of type " + value.getClass());
    }
    //Class c = theField.getType();
    //Type genericType = theField.getGenericType();

    // if this is a GenericFactory, then we need the parameter type

    Type thePluginType = type;
    if (TypeUtils.isAssignableFrom(GenericFactory.class, type)) {
        if (type instanceof Class) {
            // it's a type that extends GenericFactory; just leave it alone then
            thePluginType = type;
        } else {
            thePluginType = ((ParameterizedType) type).getActualTypeArguments()[0];
        }
    }

    java.util.SortedSet<Class> result = new TreeSet<Class>(new Comparator<Class>() {
        public int compare(Class o1, Class o2) {
            if (o1 == null) {
                return -1;
            } else if (o2 == null) {
                return 1;
            } else {
                return o1.getSimpleName().compareTo(o2.getSimpleName());
            }
        }
    });
    if (isNullable) {
        result.add(null);
    }
    try {
        PluginManager.registerPluginsFromDefaultPackages(thePluginType, incrementor);
    } catch (IOException e) {
        logger.error("Error", e);
        throw new Error(e);
    }

    result.addAll(PluginManager.getPlugins(thePluginType));
    return result;
    //         }
    //      catch (PluginException e)
    //         {
    //         return null;
    //         }
}

From source file:org.wrml.runtime.schema.DefaultSchemaLoader.java

@Override
public final SortedSet<URI> getLoadedSchemaUris() {

    final SortedSet<URI> allLoadedSchemaUris = new TreeSet<>(_NativeSchemas.keySet());
    allLoadedSchemaUris.addAll(_Schemas.keySet());
    return allLoadedSchemaUris;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.scholarship.utl.report.StudentLine.java

public Integer getCountNumberOfDegreeChanges() {
    int numberOfDegreeChanges = 0;

    if (student == null) {
        return 0;
    }/*from   w  w  w .j  a  v a 2s  .  co m*/

    List<Registration> registrations = new ArrayList<Registration>(student.getRegistrationsSet());
    Collections.sort(registrations, Registration.COMPARATOR_BY_START_DATE);
    for (final Registration iter : registrations) {
        final SortedSet<RegistrationState> states = new TreeSet<RegistrationState>(
                RegistrationState.DATE_COMPARATOR);
        states.addAll(iter.getRegistrationStates(RegistrationStateType.INTERNAL_ABANDON));
        if (!states.isEmpty()) {
            numberOfDegreeChanges++;
        }
    }

    return numberOfDegreeChanges;
}