Example usage for java.util Set contains

List of usage examples for java.util Set contains

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java

/**
 * Run DFS on EObject reference tree//from  w  w w  .j a v  a 2  s  . c  o m
 * 
 * @param object
 * @param node
 * @param alreadyHandled
 * @return
 * @throws Exception
 */
@SuppressWarnings("unchecked")
protected static void dfs(EObject object, Element node, Set<EObject> alreadyHandled,
        Map<String, Namespace> namespaces) throws Exception {

    if (alreadyHandled.contains(object))
        return;
    else {
        alreadyHandled.add(object);
    }

    // traverse references and append them to the document
    for (EReference ref : object.eClass().getEAllReferences()) {
        if (ref.isTransient())
            continue;

        if (ref.isMany()) {
            int id = 0;

            for (EObject content : ((List<EObject>) object.eGet(ref))) {
                if (!(content.eClass().getEPackage() instanceof EcorePackage)) {
                    Document n = createDocFromEObject(content, namespaces);
                    dfs(content, n.getRootElement(), alreadyHandled, namespaces);
                    if (!ref.isContainment()) {
                        updateMember(node, ref, id, content, n);
                        id++;
                    }
                }
            }
        } else {
            EObject content = ((EObject) object.eGet(ref));
            if (content != null && !(content.eClass().getEPackage() instanceof EcorePackage)) {
                Document n = createDocFromEObject(content, namespaces);
                dfs(content, n.getRootElement(), alreadyHandled, namespaces);
                if (!ref.isContainment())
                    updateMember(node, ref, 0, content, n);
            }
        }
    }
}

From source file:Main.java

public static List<Node> getNodesWithKey(Node parent, String key, Set<String> values, boolean all_of_them) {
    ArrayList<Node> valid = new ArrayList<>();
    NodeList children = parent.getChildNodes();
    Node current;/*from   ww w  . ja  v a2  s. c  o  m*/
    for (int i = 0; i < children.getLength(); i++) {
        current = children.item(i);
        NamedNodeMap attrs = current.getAttributes();
        if (attrs != null) {
            Node keynode = attrs.getNamedItem(key);
            if (keynode != null)
                if (values == null || values.contains(keynode.getNodeValue())) {
                    valid.add(current);
                    if (!all_of_them)
                        break;
                }
        }
    }
    return valid;
}

From source file:com.opengamma.financial.analytics.volatility.surface.EquityOptionVolatilitySurfaceDataFunctionDeprecated.java

/**
 * // Computes active expiry dates, which fall on the Saturday following the 3rd Friday of an expiry month
 * @param valDate The evaluation date/*w ww . jav a 2 s. com*/
 * @return The expiry dates
 */
public static TreeSet<LocalDate> getExpirySet(final LocalDate valDate) {

    final TemporalAdjuster thirdFriday = TemporalAdjusters.dayOfWeekInMonth(3, DayOfWeek.FRIDAY);
    TreeSet<LocalDate> expirySet = new TreeSet<LocalDate>();

    // Add the next six months' Expiries although they are not guaranteed to be traded
    final LocalDate thisMonthsExpiry = valDate.with(thirdFriday).plusDays(1);
    if (thisMonthsExpiry.isAfter(valDate)) {
        expirySet.add(thisMonthsExpiry);
    }
    for (int m = 1; m <= 6; m++) {
        expirySet.add(valDate.plusMonths(m).with(thirdFriday).plusDays(1));
    }

    // Add the Quarterly IMM months out 3 years
    final Set<Month> immQuarters = EnumSet.of(Month.MARCH, Month.JUNE, Month.SEPTEMBER, Month.DECEMBER);
    LocalDate nextQuarter = valDate;
    do {
        nextQuarter = nextQuarter.plusMonths(1);
    } while (!immQuarters.contains(nextQuarter.getMonth()));

    for (int q = 1; q <= 12; q++) {
        expirySet.add(nextQuarter.with(thirdFriday).plusDays(1));
        nextQuarter = nextQuarter.plusMonths(3);
    }

    return expirySet;
}

