Example usage for java.util HashSet contains

List of usage examples for java.util HashSet contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:eionet.cr.dao.virtuoso.PredicateObjectsReader.java

/**
 *
 * @param value/*from   w  w w . jav  a 2 s .  c  o m*/
 * @param language
 * @return
 */
private boolean objectAlreadyAdded(String value, boolean isLiteral, String language) {

    if (isLiteral) {
        HashSet<String> valuesByLang = distinctLiterals.get(language);
        return valuesByLang != null && valuesByLang.contains(value);
    } else {
        return distinctResources.contains(value);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo.java

public static Map<String, String> getOptions(EditConfigurationVTwo editConfig, String fieldName,
        WebappDaoFactory wDaoFact) {/*from w ww .  j  a v a 2s  .c  om*/
    if (editConfig == null) {
        log.error("fieldToSelectItemList() must be called with a non-null EditConfigurationVTwo ");
        return Collections.EMPTY_MAP;
    }
    if (fieldName == null) {
        log.error("fieldToSelectItemList() must be called with a non-null fieldName");
        return Collections.EMPTY_MAP;
    }

    FieldVTwo field = editConfig.getField(fieldName);
    if (field == null) {
        log.error("no field \"" + fieldName + "\" found from editConfig in SelectListGenerator.getOptions()");
        return Collections.EMPTY_MAP;
    }
    // now create an empty HashMap to populate and return
    HashMap<String, String> optionsMap = new LinkedHashMap<String, String>();
    // for debugging, keep a count of the number of options populated
    int optionsCount = 0;

    FieldVTwo.OptionsType optionsType = field.getOptionsType();
    String vclassUri = null;
    switch (optionsType) {
    case HARDCODED_LITERALS: // not auto-sorted, and empty values not removed or replaced
        List<List<String>> hardcodedLiteralOptions = field.getLiteralOptions();
        if (hardcodedLiteralOptions == null) {
            log.error("no literalOptions List found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType HARDCODED_LITERALS specified");
            return new HashMap<String, String>();
        }
        for (Object obj : ((Iterable) hardcodedLiteralOptions)) {
            List<String> literalPair = (List) obj;
            String value = (String) literalPair.get(0);
            if (value != null) { // allow empty string as a value
                String label = (String) literalPair.get(1);
                if (label != null) {
                    optionsMap.put(value, label);
                } else {
                    optionsMap.put(value, value);
                }
                ++optionsCount;
            }
        }
        break;
    case LITERALS:
        List<List<String>> literalOptions = field.getLiteralOptions();
        if (literalOptions == null) {
            log.error("no literalOptions List found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType LITERALS specified");
            return new HashMap<String, String>();
        }
        for (Object obj : ((Iterable) literalOptions)) {
            List<String> literalPair = (List) obj;
            String value = (String) literalPair.get(0);
            if (value != null && value.trim().length() > 0) {
                String label = (String) literalPair.get(1);
                if (label != null && label.trim().length() > 0) {
                    optionsMap.put(value, label);
                } else {
                    optionsMap.put(value, value);
                }
                ++optionsCount;
            }
        }
        break;
    case STRINGS_VIA_DATATYPE_PROPERTY:
        log.debug("processing Field \"" + fieldName
                + "\" optionType as a datatype property predicateUri in SelectListGenerator.getOptions()");
        String dataPropUri = field.getPredicateUri();
        if (dataPropUri == null || dataPropUri.equals("")) {
            log.error("no predicate dataPropUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType STRINGS_VIA_DATATYPE_PROPERTY specified");
        } else {
            /* first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption=null;
            if ((defaultOption=getDefaultOption(field))!=null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            } */
            // now populate the options
            log.debug("finding all choices for data property \"" + dataPropUri
                    + "\" in SelectListGenerator.getOptions()");

            if (wDaoFact == null)
                log.error(
                        "incoming WebappDaoFactory from request is null in SelectListGenerator.getOptions().");

            DataPropertyStatementDao dpsDao = wDaoFact.getDataPropertyStatementDao();
            DataPropertyDao dpDao = wDaoFact.getDataPropertyDao();
            DataProperty dp = dpDao.getDataPropertyByURI(dataPropUri);
            for (Iterator<DataPropertyStatement> i = dpsDao.getDataPropertyStatements(dp).iterator(); i
                    .hasNext();) {
                DataPropertyStatement dps = i.next();
                if (dps != null) {
                    optionsMap.put(dps.getData().trim(), dps.getData().trim());
                    ++optionsCount;
                }
            }
        }
        break;
    case INDIVIDUALS_VIA_OBJECT_PROPERTY:
        log.debug("processing Field \"" + fieldName
                + "\" optionType as an object property predicateUri in SelectListGenerator.getOptions()");
        String subjectUri = editConfig.getSubjectUri();
        if (subjectUri == null || subjectUri.equals("")) {
            log.error("no subjectUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified");
        } else {
            String predicateUri = field.getPredicateUri();
            if (predicateUri == null || predicateUri.equals("")) {
                log.error("no predicateUri found for field \"" + fieldName
                        + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified");
            } else {
                // first test to see whether there's a default "leave blank" value specified with the literal options
                String defaultOption = null;
                if ((defaultOption = getDefaultOption(field)) != null) {
                    optionsMap.put(LEFT_BLANK, defaultOption);
                }
                // now populate the options
                log.debug("finding range individuals for subject \"" + subjectUri + "\" and object property \""
                        + predicateUri + "\" in SelectListGenerator.getOptions()");

                if (wDaoFact == null)
                    log.error(
                            "could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

                Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
                if (subject == null)
                    log.error("could not get individual for subject uri " + subjectUri
                            + " in SelectListGenerator.getOptions()");

                ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
                if (objProp == null)
                    log.error("could not get object property for predicate " + predicateUri
                            + " in SelectListGenerator.getOptions()");

                List<VClass> vclasses = new ArrayList<VClass>();
                vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(), predicateUri);
                if (vclasses == null) {
                    log.error("no owl:Class found for predicate " + predicateUri);
                    break;
                }
                if (vclasses.size() == 0)
                    log.error("no owl:Class found for predicate " + predicateUri);

                List<Individual> individuals = new ArrayList<Individual>();
                HashSet<String> uriSet = new HashSet<String>();
                long startTime = System.currentTimeMillis();
                for (VClass vclass : vclasses) {
                    for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),
                            -1, -1)) {
                        if (!uriSet.contains(ind.getURI())) {
                            uriSet.add(ind.getURI());
                            individuals.add(ind);
                        }
                    }
                }

                List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();
                if (stmts == null)
                    log.error("object properties for subject were null in SelectListGenerator.getOptions()");

                individuals = removeIndividualsAlreadyInRange(individuals, stmts, predicateUri,
                        editConfig.getObject());
                //Collections.sort(individuals,new compareIndividualsByName());    

                for (Individual ind : individuals) {
                    String uri = ind.getURI();
                    if (uri != null) {
                        optionsMap.put(uri, ind.getName().trim());
                        ++optionsCount;
                    }
                }

            }
        }
        break;
    case INDIVIDUALS_VIA_VCLASS: //so we have a vclass URI
        vclassUri = field.getObjectClassUri();
        if (vclassUri == null || vclassUri.equals("")) {
            log.error("no vclassUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_VCLASS specified");
        } else {
            // first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption = null;
            if ((defaultOption = getDefaultOption(field)) != null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            }
            // now populate the options                
            if (wDaoFact == null)
                log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

            // if reasoning isn't available, we will also need to add 
            // individuals asserted in subclasses
            boolean inferenceAvailable = false;
            if (wDaoFact instanceof WebappDaoFactoryJena) {
                PelletListener pl = ((WebappDaoFactoryJena) wDaoFact).getPelletListener();
                if (pl != null && pl.isConsistent() && !pl.isInErrorState() && !pl.isReasoning()) {
                    inferenceAvailable = true;
                }
            }

            VClass vclass = wDaoFact.getVClassDao().getVClassByURI(vclassUri);
            if (vclass == null) {
                log.error("Cannot find owl:Class " + vclassUri + " in the model");
                optionsMap.put("", "Could not find class " + vclassUri);
            } else {
                Map<String, Individual> individualMap = new HashMap<String, Individual>();

                for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1,
                        -1)) {
                    if (ind.getURI() != null) {
                        individualMap.put(ind.getURI(), ind);
                    }
                }

                if (!inferenceAvailable) {
                    for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) {
                        for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,
                                -1, -1)) {
                            if (ind.getURI() != null) {
                                individualMap.put(ind.getURI(), ind);
                            }
                        }
                    }
                }

                List<Individual> individuals = new ArrayList<Individual>();
                individuals.addAll(individualMap.values());
                Collections.sort(individuals);

                for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1,
                        -1)) {
                    if (ind.getURI() != null) {
                        individualMap.put(ind.getURI(), ind);
                    }
                }

                if (!inferenceAvailable) {
                    for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) {
                        for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,
                                -1, -1)) {
                            if (ind.getURI() != null) {
                                individualMap.put(ind.getURI(), ind);
                            }
                        }
                    }
                }

                individuals.addAll(individualMap.values());
                Collections.sort(individuals);

                if (individuals.size() == 0) {
                    log.error("No individuals of type " + vclass.getName()
                            + " to add to pick list in SelectListGenerator.getOptions()");
                    optionsMap.put("", "No " + vclass.getName() + " found");
                } else {
                    for (Individual ind : individuals) {
                        String uri = ind.getURI();
                        if (uri != null) {
                            optionsMap.put(uri, ind.getName().trim());
                            ++optionsCount;
                        }
                    }
                }
            }
        }
        break;
    case CHILD_VCLASSES: //so we have a vclass URI
        vclassUri = field.getObjectClassUri();
        if (vclassUri == null || vclassUri.equals("")) {
            log.error("no vclassUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified");
        } else {
            // first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption = null;
            if ((defaultOption = getDefaultOption(field)) != null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            }
            // now populate the options                
            if (wDaoFact == null)
                log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

            VClassDao vclassDao = wDaoFact.getVClassDao();
            List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri);
            if (subClassList == null || subClassList.size() == 0) {
                log.debug("No subclasses of " + vclassUri
                        + " found in the model so only default value from field's literalOptions will be used");
            } else {
                for (String subClassUri : subClassList) {
                    VClass subClass = vclassDao.getVClassByURI(subClassUri);
                    if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
                        optionsMap.put(subClassUri, subClass.getName().trim());
                        ++optionsCount;
                    }
                }
            }
        }
        break;

    case CHILD_VCLASSES_WITH_PARENT: //so we have a vclass URI
        vclassUri = field.getObjectClassUri();
        if (vclassUri == null || vclassUri.equals("")) {
            log.error("no vclassUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified");
        } else {
            // first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption = null;
            if ((defaultOption = getDefaultOption(field)) != null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            }
            // now populate the options                
            if (wDaoFact == null)
                log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

            VClassDao vclassDao = wDaoFact.getVClassDao();
            List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri);
            if (subClassList == null || subClassList.size() == 0) {
                log.debug("No subclasses of " + vclassUri
                        + " found in the model so only default value from field's literalOptions will be used");
            } else {
                for (String subClassUri : subClassList) {
                    VClass subClass = vclassDao.getVClassByURI(subClassUri);
                    if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
                        optionsMap.put(subClassUri, subClass.getName().trim());
                        ++optionsCount;
                    }
                }
                optionsMap.put(vclassUri, "Other");
                ++optionsCount;
            }
        }
        break;

    case VCLASSGROUP:

        String classGroupUri = field.getObjectClassUri(); // we're overloading this property to specify the classgroup
        if (classGroupUri == null || classGroupUri.equals("")) {
            log.error("no classGroupUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType VCLASSGROUP specified");
        } else {
            // first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption = null;
            if ((defaultOption = getDefaultOption(field)) != null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            }
            // now populate the options                
            if (wDaoFact == null)
                log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

            VClassGroupDao vcgd = wDaoFact.getVClassGroupDao();

            // Need to call this method to populate the classgroups - otherwise the classgroup class list is empty
            List vClassGroups = vcgd.getPublicGroupsWithVClasses();

            if (vClassGroups == null) {
                log.error(
                        "No class groups found, so only default value from field's literalOptions will be used.");
            } else {
                VClassGroup vClassGroup = null;
                for (Object o : vClassGroups) {
                    VClassGroup vcg = (VClassGroup) o;
                    if (vcg.getURI().equals(classGroupUri)) {
                        vClassGroup = vcg;
                        break;
                    }
                }
                if (vClassGroup == null) {
                    log.error("No class group with uri " + classGroupUri
                            + "found, so only default value from field's literalOptions will be used.");
                } else {
                    List<VClass> vClassList = vClassGroup.getVitroClassList();

                    if (vClassList == null || vClassList.size() == 0) {
                        log.debug("No classes in class group " + classGroupUri
                                + " found in the model, so only default value from field's literalOptions will be used");
                    } else {
                        for (VClass vClass : vClassList) {
                            String vClassUri = vClass.getURI();
                            if (vClass != null && !OWL.Nothing.getURI().equals(vClassUri)) {
                                optionsMap.put(vClassUri, vClass.getName().trim());
                                ++optionsCount;
                            }
                        }
                    }
                }
            }
        }
        break;

    case UNDEFINED:
        log.error("optionsType \"UNDEFINED\" for Field \"" + fieldName
                + "\" in SelectListGenerator.getOptions()");
        break;
    default:
        log.error("unknown optionsType " + optionsType.toString() + " for Field \"" + fieldName
                + "\" in SelectListGenerator.getOptions()");
    }
    log.debug("added " + optionsCount + " options for field \"" + fieldName
            + "\" in SelectListGenerator.getOptions()");
    return optionsMap;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator.java

