Example usage for java.util LinkedHashSet add

List of usage examples for java.util LinkedHashSet add

Introduction

In this page you can find the example usage for java.util LinkedHashSet 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.espertech.esper.core.start.EPStatementStartMethodCreateContext.java

private ContextDetailMatchPair validateRewriteContextCondition(EPServicesContext servicesContext,
        StatementContext statementContext, ContextDetailCondition endpoint, Set<String> eventTypesReferenced,
        MatchEventSpec priorMatches, Set<String> priorAllTags) throws ExprValidationException {
    if (endpoint instanceof ContextDetailConditionCrontab) {
        ContextDetailConditionCrontab crontab = (ContextDetailConditionCrontab) endpoint;
        ScheduleSpec schedule = ExprNodeUtility.toCrontabSchedule(crontab.getCrontab(), statementContext);
        crontab.setSchedule(schedule);//  www.  j  a  v  a  2  s. c o m
        return new ContextDetailMatchPair(crontab, new MatchEventSpec(), new LinkedHashSet<String>());
    }

    if (endpoint instanceof ContextDetailConditionTimePeriod) {
        ContextDetailConditionTimePeriod timePeriod = (ContextDetailConditionTimePeriod) endpoint;
        ExprValidationContext validationContext = new ExprValidationContext(
                new StreamTypeServiceImpl(servicesContext.getEngineURI(), false),
                statementContext.getMethodResolutionService(), null, statementContext.getSchedulingService(),
                statementContext.getVariableService(), getDefaultAgentInstanceContext(statementContext),
                statementContext.getEventAdapterService(), statementContext.getStatementName(),
                statementContext.getStatementId(), statementContext.getAnnotations(),
                statementContext.getContextDescriptor());
        ExprNodeUtility.getValidatedSubtree(timePeriod.getTimePeriod(), validationContext);
        return new ContextDetailMatchPair(timePeriod, new MatchEventSpec(), new LinkedHashSet<String>());
    }

    if (endpoint instanceof ContextDetailConditionPattern) {
        ContextDetailConditionPattern pattern = (ContextDetailConditionPattern) endpoint;
        Pair<MatchEventSpec, Set<String>> matches = validatePatternContextConditionPattern(statementContext,
                pattern, eventTypesReferenced, priorMatches, priorAllTags);
        return new ContextDetailMatchPair(pattern, matches.getFirst(), matches.getSecond());
    }

    if (endpoint instanceof ContextDetailConditionFilter) {
        ContextDetailConditionFilter filter = (ContextDetailConditionFilter) endpoint;

        // compile as filter if there are no prior match to consider
        if (priorMatches == null || (priorMatches.getArrayEventTypes().isEmpty()
                && priorMatches.getTaggedEventTypes().isEmpty())) {
            FilterStreamSpecRaw rawExpr = new FilterStreamSpecRaw(filter.getFilterSpecRaw(),
                    ViewSpec.EMPTY_VIEWSPEC_ARRAY, null, new StreamSpecOptions());
            FilterStreamSpecCompiled compiled = (FilterStreamSpecCompiled) rawExpr.compile(statementContext,
                    eventTypesReferenced, false, Collections.<Integer>emptyList());
            filter.setFilterSpecCompiled(compiled.getFilterSpec());
            MatchEventSpec matchEventSpec = new MatchEventSpec();
            EventType filterForType = compiled.getFilterSpec().getFilterForEventType();
            LinkedHashSet<String> allTags = new LinkedHashSet<String>();
            if (filter.getOptionalFilterAsName() != null) {
                matchEventSpec.getTaggedEventTypes().put(filter.getOptionalFilterAsName(),
                        new Pair<EventType, String>(filterForType,
                                rawExpr.getRawFilterSpec().getEventTypeName()));
                allTags.add(filter.getOptionalFilterAsName());
            }
            return new ContextDetailMatchPair(filter, matchEventSpec, allTags);
        }

        // compile as pattern if there are prior matches to consider, since this is a type of followed-by relationship
        EvalFactoryNode factoryNode = servicesContext.getPatternNodeFactory()
                .makeFilterNode(filter.getFilterSpecRaw(), filter.getOptionalFilterAsName(), 0);
        ContextDetailConditionPattern pattern = new ContextDetailConditionPattern(factoryNode, true, false);
        Pair<MatchEventSpec, Set<String>> matches = validatePatternContextConditionPattern(statementContext,
                pattern, eventTypesReferenced, priorMatches, priorAllTags);
        return new ContextDetailMatchPair(pattern, matches.getFirst(), matches.getSecond());
    } else if (endpoint instanceof ContextDetailConditionImmediate) {
        return new ContextDetailMatchPair(endpoint, new MatchEventSpec(), new LinkedHashSet<String>());
    } else {
        throw new IllegalStateException("Unrecognized endpoint type " + endpoint);
    }
}

From source file:org.loklak.geo.GeoNames.java