From source file:info.archinnov.achilles.internals.parser.validator.BeanValidator.java

public static void validateComputed(AptUtils aptUtils, TypeName rawClassType,
        List<TypeParsingResult> parsingResults) {
    List<String> fieldNames = parsingResults.stream().map(x -> x.context.fieldName).collect(toList());

    final Set<String> aliases = new HashSet<>();

    parsingResults.stream().filter(x -> x.context.columnType == ColumnType.COMPUTED)
            .map(x -> Tuple2.of(x.context.fieldName, ((ComputedColumnInfo) x.context.columnInfo).alias))
            .forEach(x -> {//from  w  ww  .  ja  v  a  2 s  . c  o m
                aptUtils.validateFalse(aliases.contains(x._2()),
                        "Alias '%s' in @Computed annotation on field '%s' is already used by another @Computed field",
                        x._2(), x._1());
                if (!aliases.contains(x._2()))
                    aliases.add(x._2());
            });

    parsingResults.stream().filter(x -> x.context.columnType == ColumnType.COMPUTED).forEach(x -> {
        final ComputedColumnInfo columnInfo = (ComputedColumnInfo) x.context.columnInfo;
        for (String column : columnInfo.functionArgs) {
            aptUtils.validateTrue(fieldNames.contains(column),
                    "Target field '%s' in @Computed annotation of field '%s' of class '%s' does not exist",
                    column, x.context.fieldName, rawClassType);
        }
    });
}

From source file:net.metanotion.sqlc.SqlcPhp.java

private static void generateStructs(final String outputFolder, final StructManager sm,
        final Set<String> implicits, final Map<String, String> implicitDocs) throws IOException {
    for (final Map.Entry<String, GetInitializer> e : sm) {
        if (!implicits.contains(e.getKey())) {
            continue;
        }//from  w w  w  .  j ava 2s .co m
        System.out.println("GENERATING " + e.getKey());
        final String docString = implicitDocs.get(e.getKey());
        final GetInitializer gi = e.getValue();

        final Struct s = (Struct) gi;
        final String[] name = e.getKey().split("\\.");
        final String[] pkg = new String[name.length - 1];
        for (int i = 0; i < pkg.length; i++) {
            pkg[i] = name[i];
        }
        final FileOutputStream fos = new FileOutputStream(mkPath(outputFolder, pkg, name[pkg.length]));
        final PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, "UTF-8"));
        writer.println("<?php");
        if (pkg.length > 0) {
            writer.print("namespace ");
            String sep = "";
            for (String pe : pkg) {
                writer.print(sep + pe);
                sep = "\\";
            }
            writer.println(";");
            writer.println("");
        }

        System.out.println("GENERATING: " + name[pkg.length]);
        writer.print("/** ");
        if (docString != null) {
            writer.println(docString.substring(3, docString.length() - 2));
        }
        writer.println("<i>This is a data/struct/value class generated by the SQLC compiler.</i> */");
        writer.println("final class " + name[pkg.length] + " {");
        for (final String p : s.listProperties()) {
            writer.print("\tpublic ");
            //writer.print(s.getType(p));
            writer.println(" $" + p + ";");
        }
        writer.println("}");
        writer.println("?>");
        writer.close();
        fos.close();
    }
}

From source file:org.hxzon.util.db.springjdbc.NamedParameterUtils.java

private static int addNewNamedParameter(Set<String> namedParameters, int namedParameterCount,
        String parameter) {/*  www  .j  a va2  s.  c  o m*/
    if (!namedParameters.contains(parameter)) {
        namedParameters.add(parameter);
        namedParameterCount++;
    }
    return namedParameterCount;
}

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

/**
 * Verify that each given name occurs exactly one.
 * @param selectionList is the list of select items to verify names
 * @throws com.espertech.esper.epl.expression.ExprValidationException thrown if a name occured more then once
 */// ww w .j  av  a 2  s.  c om