public static Map<String, String> getOptions(EditConfiguration editConfig, String fieldName,
        WebappDaoFactory wDaoFact) {/*  ww w  .  java2  s .c o m*/
    if (editConfig == null) {
        log.error("fieldToSelectItemList() must be called with a non-null EditConfiguration ");
        return Collections.EMPTY_MAP;
    }
    if (fieldName == null) {
        log.error("fieldToSelectItemList() must be called with a non-null fieldName");
        return Collections.EMPTY_MAP;
    }

    Field field = editConfig.getField(fieldName);
    if (field == null) {
        log.error("no field \"" + fieldName + "\" found from editConfig in SelectListGenerator.getOptions()");
        return Collections.EMPTY_MAP;
    }
    // now create an empty HashMap to populate and return
    HashMap<String, String> optionsMap = new LinkedHashMap<String, String>();
    // for debugging, keep a count of the number of options populated
    int optionsCount = 0;

    Field.OptionsType optionsType = field.getOptionsType();
    String vclassUri = null;
    switch (optionsType) {
    case HARDCODED_LITERALS: // not auto-sorted, and empty values not removed or replaced
        List<List<String>> hardcodedLiteralOptions = field.getLiteralOptions();
        if (hardcodedLiteralOptions == null) {
            log.error("no literalOptions List found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType HARDCODED_LITERALS specified");
            return new HashMap<String, String>();
        }
        for (Object obj : ((Iterable) hardcodedLiteralOptions)) {
            List<String> literalPair = (List) obj;
            String value = (String) literalPair.get(0);
            if (value != null) { // allow empty string as a value
                String label = (String) literalPair.get(1);
                if (label != null) {
                    optionsMap.put(value, label);
                } else {
                    optionsMap.put(value, value);
                }
                ++optionsCount;
            }
        }
        break;
    case LITERALS:
        List<List<String>> literalOptions = field.getLiteralOptions();
        if (literalOptions == null) {
            log.error("no literalOptions List found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType LITERALS specified");
            return new HashMap<String, String>();
        }
        for (Object obj : ((Iterable) literalOptions)) {
            List<String> literalPair = (List) obj;
            String value = (String) literalPair.get(0);
            if (value != null && value.trim().length() > 0) {
                String label = (String) literalPair.get(1);
                if (label != null && label.trim().length() > 0) {
                    optionsMap.put(value, label);
                } else {
                    optionsMap.put(value, value);
                }
                ++optionsCount;
            }
        }
        break;
    case STRINGS_VIA_DATATYPE_PROPERTY:
        log.debug("processing Field \"" + fieldName
                + "\" optionType as a datatype property predicateUri in SelectListGenerator.getOptions()");
        String dataPropUri = field.getPredicateUri();
        if (dataPropUri == null || dataPropUri.equals("")) {
            log.error("no predicate dataPropUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType STRINGS_VIA_DATATYPE_PROPERTY specified");
        } else {
            /* first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption=null;
            if ((defaultOption=getDefaultOption(field))!=null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            } */
            // now populate the options
            log.debug("finding all choices for data property \"" + dataPropUri
                    + "\" in SelectListGenerator.getOptions()");

            if (wDaoFact == null)
                log.error(
                        "incoming WebappDaoFactory from request is null in SelectListGenerator.getOptions().");

            DataPropertyStatementDao dpsDao = wDaoFact.getDataPropertyStatementDao();
            DataPropertyDao dpDao = wDaoFact.getDataPropertyDao();
            DataProperty dp = dpDao.getDataPropertyByURI(dataPropUri);
            for (Iterator<DataPropertyStatement> i = dpsDao.getDataPropertyStatements(dp).iterator(); i
                    .hasNext();) {
                DataPropertyStatement dps = i.next();
                if (dps != null) {
                    optionsMap.put(dps.getData().trim(), dps.getData().trim());
                    ++optionsCount;
                }
            }
        }
        break;
    case INDIVIDUALS_VIA_OBJECT_PROPERTY:
        log.debug("processing Field \"" + fieldName
                + "\" optionType as an object property predicateUri in SelectListGenerator.getOptions()");
        String subjectUri = editConfig.getSubjectUri();
        if (subjectUri == null || subjectUri.equals("")) {
            log.error("no subjectUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified");
        } else {
            String predicateUri = field.getPredicateUri();
            if (predicateUri == null || predicateUri.equals("")) {
                log.error("no predicateUri found for field \"" + fieldName
                        + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified");
            } else {
                // first test to see whether there's a default "leave blank" value specified with the literal options
                String defaultOption = null;
                if ((defaultOption = getDefaultOption(field)) != null) {
                    optionsMap.put(LEFT_BLANK, defaultOption);
                }
                // now populate the options
                log.debug("finding range individuals for subject \"" + subjectUri + "\" and object property \""
                        + predicateUri + "\" in SelectListGenerator.getOptions()");

                if (wDaoFact == null)
                    log.error(
                            "could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

                Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
                if (subject == null)
                    log.error("could not get individual for subject uri " + subjectUri
                            + " in SelectListGenerator.getOptions()");

                ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
                if (objProp == null)
                    log.error("could not get object property for predicate " + predicateUri
                            + " in SelectListGenerator.getOptions()");

                List<VClass> vclasses = new ArrayList<VClass>();
                vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(), predicateUri);
                if (vclasses == null) {
                    log.error("no owl:Class found for predicate " + predicateUri);
                    break;
                }
                if (vclasses.size() == 0)
                    log.error("no owl:Class found for predicate " + predicateUri);

                List<Individual> individuals = new ArrayList<Individual>();
                HashSet<String> uriSet = new HashSet<String>();
                long startTime = System.currentTimeMillis();
                for (VClass vclass : vclasses) {
                    for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),
                            -1, -1)) {
                        if (!uriSet.contains(ind.getURI())) {
                            uriSet.add(ind.getURI());
                            individuals.add(ind);
                        }
                    }
                }

                List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();
                if (stmts == null)
                    log.error("object properties for subject were null in SelectListGenerator.getOptions()");

                individuals = removeIndividualsAlreadyInRange(individuals, stmts, predicateUri,
                        editConfig.getObject());
                //Collections.sort(individuals,new compareIndividualsByName());    

                for (Individual ind : individuals) {
                    String uri = ind.getURI();
                    if (uri != null) {
                        optionsMap.put(uri, ind.getName().trim());
                        ++optionsCount;
                    }
                }

            }
        }
        break;
    case INDIVIDUALS_VIA_VCLASS: //so we have a vclass URI
        vclassUri = field.getObjectClassUri();
        if (vclassUri == null || vclassUri.equals("")) {
            log.error("no vclassUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_VCLASS specified");
        } else {
            // first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption = null;
            if ((defaultOption = getDefaultOption(field)) != null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            }
            // now populate the options                
            if (wDaoFact == null)
                log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

            // if reasoning isn't available, we will also need to add 
            // individuals asserted in subclasses
            boolean inferenceAvailable = false;
            if (wDaoFact instanceof WebappDaoFactoryJena) {
                PelletListener pl = ((WebappDaoFactoryJena) wDaoFact).getPelletListener();
                if (pl != null && pl.isConsistent() && !pl.isInErrorState() && !pl.isReasoning()) {
                    inferenceAvailable = true;
                }
            }

            VClass vclass = wDaoFact.getVClassDao().getVClassByURI(vclassUri);
            if (vclass == null) {
                log.error("Cannot find owl:Class " + vclassUri + " in the model");
                optionsMap.put("", "Could not find class " + vclassUri);
            } else {
                Map<String, Individual> individualMap = new HashMap<String, Individual>();

                for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1,
                        -1)) {
                    if (ind.getURI() != null) {
                        individualMap.put(ind.getURI(), ind);
                    }
                }

                if (!inferenceAvailable) {
                    for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) {
                        for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,
                                -1, -1)) {
                            if (ind.getURI() != null) {
                                individualMap.put(ind.getURI(), ind);
                            }
                        }
                    }
                }

                List<Individual> individuals = new ArrayList<Individual>();
                individuals.addAll(individualMap.values());
                Collections.sort(individuals);

                for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1,
                        -1)) {
                    if (ind.getURI() != null) {
                        individualMap.put(ind.getURI(), ind);
                    }
                }

                if (!inferenceAvailable) {
                    for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) {
                        for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,
                                -1, -1)) {
                            if (ind.getURI() != null) {
                                individualMap.put(ind.getURI(), ind);
                            }
                        }
                    }
                }

                individuals.addAll(individualMap.values());
                Collections.sort(individuals);

                if (individuals.size() == 0) {
                    log.error("No individuals of type " + vclass.getName()
                            + " to add to pick list in SelectListGenerator.getOptions()");
                    optionsMap.put("", "No " + vclass.getName() + " found");
                } else {
                    for (Individual ind : individuals) {
                        String uri = ind.getURI();
                        if (uri != null) {
                            optionsMap.put(uri, ind.getName().trim());
                            ++optionsCount;
                        }
                    }
                }
            }
        }
        break;

    case CHILD_VCLASSES: //so we have a vclass URI
        vclassUri = field.getObjectClassUri();
        if (vclassUri == null || vclassUri.equals("")) {
            log.error("no vclassUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified");
        } else {
            // first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption = null;
            if ((defaultOption = getDefaultOption(field)) != null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            }
            // now populate the options                
            if (wDaoFact == null)
                log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

            VClassDao vclassDao = wDaoFact.getVClassDao();
            List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri);
            if (subClassList == null || subClassList.size() == 0) {
                log.debug("No subclasses of " + vclassUri
                        + " found in the model so only default value from field's literalOptions will be used");
            } else {
                for (String subClassUri : subClassList) {
                    VClass subClass = vclassDao.getVClassByURI(subClassUri);
                    if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
                        optionsMap.put(subClassUri, subClass.getName().trim());
                        ++optionsCount;
                    }
                }
            }
        }
        break;

    case CHILD_VCLASSES_WITH_PARENT: //so we have a vclass URI
        vclassUri = field.getObjectClassUri();
        if (vclassUri == null || vclassUri.equals("")) {
            log.error("no vclassUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified");
        } else {
            // first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption = null;
            if ((defaultOption = getDefaultOption(field)) != null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            }
            // now populate the options                
            if (wDaoFact == null)
                log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

            VClassDao vclassDao = wDaoFact.getVClassDao();
            List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri);
            if (subClassList == null || subClassList.size() == 0) {
                log.debug("No subclasses of " + vclassUri
                        + " found in the model so only default value from field's literalOptions will be used");
            } else {
                for (String subClassUri : subClassList) {
                    VClass subClass = vclassDao.getVClassByURI(subClassUri);
                    if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
                        optionsMap.put(subClassUri, subClass.getName().trim());
                        ++optionsCount;
                    }
                }
                optionsMap.put(vclassUri, "Other");
                ++optionsCount;
            }
        }
        break;

    case VCLASSGROUP:

        String classGroupUri = field.getObjectClassUri(); // we're overloading this property to specify the classgroup
        if (classGroupUri == null || classGroupUri.equals("")) {
            log.error("no classGroupUri found for field \"" + fieldName
                    + "\" in SelectListGenerator.getOptions() when OptionsType VCLASSGROUP specified");
        } else {
            // first test to see whether there's a default "leave blank" value specified with the literal options
            String defaultOption = null;
            if ((defaultOption = getDefaultOption(field)) != null) {
                optionsMap.put(LEFT_BLANK, defaultOption);
            }
            // now populate the options                
            if (wDaoFact == null)
                log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");

            VClassGroupDao vcgd = wDaoFact.getVClassGroupDao();

            // Need to call this method to populate the classgroups - otherwise the classgroup class list is empty
            List vClassGroups = vcgd.getPublicGroupsWithVClasses();

            if (vClassGroups == null) {
                log.error(
                        "No class groups found, so only default value from field's literalOptions will be used.");
            } else {
                VClassGroup vClassGroup = null;
                for (Object o : vClassGroups) {
                    VClassGroup vcg = (VClassGroup) o;
                    if (vcg.getURI().equals(classGroupUri)) {
                        vClassGroup = vcg;
                        break;
                    }
                }
                if (vClassGroup == null) {
                    log.error("No class group with uri " + classGroupUri
                            + "found, so only default value from field's literalOptions will be used.");
                } else {
                    List<VClass> vClassList = vClassGroup.getVitroClassList();

                    if (vClassList == null || vClassList.size() == 0) {
                        log.debug("No classes in class group " + classGroupUri
                                + " found in the model, so only default value from field's literalOptions will be used");
                    } else {
                        for (VClass vClass : vClassList) {
                            String vClassUri = vClass.getURI();
                            if (vClass != null && !OWL.Nothing.getURI().equals(vClassUri)) {
                                optionsMap.put(vClassUri, vClass.getName().trim());
                                ++optionsCount;
                            }
                        }
                    }
                }
            }
        }
        break;

    case UNDEFINED:
        log.error("optionsType \"UNDEFINED\" for Field \"" + fieldName
                + "\" in SelectListGenerator.getOptions()");
        break;
    default:
        log.error("unknown optionsType " + optionsType.toString() + " for Field \"" + fieldName
                + "\" in SelectListGenerator.getOptions()");
    }
    log.debug("added " + optionsCount + " options for field \"" + fieldName
            + "\" in SelectListGenerator.getOptions()");
    return optionsMap;
}

