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:ch.algotrader.esper.EsperTestBase.java

protected static void deployModule(final EPServiceProvider epServiceProvider, final URL resource,
        final String... includedStatements) throws IOException, ParseException {

    Set<String> statementNames = new LinkedHashSet<>();
    for (String includedStatement : includedStatements) {
        statementNames.add(includedStatement);
    }/*from w  w  w  .j  av a2  s  .com*/
    Module module = load(resource, "unit-test");
    EPAdministrator epAdministrator = epServiceProvider.getEPAdministrator();
    for (ModuleItem moduleItem : module.getItems()) {
        String expression = moduleItem.getExpression();
        EPStatementObjectModel compiledStatement = epAdministrator.compileEPL(expression);
        boolean included = true;
        if (!statementNames.isEmpty()) {
            for (AnnotationPart annotationPart : compiledStatement.getAnnotations()) {
                if (annotationPart.getName().equals("Name")) {
                    for (AnnotationAttribute attribute : annotationPart.getAttributes()) {
                        if (attribute.getName().equals("value")) {
                            Object name = attribute.getValue();
                            included = statementNames.contains(name);
                            break;
                        }
                    }
                    break;
                }
            }
        }
        if (included) {
            epAdministrator.create(compiledStatement);
        }
    }
}

From source file:com.itpro.restws.helper.MultipartFromWrapper.java

/**
 * Return all request parameter names, for both regular controls and file
 * upload controls.//from   w  w w . j av a  2s.c  o m
 */
@Override
public Enumeration<String> getParameterNames() {
    Set<String> allNames = new LinkedHashSet<>();
    allNames.addAll(fRegularParams.keySet());
    allNames.addAll(fFileParams.keySet());
    return Collections.enumeration(allNames);
}

From source file:net.audumla.climate.ClimateDataFactory.java

/**
 * Replaces the climate observation with a readonly version.
 *
 * @param cd the existing climate data bean
 * @return the climate data// www.ja v a2  s.  c  om
 */
public static WritableClimateObservation convertToWritableClimateObservation(ClimateObservation cd) {
    if (cd == null) {
        return null;
    }
    Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>();
    interfaces.addAll(ClassUtils.getAllInterfaces(cd.getClass()));
    return BeanUtils.convertBean(cd, WritableClimateObservation.class,
            interfaces.toArray(new Class<?>[interfaces.size()]));
}

From source file:com.janrain.backplane2.server.Scope.java

public Scope(final BackplaneMessage.Field scopeField, final String value) {
    this.scopes = new LinkedHashMap<BackplaneMessage.Field, LinkedHashSet<String>>() {
        {// ww w . ja va 2  s.c  o m
            put(scopeField, new LinkedHashSet<String>() {
                {
                    add(value);
                }
            });
        }
    };
}

From source file:com.yahoo.maven.visitor.VisitorGenerator.java