protected static void verifyNameUniqueness(SelectClauseElementCompiled[] selectionList)
        throws ExprValidationException {
    Set<String> names = new HashSet<String>();
    for (SelectClauseElementCompiled element : selectionList) {
        if (element instanceof SelectClauseExprCompiledSpec) {
            SelectClauseExprCompiledSpec expr = (SelectClauseExprCompiledSpec) element;
            if (names.contains(expr.getAssignedName())) {
                throw new ExprValidationException(
                        "Column name '" + expr.getAssignedName() + "' appears more then once in select clause");
            }
            names.add(expr.getAssignedName());
        } else if (element instanceof SelectClauseStreamCompiledSpec) {
            SelectClauseStreamCompiledSpec stream = (SelectClauseStreamCompiledSpec) element;
            if (stream.getOptionalName() == null) {
                continue; // ignore no-name stream selectors
            }
            if (names.contains(stream.getOptionalName())) {
                throw new ExprValidationException("Column name '" + stream.getOptionalName()
                        + "' appears more then once in select clause");
            }
            names.add(stream.getOptionalName());
        }
    }
}

From source file:Main.java

public static ArrayList<Node> getNodesWithKey(Node parent, String key, Set<String> values,
        boolean all_of_them) {
    ArrayList<Node> valid = new ArrayList<Node>();
    NodeList children = parent.getChildNodes();
    Node current;//w w w.  ja v  a  2 s .  c  om
    for (int i = 0; i < children.getLength(); i++) {
        current = children.item(i);
        NamedNodeMap attrs = current.getAttributes();
        if (attrs != null) {
            Node keynode = attrs.getNamedItem(key);
            if (keynode != null)
                if (values == null || values.contains(keynode.getNodeValue())) {
                    valid.add(current);
                    if (!all_of_them)
                        break;
                }
        }
    }
    return valid;
}

From source file:com.bigdata.dastor.tools.SSTableExport.java

static void export(SSTableReader reader, PrintStream outs, String[] excludes) throws IOException {
    SSTableScanner scanner = reader.getScanner(INPUT_FILE_BUFFER_SIZE);
    Set<String> excludeSet = new HashSet();

    if (excludes != null)
        excludeSet = new HashSet<String>(Arrays.asList(excludes));

    outs.println("{");

    while (scanner.hasNext()) {
        IteratingRow row = scanner.next();
        if (excludeSet.contains(row.getKey().key))
            continue;
        try {/* w ww .j a v a 2 s  . c o  m*/
            String jsonOut = serializeRow(row);
            outs.print("  " + jsonOut);
            if (scanner.hasNext())
                outs.println(",");
            else
                outs.println();
        } catch (IOException ioexcep) {
            System.err.println("WARNING: Corrupt row " + row.getKey().key + " (skipping).");
            continue;
        } catch (OutOfMemoryError oom) {
            System.err.println("ERROR: Out of memory deserializing row " + row.getKey().key);
            continue;
        }
    }

    outs.println("}");
    outs.flush();
}

From source file:net.sourceforge.fenixedu.domain.DomainObjectActionLog.java

public static Set<DomainObjectActionLog> readDomainObjectActionLogsOrderedByInstant(
        Set<Class<? extends DomainObject>> domainObjectClasss) {

    Set<DomainObjectActionLog> resultList = new TreeSet<DomainObjectActionLog>(
            DomainObjectActionLog.COMPARATOR_BY_INSTANT);
    for (DomainObjectActionLog log : Bennu.getInstance().getDomainObjectActionLogsSet()) {
        try {//from w ww.j  ava2s. c  om
            Class<?> domainObjectClass = Class.forName(log.getDomainObjectClassName());
            if (domainObjectClasss.contains(domainObjectClass)) {
                resultList.add(log);
            }
        } catch (ClassNotFoundException e) {
            continue;
        }
    }
    return resultList;
}