From source file:com.thoughtworks.go.plugin.configrepo.contract.CREnvironment.java

private void validateAgentUniqueness(ErrorCollection errors, String location) {
    HashSet<String> keys = new HashSet<>();
    for (String agent : agents) {
        String lowerCase = agent.toLowerCase();
        if (keys.contains(lowerCase))
            errors.addError(location, String.format("Agent %s is defined more than once", agent));
        else/*from  ww w.  j a  v  a2s  .  c o m*/
            keys.add(lowerCase);
    }
}

From source file:com.thoughtworks.go.plugin.configrepo.contract.CRStage.java

public String validateNameUniqueness(HashSet<String> keys) {
    if (keys.contains(this.getName()))
        return String.format("Stage named %s is defined more than once", this.getName());
    else/*w  w  w  .j av a  2  s.c o m*/
        keys.add(this.getName());
    return null;
}

From source file:com.thoughtworks.go.plugin.configrepo.contract.CREnvironment.java

private void validatePipelineUniqueness(ErrorCollection errors, String location) {
    HashSet<String> keys = new HashSet<>();
    for (String pipeline : pipelines) {
        String lowerCase = pipeline.toLowerCase();
        if (keys.contains(lowerCase))
            errors.addError(location, String.format("Pipeline %s is defined more than once", pipeline));
        else/*from w  ww .j  a  v  a2s  .co  m*/
            keys.add(lowerCase);
    }
}