public void generate() throws IOException {
    for (Visitor visitor : getVisitors()) {
        String name = visitor.getVisitedName();
        int packageTail = name.lastIndexOf(".");
        String aPackage = packageTail == -1 ? null : name.substring(0, packageTail);
        String disjunctName = packageTail == -1 ? name : name.substring(packageTail + 1, name.length());
        String className = capitalizer.capitalize(disjunctName);
        String dir = aPackage == null ? ""
                : StringUtils.replace(aPackage, ".", FileSystems.getDefault().getSeparator());
        List<TypeParameterContext> typeParameterContexts = new ArrayList<>();
        Set<String> typeParameterNames = new LinkedHashSet<>();
        if (visitor.getTypeParameters() != null) {
            typeParameterContexts.addAll(Arrays.asList(visitor.getTypeParameters()));
            for (TypeParameter typeParameter : visitor.getTypeParameters()) {
                typeParameterNames.add(typeParameter.getName());
            }// w w w .j av a  2  s  .com
        }
        List<DisjunctContext> disjuncts = new ArrayList<>();
        for (Disjunction disjunction : visitor.getDisjunctions()) {
            List<ParameterContext> parameterContexts = new ArrayList<>();
            if (disjunction.parameters != null) {
                for (Parameter parameter : disjunction.parameters) {
                    parameterContexts.add(new ParameterContext() {
                        @Override
                        public String getType() {
                            return parameter.type;
                        }

                        @Override
                        public String getName() {
                            return parameter.name;
                        }

                        @Override
                        public String getHashExpression() {
                            switch (getType()) {
                            case "boolean":
                                return "(" + getName() + " ? 1 : 0)";
                            case "char":
                            case "byte":
                            case "short":
                                return "(int) " + getName();
                            case "int":
                                return getName();
                            case "long":
                                return "(int) (" + getName() + " ^ (" + getName() + " >>> 32))";
                            case "float":
                                return "(" + getName() + " != +0.0f ? Float.floatToIntBits(" + getName()
                                        + ") : 0)";
                            case "double":
                                return "(int) (Double.doubleToLongBits(" + getName()
                                        + ") ^ (Double.doubleToLongBits(" + getName() + ") >>> 32))";
                            default:
                                return "(" + getName() + " != null ? " + getName() + ".hashCode() : 0)";
                            }
                        }
                    });
                }
            }
            disjuncts.add(new DisjunctContext() {
                @Override
                public String getMethodName() {
                    return disjunction.name;
                }

                @Override
                public List<ParameterContext> getParameters() {
                    return parameterContexts.isEmpty() ? null : parameterContexts;
                }

                @Override
                public boolean hasAsMethod() {
                    return parameterContexts.size() == 1
                            && !primitives.contains(parameterContexts.get(0).getType());
                }
            });
        }
        class AbstractBaseContext implements BaseContext {
            @Override
            public String getPackage() {
                return aPackage;
            }

            @Override
            public String getVisitedClassName() {
                return className;
            }

            @Override
            public List<TypeParameterContext> getTypeParameters() {
                return typeParameterContexts.isEmpty() ? null : typeParameterContexts;
            }

            @Override
            public List<DisjunctContext> getDisjuncts() {
                return disjuncts.isEmpty() ? null : disjuncts;
            }
        }
        Path outputFolder = getOutputDirectory().resolve(dir);
        File outputFolderAsFile = outputFolder.toFile();
        if (!outputFolderAsFile.mkdirs() && !outputFolderAsFile.exists()) {
            throw new IOException("Unable to make directory: " + outputFolderAsFile.getAbsolutePath());
        }
        try (Writer visitedWriter = Files.newBufferedWriter(outputFolder.resolve(className + ".java"))) {
            class ThisVisitedContext extends AbstractBaseContext implements VisitedContext {
            }
            visitedTemplate.merge(visitedWriter, new ThisVisitedContext());
        }
        try (Writer visitorWriter = Files.newBufferedWriter(outputFolder.resolve(className + "Visitor.java"))) {
            class ThisVisitorContext extends AbstractBaseContext implements VisitorContext {
            }
            visitorTemplate.merge(visitorWriter, new ThisVisitorContext());
        }
        try (Writer visitorWriter = Files
                .newBufferedWriter(outputFolder.resolve("Defaulting" + className + "Visitor.java"))) {
            class ThisDefaultingVisitorContext extends AbstractBaseContext implements DefaultingVisitorContext {
            }
            defaultingVisitorTemplate.merge(visitorWriter, new ThisDefaultingVisitorContext());
        }
        try (Writer visitorWriter = Files
                .newBufferedWriter(outputFolder.resolve("Identity" + className + "Visitor.java"))) {
            class ThisIdentityVisitorContext extends AbstractBaseContext implements IdentityVisitorContext {
            }
            identityVisitorTemplate.merge(visitorWriter, new ThisIdentityVisitorContext());
        }
        try (Writer visitorWriter = Files
                .newBufferedWriter(outputFolder.resolve("DefaultingIdentity" + className + "Visitor.java"))) {
            class ThisIdentityVisitorContext extends AbstractBaseContext
                    implements IdentityVisitorContext, DefaultingVisitorContext {
            }
            defaultingIdentityVisitorTemplate.merge(visitorWriter, new ThisIdentityVisitorContext());
        }
    }
}

From source file:biomine.bmvis2.pipeline.RepresentiveHighlightOperation.java