public LinkedHashSet<String> suggest(String q, int count, int distance) {
    TreeMap<Long, String> a = new TreeMap<>();
    String ql = normalize(q);/*from  w  ww  .java 2 s.  co  m*/
    boolean exact = false;
    String exactTerm = null;
    seekloop: for (GeoLocation g : id2loc.values()) {
        termloop: for (String n : g.getNames()) {
            if (n.length() > 3 && n.length() < ql.length() * 4) {
                String nn = normalize(n);
                if (!exact && nn.equals(ql)) {
                    exact = true;
                    exactTerm = n;
                    continue seekloop;
                }
                // starts-with:
                if (nn.startsWith(ql)) {
                    a.put(g.getPopulation() + a.size(), n);
                    if (a.size() > count * 2)
                        break seekloop;
                }
                // distance

                if (nn.length() == ql.length()) {
                    int errorcount = 0;
                    for (int i = 0; i < nn.length(); i++) {
                        if (nn.charAt(i) != ql.charAt(i)) {
                            errorcount++;
                            if (errorcount > distance)
                                continue termloop;
                        }
                    }
                    a.put(g.getPopulation() + a.size(), n);
                    if (a.size() > count * 2)
                        break seekloop;
                }
            }
        }
    }
    // order by population
    LinkedHashSet<String> list = new LinkedHashSet<>();
    int i = 0;
    if (exact) {
        list.add(exactTerm);
    }
    for (Long p : a.descendingKeySet()) {
        list.add(a.get(p));
        if (i >= list.size())
            break;
    }
    return list;
}

From source file:com.espertech.esper.epl.core.EngineImportServiceImpl.java

public void addAggregationMultiFunction(ConfigurationPlugInAggregationMultiFunction desc)
        throws EngineImportException {
    LinkedHashSet<String> orderedImmutableFunctionNames = new LinkedHashSet<String>();
    for (String functionName : desc.getFunctionNames()) {
        orderedImmutableFunctionNames.add(functionName.toLowerCase());
        validateFunctionName("aggregation multi-function", functionName.toLowerCase());
    }// w  w w  .ja v  a  2  s.c  o  m
    if (!isClassName(desc.getMultiFunctionFactoryClassName())) {
        throw new EngineImportException("Invalid class name for aggregation multi-function factory '"
                + desc.getMultiFunctionFactoryClassName() + "'");
    }
    aggregationAccess.add(new Pair<Set<String>, ConfigurationPlugInAggregationMultiFunction>(
            orderedImmutableFunctionNames, desc));
}

From source file:com.heliosapm.script.AbstractDeployedScript.java

protected static LinkedHashSet<File> locateConfigFiles(final File sourceFile, final String rootDir,
        final String[] pathSegments) {
    final LinkedHashSet<File> configs = new LinkedHashSet<File>();
    /*/*w  ww .j av  a  2 s .c o m*/
     * root config:  root.config, root.*.config
     * for each dir:  foo.config, foo.*.config, dir.config, dir.*.config
     * 
     */
    final String deplName = URLHelper.getPlainFileName(sourceFile);
    final ConfigFileFilter cff = new ConfigFileFilter("root");
    final File root = new File(rootDir);
    for (File f : root.listFiles(cff)) {
        configs.add(f);
    }
    cff.plainName = deplName;
    File subDir = root;
    for (int i = 1; i < pathSegments.length; i++) {
        subDir = new File(subDir, pathSegments[i]);
        cff.plainName = pathSegments[i];
        for (File f : subDir.listFiles(cff)) {
            configs.add(f);
        }
        cff.plainName = deplName;
        for (File f : subDir.listFiles(cff)) {
            configs.add(f);
        }
    }
    System.out
            .println(String.format("Config Files for deployment [%s] --> %s", sourceFile, configs.toString()));
    return configs;
}

From source file:com.geewhiz.pacify.managers.FilterManager.java

private LinkedHashSet<Defect> fillPropertyValuesFor(Map<String, String> propertyValues, PFile pFile) {
    LinkedHashSet<Defect> defects = new LinkedHashSet<Defect>();

    for (PProperty pProperty : pFile.getPProperties()) {
        String propertyName = pProperty.getName();
        String propertyValue = null;
        try {//from  w ww.j ava2  s .c  o m
            propertyValue = propertyResolveManager.getPropertyValue(pProperty);
        } catch (PropertyNotFoundRuntimeException e) {
            Defect defect = new PropertyNotDefinedInResolverDefect(pMarker, pFile, pProperty,
                    propertyResolveManager.toString());
            defects.add(defect);
            continue;
        }
        propertyValues.put(propertyName, propertyValue);
    }

    return defects;
}

From source file:ch.puzzle.itc.mobiliar.presentation.propertyEdit.EditPropertyView.java