From source file:edu.harvard.i2b2.patientMapping.serviceClient.PatientMappingQueryClient.java

public static String getlldString(ArrayList<TimelineRow> tlrows, String patientRefId, int minPatient,
        int maxPatient, boolean bDisplayAll, boolean writeFile, boolean displayDemographics,
        MainComposite explorer) {// w w  w  .j av a 2  s. c om

    try {
        HashSet<String> conceptPaths = new HashSet<String>();
        // HashSet<String> providerPaths = new HashSet<String>();
        // HashSet<String> visitPaths = new HashSet<String>();
        ArrayList<PDOItem> items = new ArrayList<PDOItem>();

        for (int i = 0; i < tlrows.size(); i++) {
            for (int j = 0; j < tlrows.get(i).pdoItems.size(); j++) {
                PDOItem pdoItem = tlrows.get(i).pdoItems.get(j);
                String path = pdoItem.fullPath;

                if (conceptPaths.contains(path)) {
                    //continue;
                }
                conceptPaths.add(path);
                // for(int k=0; k<pdoItem.valDisplayProperties.size(); k++)
                // {
                items.add(pdoItem);
                // }
            }
        }

        PDORequestMessageModel pdoFactory = new PDORequestMessageModel();
        String pid = null;
        if (patientRefId.equalsIgnoreCase("All")) {
            pid = "-1";
        } else {
            pid = patientRefId;
        }
        String xmlStr = pdoFactory.requestXmlMessage(items, pid, new Integer(minPatient),
                new Integer(maxPatient), false);
        // explorer.lastRequestMessage(xmlStr);

        String result = null;// sendPDOQueryRequestREST(xmlStr);
        if (System.getProperty("webServiceMethod").equals("SOAP")) {
            result = PatientMappingQueryClient.sendPDOQueryRequestSOAP(xmlStr);
        } else {
            result = PatientMappingQueryClient.sendPDOQueryRequestREST(xmlStr);
        }

        if (result == null || result.equalsIgnoreCase("memory error")) {
            return result;
        }
        // explorer.lastResponseMessage(result);

        return new PatientMappingFactory().generateTimelineData(result, tlrows, writeFile, bDisplayAll,
                displayDemographics, explorer);
    }
    /*
     * catch(org.apache.axis2.AxisFault e) { e.printStackTrace();
     * java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
     * JOptionPane.showMessageDialog(null,
     * "Trouble with connection to the remote server, " +
     * "this is often a network error, please try again", "Network Error",
     * JOptionPane.INFORMATION_MESSAGE); } });
     * 
     * return null; }
     */
    catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.sparql.GetClazzDataProperties.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!isAuthorizedToDisplayPage(request, response, SimplePermission.USE_MISCELLANEOUS_PAGES.ACTION)) {
        return;/*from   w  w w. ja v a  2s.c  o  m*/
    }

    VitroRequest vreq = new VitroRequest(request);

    String vClassURI = vreq.getParameter("vClassURI");
    if (vClassURI == null || vClassURI.trim().equals("")) {
        return;
    }

    String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    respo += "<options>";

    // Add rdfs:label to the list
    respo += "<option>" + "<key>" + "label" + "</key>" + "<value>"
            + "http://www.w3.org/2000/01/rdf-schema#label" + "</value>" + "</option>";

    DataPropertyDao ddao = vreq.getUnfilteredWebappDaoFactory().getDataPropertyDao();

    Collection<DataProperty> dataProps = ddao.getDataPropertiesForVClass(vClassURI);
    Iterator<DataProperty> dataPropIt = dataProps.iterator();
    HashSet<String> dpropURIs = new HashSet<String>();
    while (dataPropIt.hasNext()) {
        DataProperty dp = dataPropIt.next();
        if (!(dpropURIs.contains(dp.getURI()))) {
            dpropURIs.add(dp.getURI());
            DataProperty dprop = (DataProperty) ddao.getDataPropertyByURI(dp.getURI());
            if (dprop != null) {
                respo += "<option>" + "<key>" + dprop.getLocalName() + "</key>" + "<value>" + dprop.getURI()
                        + "</value>" + "</option>";
            }
        }
    }
    respo += "</options>";
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();

    out.println(respo);
    out.flush();
    out.close();
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ConsolidateAssignsRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
        return false;
    }/*w  ww .j a  va2  s  . co m*/
    AssignOperator assign1 = (AssignOperator) op;

    AbstractLogicalOperator op2 = (AbstractLogicalOperator) assign1.getInputs().get(0).getValue();
    if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
        return false;
    }
    AssignOperator assign2 = (AssignOperator) op2;

    HashSet<LogicalVariable> used1 = new HashSet<LogicalVariable>();
    VariableUtilities.getUsedVariables(assign1, used1);
    for (LogicalVariable v2 : assign2.getVariables()) {
        if (used1.contains(v2)) {
            return false;
        }
    }

    assign1.getVariables().addAll(assign2.getVariables());
    assign1.getExpressions().addAll(assign2.getExpressions());

    Mutable<ILogicalOperator> botOpRef = assign2.getInputs().get(0);
    List<Mutable<ILogicalOperator>> asgnInpList = assign1.getInputs();
    asgnInpList.clear();
    asgnInpList.add(botOpRef);
    context.computeAndSetTypeEnvironmentForOperator(assign1);
    return true;
}

