Example usage for java.util LinkedHashSet LinkedHashSet

List of usage examples for java.util LinkedHashSet LinkedHashSet

Introduction

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

Prototype

public LinkedHashSet() 

Source Link

Document

Constructs a new, empty linked hash set with the default initial capacity (16) and load factor (0.75).

Usage

From source file:annis.visualizers.iframe.partitur.PartiturVisualizer.java

@Override
public void writeOutput(VisualizerInput input, Writer writer) {
    try {/* w  ww.j av  a  2  s  .c o m*/

        nodes = input.getResult().getGraph().getNodes();
        token = input.getResult().getGraph().getTokens();

        // get partitur
        PartiturParser partitur = new PartiturParser(input.getResult().getGraph(), input.getNamespace());

        // check right to left
        boolean isRTL = checkRTL(input.getResult().getTokenList());

        List<String> tierNames = new LinkedList<String>(partitur.getKnownTiers());
        Collections.sort(tierNames);

        // get keys that are allowed to select
        LinkedHashSet<String> keys = new LinkedHashSet<String>();
        String mapping = input.getMappings().getProperty("annos");
        if (mapping == null) {
            // default to the alphabetical order
            keys.addAll(partitur.getNameslist());
        } else {
            String[] splitted = mapping.split(",");
            for (int k = 0; k < splitted.length; k++) {
                String s = splitted[k].trim();
                if (partitur.getNameslist().contains(s)) {
                    keys.add(s);
                }
            }
        }

        writer.append(
                "<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
        writer.append("<link href=\"" + input.getResourcePath("jbar.css")
                + "\" rel=\"stylesheet\" type=\"text/css\" >");
        writer.append("<link href=\"" + input.getResourcePath("jquery.tooltip.css")
                + "\" rel=\"stylesheet\" type=\"text/css\" >");
        writer.append("<link href=\"" + input.getResourcePath("jquery.noty.css")
                + "\" rel=\"stylesheet\" type=\"text/css\" >");
        writer.append("<link href=\"" + input.getResourcePath("partitur.css")
                + "\" rel=\"stylesheet\" type=\"text/css\" >");
        writer.append("<script src=\"" + input.getResourcePath("jquery-1.7.1.min.js") + "\"></script>");
        writer.append("<script src=\"" + input.getResourcePath("jquery.jbar.js") + "\"></script>");
        writer.append("<script src=\"" + input.getResourcePath("jquery.tooltip.min.js") + "\"></script>");
        writer.append("<script src=\"" + input.getResourcePath("jquery.noty.js") + "\"></script>");
        writer.append("<script>");
        writer.append(convertToJavacSriptArray(new LinkedList<String>()));
        writer.append("\nvar levelNames = [");
        int i = 0;
        for (String levelName : tierNames) {
            if (keys.contains(levelName)) {
                writer.append((i++ > 0 ? ", " : "") + "\"" + levelName + "\"");
            }
        }
        writer.append("];\n</script>");
        writer.append("<script type=\"text/javascript\" src=\"" + input.getResourcePath("PartiturVisualizer.js")
                + "\"></script>");

        writer.append("</head>");
        writer.append("<body>\n");

        writer.append("<ul id=\"toolbar\"></ul>");
        writer.append("<div id=\"partiture\">");

        if (isRTL) {
            writer.append("<table class=\"partitur_table\" dir=\"rtl\">\n");
        } else {
            writer.append("<table class=\"partitur_table\")\">\n");
        }

        for (String tier : keys) {
            List<String> indexlist = new ArrayList<String>();

            for (List<PartiturParser.ResultElement> span : partitur.getResultlist()) {
                for (PartiturParser.ResultElement strr : span) {
                    if (strr.getName().equals(tier) && !indexlist.contains(strr.getId())) {
                        indexlist.add(strr.getId());
                    }
                }
            }

            String[] currentarray; //Saves annotation-ids of the current row

            while (!indexlist.isEmpty()) { //Create Rows until all Annotations fit in
                List<String> currentdontuselist = new LinkedList<String>(); //Lists all Annotations that should not be added to the current row
                writer.append("<tr class=\"level_" + tier + "\"><th>" + tier + "</th>"); //new row

                currentarray = new String[partitur.getResultlist().size()];
                for (int iterator3 = 0; iterator3 < partitur.getResultlist().size(); iterator3++) {
                    currentarray[iterator3] = null;
                }

                int spanCounter = 0;
                for (List<PartiturParser.ResultElement> span : partitur.getResultlist()) { //for each Token
                    for (PartiturParser.ResultElement annotationelement : span) { // for each Annotation annotationelement of that Token
                        if (indexlist.contains(annotationelement.getId())
                                && !currentdontuselist.contains(annotationelement.getId())) {
                            boolean neu = false; //Should the Annotation be added?
                            if (currentarray[spanCounter] == null) {
                                indexlist.remove(annotationelement.getId());
                                currentarray[spanCounter] = annotationelement.getId();
                                neu = true;
                            }
                            //get all other annotationelement.id (earlier Ids => dontuselist)
                            int span2Counter = 0;
                            for (List<PartiturParser.ResultElement> span2 : partitur.getResultlist()) {
                                for (PartiturParser.ResultElement strr2 : span2) {
                                    if (strr2.getId().equals(annotationelement.getId()) && neu) //{
                                    {
                                        if (currentarray[span2Counter] == null) {
                                            currentarray[span2Counter] = annotationelement.getId();
                                        }
                                    }
                                    if (span2Counter <= spanCounter
                                            && !currentdontuselist.contains(strr2.getId())) {
                                        currentdontuselist.add(strr2.getId());
                                    }
                                }
                                span2Counter++;
                            }
                            //break; //Not needed?
                        }
                    }
                    spanCounter++;
                }

                //Write Row
                int length = 1;
                for (int iterator5 = 0; iterator5 < currentarray.length; iterator5 += length) {
                    StringBuffer tokenIdsArray = new StringBuffer();
                    StringBuffer eventIdsArray = new StringBuffer();
                    boolean unused = true;
                    length = 1;
                    if (currentarray[iterator5] == null) { //empty entry
                        writer.append("<td></td>");
                    } else {
                        PartiturParser.ResultElement element = null;
                        HashSet<Integer> common = new HashSet<Integer>();
                        boolean found = false;
                        int outputSpanCounter = 0;
                        for (List<PartiturParser.ResultElement> outputSpan : partitur.getResultlist()) {
                            for (PartiturParser.ResultElement strr : outputSpan) {
                                if (strr.getId().equals(currentarray[iterator5])) {
                                    if (!found) {
                                        element = strr;
                                    }
                                    if (!common.contains(outputSpanCounter)) {
                                        common.add(outputSpanCounter);
                                    }
                                    found = true;
                                    if (unused) {
                                        tokenIdsArray.append("" + strr.getId() + "_" + outputSpanCounter);
                                        eventIdsArray
                                                .append(tier + "_" + strr.getId() + "_" + outputSpanCounter);
                                        unused = false;
                                    } else {
                                        tokenIdsArray.append("," + strr.getId() + "_" + outputSpanCounter);
                                        eventIdsArray.append(
                                                "," + tier + "_" + strr.getId() + "_" + outputSpanCounter);
                                    }
                                }
                            }
                            outputSpanCounter++;
                        }
                        for (int iterator7 = iterator5 + 1; iterator7 < currentarray.length; iterator7++) {
                            if (common.contains(iterator7)) {
                                length++;
                            } else {
                                break;
                            }
                        }

                        for (int iterator8 = 0; iterator8 < currentarray.length; iterator8++) {
                            if (common.contains(iterator8)) {
                                Long id = ((PartiturParser.Token) partitur.getToken().toArray()[iterator8])
                                        .getId();
                                if (unused) {
                                    tokenIdsArray.append("" + id);
                                    eventIdsArray.append(tier + "_" + id);
                                    unused = false;
                                } else {
                                    tokenIdsArray.append("," + id);
                                    eventIdsArray.append("," + tier + "_" + id);
                                }
                            }
                        }

                        String color = "black";
                        if (input.getMarkableExactMap().containsKey("" + element.getNodeId())) {
                            color = input.getMarkableExactMap().get("" + element.getNodeId());
                        }
                        if (found) {
                            writer.append("<td class=\"single_event\" " + "id=\"event_" + tier + "_"
                                    + element.getId() + "_" + iterator5 + "\" " + "style=\"color:" + color
                                    + ";\" " + "colspan=" + length + " " + "annis:tokenIds=\"" + tokenIdsArray
                                    + "\" " + "annis:eventIds=\"" + eventIdsArray + "\" " + "title=\""
                                    + partitur.namespaceForTier(tier) + ":" + tier + " = "
                                    + StringEscapeUtils.escapeXml(element.getValue()) + "\"  " //tier =tier, event.getValue()= element.name
                                    + "onMouseOver=\"toggleAnnotation(this, true);\" "
                                    + "onMouseOut=\"toggleAnnotation(this, false);\" "
                                    + addTimeAttribute(element.getNodeId()) + ">" + element.getValue()
                                    + "</td>");
                        } else {
                            writer.append("<td class=\"single_event\" >error</td>");
                        }
                    }
                }
                writer.append("</tr>"); //finish row
            }
        }

        // add token itself
        writer.append("<tr><th>tok</th>");

        for (PartiturParser.Token token : partitur.getToken()) {
            String color = "black";

            if (input.getMarkableExactMap().containsKey("" + token.getId())) {
                color = input.getMarkableExactMap().get("" + token.getId());
            }
            writer.append("<td class=\"tok\" style=\"color:" + color + ";\" " + "id=\"token_" + token.getId()
                    + "\" " + ">" + token.getValue() + "</td>");
        }
        writer.append("</tr>");

        writer.append("</table>\n");
        writer.append("</div>\n");
        writer.append("</body></html>");

    } catch (Exception ex) {
        log.error(null, ex);
        try {
            String annisLine = "";
            for (int i = 0; i < ex.getStackTrace().length; i++) {
                if (ex.getStackTrace()[i].getClassName().startsWith("annis.")) {
                    annisLine = ex.getStackTrace()[i].toString();
                }
            }

            writer.append("<html><body>Error occured (" + ex.getClass().getName() + "): "
                    + ex.getLocalizedMessage() + "<br/>" + annisLine + "</body></html>");
        } catch (IOException ex1) {
            log.error(null, ex1);
        }
    }
}

From source file:com.contentful.vault.compiler.Processor.java

@Override
public Set<String> getSupportedAnnotationTypes() {
    Set<String> types = new LinkedHashSet<>();
    types.add(ContentType.class.getCanonicalName());
    types.add(Space.class.getCanonicalName());
    return types;
}

From source file:maltcms.ui.fileHandles.cdf.CDF2ChartOpenSupport.java

/**
 *
 * @return/*  w  w  w. j ava 2  s .  c om*/
 */
@Override
protected CloneableTopComponent createCloneableTopComponent() {
    final HashSet<IFileFragment> fragments = new LinkedHashSet<>();
    for (CDFDataObject dataObject : auxDataObjects) {
        fragments.add(new FileFragment(dataObject.getPrimaryFile().toURI()));
    }

    Chromatogram1DChartProvider c1d = new Chromatogram1DChartProvider();
    JFCTopComponent jtc = new JFCTopComponent();
    JFreeChart jfc = c1d.provideChart(new LinkedList<>(fragments));
    if (jfc == null) {
        return null;
    }
    jtc.setChart(jfc);
    jtc.setDisplayName("Chart");
    return jtc;
}

From source file:brut.directory.ZipRODirectory.java

private void loadAll() {
    mFiles = new LinkedHashSet<String>();
    mDirs = new LinkedHashMap<String, AbstractDirectory>();

    int prefixLen = getPath().length();
    Enumeration<? extends ZipArchiveEntry> entries = getZipFile().getEntries();
    while (entries.hasMoreElements()) {
        ZipArchiveEntry entry = entries.nextElement();

        // ignore general purpose bit, since AOSP does
        entry.getGeneralPurposeBit().useEncryption(false);
        String name = entry.getName();

        if (name.equals(getPath()) || !name.startsWith(getPath())) {
            continue;
        }//from w ww  .ja  v  a  2  s. c o  m

        String subname = name.substring(prefixLen);

        int pos = subname.indexOf(separator);
        if (pos == -1) {
            if (!entry.isDirectory()) {
                mFiles.add(subname);
                continue;
            }
        } else {
            subname = subname.substring(0, pos);
        }

        if (!mDirs.containsKey(subname)) {
            AbstractDirectory dir = new ZipRODirectory(getZipFile(), getPath() + subname + separator);
            mDirs.put(subname, dir);
        }
    }
}

From source file:com.gargoylesoftware.htmlunit.CookieManager.java

/**
 * Returns the currently configured cookies, in an unmodifiable set.
 * If disabled, this returns an empty set.
 * @return the currently configured cookies, in an unmodifiable set
 *//*from   w  ww .  j a  v  a 2 s.  c  om*/
public synchronized Set<Cookie> getCookies() {
    if (!isCookiesEnabled()) {
        return Collections.<Cookie>emptySet();
    }

    final Set<Cookie> copy = new LinkedHashSet<>();
    copy.addAll(cookies_);
    return Collections.unmodifiableSet(copy);
}

From source file:lt.geostream.security.GoogleAccessTokenConverter.java

@SuppressWarnings("unchecked")
private Set<String> parseScopes(Map<String, ?> map) {
    // Parsing of scopes coming back from Google are slightly different from the default implementation
    // Instead of it being a collection it is a String where multiple scopes are separated by a space.
    Object scopeAsObject = map.containsKey(SCOPE) ? map.get(SCOPE) : EMPTY;
    Set<String> scope = new LinkedHashSet<String>();
    if (String.class.isAssignableFrom(scopeAsObject.getClass())) {
        String scopeAsString = (String) scopeAsObject;
        Collections.addAll(scope, scopeAsString.split(" "));
    } else if (Collection.class.isAssignableFrom(scopeAsObject.getClass())) {
        Collection<String> scopes = (Collection<String>) scopeAsObject;
        scope.addAll(scopes);//from   ww w.ja va  2s .  com
    }
    return scope;
}

From source file:com.phoenixnap.oss.ramlapisync.verification.checkers.ActionResponseBodySchemaChecker.java

@Override
public Pair<Set<Issue>, Set<Issue>> check(ActionType name, Action reference, Action target,
        IssueLocation location, IssueSeverity maxSeverity) {
    logger.debug("Checking action " + name);
    Set<Issue> errors = new LinkedHashSet<>();
    Set<Issue> warnings = new LinkedHashSet<>();
    Issue issue;//  w  ww. jav a2  s.  co m

    //Only apply this checker in the contract
    if (location.equals(IssueLocation.CONTRACT)) {
        return new Pair<>(warnings, errors);
    }

    //Now the response
    if (reference.getResponses() != null && !reference.getResponses().isEmpty()
            && reference.getResponses().containsKey("200")
            && reference.getResponses().get("200").getBody() != null) {
        //successful response
        Map<String, MimeType> response = reference.getResponses().get("200").getBody();
        for (Entry<String, MimeType> responseBodyMime : response.entrySet()) {
            MimeType value = responseBodyMime.getValue();
            if (StringUtils.hasText(value.getSchema())) {
                logger.debug("Found body for mime type " + responseBodyMime.getKey());
                String targetSchema = null;
                try {
                    //lets assume the implementation contains exactly what we're looking for
                    targetSchema = target.getResponses().get("200").getBody().get(responseBodyMime.getKey())
                            .getSchema();
                } catch (NullPointerException npe) {
                    try {
                        // lets try the first response we get
                        targetSchema = target.getResponses().get("200").getBody().values().iterator().next()
                                .getSchema();
                    } catch (Exception ex) {
                        issue = new Issue(maxSeverity, location, IssueType.MISSING, RESPONSE_BODY_MISSING,
                                reference.getResource(), reference);
                        RamlCheckerResourceVisitorCoordinator.addIssue(errors, warnings, issue,
                                RESPONSE_BODY_MISSING + " " + responseBodyMime.getKey());
                        break;
                    }
                }

                //just a sanity check in case someone removes the break
                if (targetSchema != null) {
                    JCodeModel referenceCodeModel = new JCodeModel();
                    JCodeModel targetCodeModel = new JCodeModel();

                    GenerationConfig config = new DefaultGenerationConfig() {
                        @Override
                        public boolean isGenerateBuilders() { // set config
                            // option by
                            // overriding
                            // method
                            return false;
                        }
                    };

                    try {
                        SchemaMapper mapper = new SchemaMapper(
                                new RuleFactory(config, new Jackson2Annotator(), new SchemaStore()),
                                new SchemaGenerator());
                        mapper.generate(referenceCodeModel, "Reference", "com.response", value.getSchema());
                        mapper.generate(targetCodeModel, "Target", "com.response", targetSchema);

                        Map<String, JFieldVar> referenceResponseFields = referenceCodeModel
                                ._getClass("com.response.Reference").fields();
                        Map<String, JFieldVar> targetResponseClassFields = targetCodeModel
                                ._getClass("com.response.Target").fields();

                        for (Entry<String, JFieldVar> referenceField : referenceResponseFields.entrySet()) {
                            String fieldKey = referenceField.getKey();
                            JFieldVar targetField = targetResponseClassFields.get(fieldKey);
                            if (targetField == null) {
                                issue = new Issue(maxSeverity, location, IssueType.MISSING,
                                        RESPONSE_BODY_FIELDMISSING, reference.getResource(), reference,
                                        fieldKey);
                                RamlCheckerResourceVisitorCoordinator.addIssue(errors, warnings, issue,
                                        RESPONSE_BODY_FIELDMISSING + " " + fieldKey);
                            } else if (!referenceField.getValue().type().fullName()
                                    .equals(targetField.type().fullName())) {
                                issue = new Issue(IssueSeverity.WARNING, location, IssueType.DIFFERENT,
                                        RESPONSE_BODY_FIELDDIFFERENT, reference.getResource(), reference,
                                        fieldKey);
                                RamlCheckerResourceVisitorCoordinator.addIssue(errors, warnings, issue,
                                        RESPONSE_BODY_FIELDDIFFERENT + " " + fieldKey);
                            }
                        }

                        if (referenceResponseFields.size() != targetResponseClassFields.size()) {
                            for (Entry<String, JFieldVar> targetField : targetResponseClassFields.entrySet()) {
                                String fieldKey = targetField.getKey();
                                JFieldVar referenceField = referenceResponseFields.get(fieldKey);
                                if (referenceField == null) {
                                    issue = new Issue(maxSeverity, IssueLocation.CONTRACT, IssueType.MISSING,
                                            RESPONSE_BODY_FIELDMISSING, reference.getResource(), reference,
                                            fieldKey);
                                    RamlCheckerResourceVisitorCoordinator.addIssue(errors, warnings, issue,
                                            RESPONSE_BODY_FIELDMISSING + " " + fieldKey);
                                } else if (!targetField.getValue().type().fullName()
                                        .equals(referenceField.type().fullName())) {
                                    issue = new Issue(IssueSeverity.WARNING, IssueLocation.CONTRACT,
                                            IssueType.DIFFERENT, RESPONSE_BODY_FIELDDIFFERENT,
                                            reference.getResource(), reference, fieldKey);
                                    RamlCheckerResourceVisitorCoordinator.addIssue(errors, warnings, issue,
                                            RESPONSE_BODY_FIELDDIFFERENT + " " + fieldKey);
                                }
                            }
                        }

                    } catch (IOException ex) {
                        logger.error("Error during Schema to POJO generation");
                    }
                }

            }
        }

    }

    return new Pair<>(warnings, errors);
}

From source file:com.blackducksoftware.integration.gradle.DependencyGatherer.java

public DependencyNode getFullyPopulatedRootNode(final Project project, final String hubProjectName,
        final String hubProjectVersion) {
    logger.info("creating the dependency graph");
    final String groupId = project.getGroup().toString();
    final String artifactId = project.getName();
    final String version = hubProjectVersion;
    final MavenExternalId projectGav = new MavenExternalId(groupId, artifactId, version);

    final Set<DependencyNode> children = new LinkedHashSet<>();
    final DependencyNode root = new DependencyNode(hubProjectName, hubProjectVersion, projectGav, children);
    for (final Project childProject : project.getAllprojects()) {
        if (!excludedModules.contains(childProject.getName())) {
            getProjectDependencies(childProject, children);
        }/*w  w  w . ja  va 2s  . c o m*/
    }

    return root;
}

From source file:org.jasig.schedassist.impl.CompositeRelationshipDaoImpl.java

@Override
public List<Relationship> forVisitor(final IScheduleVisitor visitor) {
    Set<Relationship> union = new LinkedHashSet<Relationship>();
    for (RelationshipDao dao : components) {
        List<Relationship> relationships = dao.forVisitor(visitor);
        union.addAll(relationships);//from   www .ja  v  a 2s .  c o m
    }
    List<Relationship> results = new ArrayList<Relationship>();
    results.addAll(union);

    return results;
}

From source file:com.netflix.discovery.shared.Application.java

public Application(String name) {
    this.name = StringCache.intern(name);
    instancesMap = new ConcurrentHashMap<String, InstanceInfo>();
    instances = new LinkedHashSet<InstanceInfo>();
}