public void assignPropertyTypeId() {
    if (propertyTypes != null) {
        if (propertyTypeId == 0) {
            // Custom type
            propertyDescriptor.setPropertyTypeEntity(null);
            propertyDescriptor.setValidationLogic(null);
            return;
        }/*from  w  w  w  .ja  v a2  s  . c  o  m*/
        for (PropertyTypeEntity t : propertyTypes) {
            if (t.getId() != null && t.getId().equals(propertyTypeId)) {
                propertyDescriptor.setPropertyTypeEntity(t);
                propertyDescriptor.setEncrypt(t.isEncrypt());
                propertyDescriptor.setValidationLogic(t.getValidationRegex());

                // tags
                StringBuffer newTagsSb = new StringBuffer();
                LinkedHashSet<String> existingTags = new LinkedHashSet<>();

                if (!StringUtils.isEmpty(propertyTagsString)) {
                    newTagsSb.append(propertyTagsString);
                    String[] tags = propertyTagsString.split(",");
                    for (String tag : tags) {
                        existingTags.add(tag);
                    }
                }
                for (PropertyTagEntity tag : t.getPropertyTags()) {
                    if (!existingTags.contains(tag.getName())) {
                        newTagsSb.append(tag.getName()).append(",");
                    }
                }
                propertyTagsString = newTagsSb.toString();
            }
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SimpleSQLReportDataFactory.java

public String[] getReferencedFields(final String query, final DataRow parameters)
        throws ReportDataFactoryException {

    final boolean isNewConnection = connection == null;
    try {/*from www . jav  a 2s  .  c o m*/
        final ParametrizationProviderFactory factory = createParametrizationProviderFactory();
        final Connection connection = getConnection(parameters);
        final ParametrizationProvider parametrizationProvider = factory.create(connection);
        final String computedQuery = computedQuery(query, parameters);
        parametrizationProvider.rewriteQueryForParametrization(connection, computedQuery, parameters);
        final LinkedHashSet<String> list = new LinkedHashSet<String>();
        list.addAll(Arrays.asList(parametrizationProvider.getPreparedParameterNames()));
        if (userField != null) {
            list.add(userField);
        }
        if (passwordField != null) {
            list.add(passwordField);
        }
        list.add(DataFactory.QUERY_LIMIT);
        return list.toArray(new String[list.size()]);
    } catch (ReportDataFactoryException e) {
        logger.warn("Unable to perform cache preparation", e);
        throw e;
    } catch (SQLException e) {
        logger.warn("Unable to perform cache preparation", e);
        throw new ReportDataFactoryException("Unable to perform cache preparation", e);
    } finally {
        if (isNewConnection) {
            close();
        }
    }
}

From source file:com.alibaba.wasp.plan.parser.druid.DruidDQLParser.java

/**
 * Parse The SQL SELECT Statement. Get which columns should be return
 * //from w w  w  .j a  v  a2  s .  co  m
 */
private LinkedHashSet<String> parseSelectClause(List<SQLSelectItem> select) throws UnsupportedException {
    LinkedHashSet<String> selectItem = new LinkedHashSet<String>(select.size());
    for (SQLSelectItem item : select) {
        SQLExpr expr = item.getExpr();
        if (expr instanceof SQLAggregateExpr) {

        }
        String columnName = parseColumn(expr);
        selectItem.add(columnName);
        LOG.debug(" SQLSelectItem " + columnName);
    }
    return selectItem;
}

From source file:net.sourceforge.sqlexplorer.connections.ConnectionsView.java

/**
 * Returns a list of selected Users; if recurse is true, indirectly selected users are included also (eg a session's
 * user)//from   ww w. j  a  v a 2 s.co  m
 * 
 * @param recurse
 * @return Set of Users, never returns null
 */
public Set<User> getSelectedUsers(boolean recurse) {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return EMPTY_USERS;
    }

    LinkedHashSet<User> result = new LinkedHashSet<User>();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof User) {
            result.add((User) obj);
        } else if (recurse) {
            if (obj instanceof Alias) {
                Alias alias = (Alias) obj;
                result.addAll(alias.getUsers());
            } else if (obj instanceof SQLConnection) {
                SQLConnection connection = (SQLConnection) obj;
                result.add(connection.getUser());
            }
        }
    }

    return result;
}

From source file:net.sourceforge.sqlexplorer.connections.ConnectionsView.java

/**
 * Returns a list of the selected Aliases. If recurse is true then the result will include any aliases associated
 * with other objects; eg, if a connection is selected and recurse is true, then the connection's alias will also be
 * returned/*from  w w w  .ja  v  a 2s.c o  m*/
 * 
 * @param recurse
 * @return Set of Aliases, never returns null
 */
public Set<Alias> getSelectedAliases(boolean recurse) {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return EMPTY_ALIASES;
    }

    LinkedHashSet<Alias> result = new LinkedHashSet<Alias>();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof Alias) {
            result.add((Alias) obj);
        } else if (recurse) {
            if (obj instanceof User) {
                User user = (User) obj;
                result.add(user.getAlias());
            } else if (obj instanceof SQLConnection) {
                SQLConnection connection = (SQLConnection) obj;
                result.add(connection.getUser().getAlias());
            }
        }
    }

    return result;
}