From source file:disko.flow.analyzers.ConsoleOutputAnalyzer.java

public void process(AnalysisContext<TextDocument> ctx, Ports ports) throws InterruptedException {
    log.debug("ConsoleOutputAnalyzer starts");
    HashSet<InputPort<?>> closedPorts = new HashSet<InputPort<?>>();

    while (closedPorts.size() < ports.getInputCount()) {
        for (InputPort<?> inputPort : ports.getInputPorts()) {
            if (closedPorts.contains(inputPort))
                continue;
            Object data = inputPort.take();
            if (inputPort.isEOS(data)) {
                closedPorts.add(inputPort);
                continue;
            }/*from  w  w  w  .  j  a va2  s . co m*/
            if (data instanceof EntityMaintainer) {
                EntityMaintainer em = (EntityMaintainer) data;
                System.out.println(inputPort.getChannel() + ": '" + em.getConvertedSentence() + "'\n" + em);
            }
            if (data instanceof SentenceInterpretation) {
                SentenceInterpretation s = (SentenceInterpretation) data;
                System.out.println(s.getSentence());
                for (RelOccurrence occ : s.getRelOccs())
                    System.out.println(occ.getRelation().toString(ctx.getGraph()));
                System.out.println();
            } else {
                System.out.println(inputPort.getChannel() + ":\n'" + data + "'\n");
            }
        }
    }
    log.debug("ConsoleOutputAnalyzer ends");

}