public ArrayList<VisualNode> initList(VisualGraph g) {
    SimpleVisualGraph sg = new SimpleVisualGraph(g.getRootNode().getDescendants());
    ArrayList<ProbDijkstra> positive = new ArrayList<ProbDijkstra>();
    ArrayList<ProbDijkstra> negative = new ArrayList<ProbDijkstra>();
    int poicount = 0;

    LinkedHashSet<Integer> remaining = new LinkedHashSet<Integer>();
    for (int i = 0; i < sg.n; i++)
        remaining.add(i);/*from   ww  w .j av a 2s . com*/

    for (Map.Entry<VisualNode, Double> ent : g.getNodesOfInterest().entrySet()) {
        VisualNode vn = ent.getKey();
        double val = ent.getValue();
        int ivn = sg.getInt(vn);
        remaining.remove(ivn);
        ProbDijkstra pd = new ProbDijkstra(sg, ivn);
        if (val > 0)
            positive.add(pd);
        else
            negative.add(pd);
        poicount++;
    }

    ArrayList<VisualNode> rlist = new ArrayList<VisualNode>();
    ArrayList<Double> posProb = new ArrayList<Double>();
    ArrayList<Double> posSquareSum = new ArrayList<Double>();
    for (int i = 0; i < sg.n; i++) {
        double p = 1;
        double ss = 0;
        for (ProbDijkstra pd : positive) {
            p *= pd.getProbTo(i);
            ss += Math.pow(pd.getProbTo(i), 2);
        }
        posProb.add(p);
        posSquareSum.add(ss);
    }

    ArrayList<Double> negProb = new ArrayList<Double>();
    for (int i = 0; i < sg.n; i++) {
        double p = 1;
        for (ProbDijkstra pd : negative) {
            p *= (1 - pd.getProbTo(i));
        }
        negProb.add(p);
    }

    int it = 0;
    while (negative.size() + positive.size() < sg.n) {
        it++;
        //add 
        //select n with highest posProb[n]*(1-negProb[n])
        //in case of a tie, select n with lowest square sum distance from 
        //positive nodes

        int best = -1;
        double bestSS = 100000;
        double bestProb = 0;
        for (int n : remaining) {
            double prob = posProb.get(n) * (negProb.get(n));
            double ss = posSquareSum.get(n);
            if (prob == bestProb) {
                if (ss < bestSS) {
                    bestSS = ss;
                    best = n;
                }
            }
            if (prob > bestProb) {
                bestProb = prob;
                bestSS = ss;
                best = n;
            }
        }
        if (best < 0)
            break;

        System.out.println("it " + it + " best = " + best + " prob = " + bestProb);

        rlist.add(sg.getVisualNode(best));
        ProbDijkstra newPD = new ProbDijkstra(sg, best);
        negative.add(newPD);

        remaining.remove(best);
        for (int i : remaining) {
            double ol = negProb.get(i);
            ol *= 1 - newPD.getProbTo(i);
            negProb.set(i, ol);
        }
    }
    return rlist;
}

From source file:edu.uci.ics.jung.graph.UndirectedOrderedSparseMultigraph.java

@Override
public Collection<V> getNeighbors(V vertex) {
    if (!containsVertex(vertex))
        return null;

    Set<V> neighbors = new LinkedHashSet<V>();
    for (E edge : getIncident_internal(vertex)) {
        Pair<V> endpoints = this.getEndpoints(edge);
        V e_a = endpoints.getFirst();//from www  .  j  a v a 2  s .co m
        V e_b = endpoints.getSecond();
        if (vertex.equals(e_a))
            neighbors.add(e_b);
        else
            neighbors.add(e_a);
    }

    return Collections.unmodifiableCollection(neighbors);
}

From source file:cc.recommenders.utils.dictionary.Dictionary.java

public Set<T> getAllMatchings(IMatcher<T> m) {
    Set<T> matchings = new LinkedHashSet<T>();

    for (T entry : getAllEntries()) {
        if (m.matches(entry)) {
            matchings.add(entry);//from  w ww  .j  a  va  2s.  com
        }
    }

    return matchings;
}

From source file:de.vandermeer.skb.interfaces.antlr.IsST.java

/**
 * Validates the ST for expected arguments.
 * @return a set of error messages, empty if no errors found, null if no expected arguments where set or no ST was set
 *///from  w  ww  .j av  a 2 s  .c  om
default Set<String> validate() {
    if (this.getExpectedArguments() == null) {
        return null;
    }
    if (this.getST() == null) {
        return null;
    }

    Set<String> ret = new LinkedHashSet<>();
    Map<?, ?> formalArgs = this.getST().impl.formalArguments;
    if (formalArgs == null) {
        for (String s : this.getExpectedArguments()) {
            ret.add("ST <" + this.getST().getName() + "> does not define expected argument <" + s + ">");
        }
    } else {
        for (String s : this.getExpectedArguments()) {
            if (!formalArgs.containsKey(s)) {
                ret.add("ST <" + this.getST().getName() + "> does not define expected argument <" + s + ">");
            }
        }
    }
    return ret;
}

From source file:com.streamsets.datacollector.definition.StageDefinitionExtractor.java

public static List<String> getGroups(Class<? extends Stage> klass) {
    Set<String> set = new LinkedHashSet<>();
    addGroupsToList(klass, set);/*from ww  w. j  a va2s  .  c  o m*/
    List<Class<?>> allSuperclasses = ClassUtils.getAllSuperclasses(klass);
    for (Class<?> superClass : allSuperclasses) {
        if (!superClass.isInterface() && superClass.isAnnotationPresent(ConfigGroups.class)) {
            addGroupsToList(superClass, set);
        }
    }
    if (set.isEmpty()) {
        set.add(""); // the default empty group
    }

    return new ArrayList<>(set);
}