Example usage for java.util Vector elementAt

List of usage examples for java.util Vector elementAt

Introduction

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

Prototype

public synchronized E elementAt(int index) 

Source Link

Document

Returns the component at the specified index.

Usage

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

public ResolvedConceptReferencesIteratorWrapper searchByNameAndCode(Vector<String> schemes,
        Vector<String> versions, String matchText, String source, String matchAlgorithm, boolean ranking,
        int maxToReturn) {
    try {//from  ww  w. j av a 2 s  .  com
        if (matchText == null || matchText.trim().length() == 0)
            return null;

        Utils.StopWatch stopWatch = new Utils.StopWatch();
        Utils.StopWatch stopWatchTotal = new Utils.StopWatch();
        boolean debug_flag = false;

        matchText = matchText.trim();
        _logger.debug("searchByName ... " + matchText);

        // p11.1-q11.1  // /100{WBC}
        if (matchAlgorithm.compareToIgnoreCase("contains") == 0) {
            // matchAlgorithm = Constants.CONTAIN_SEARCH_ALGORITHM;
            matchAlgorithm = findBestContainsAlgorithm(matchText);
        }

        LexBIGService lbSvc = RemoteServerUtil.createLexBIGService();
        Vector<CodedNodeSet> cns_vec = new Vector<CodedNodeSet>();

        for (int i = 0; i < schemes.size(); i++) {
            stopWatch.start();
            String scheme = (String) schemes.elementAt(i);

            CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
            String version = (String) versions.elementAt(i);
            if (version != null)
                versionOrTag.setVersion(version);

            //Name search
            CodedNodeSet cns = getNodeSet(lbSvc, scheme, versionOrTag);
            if (cns != null) {
                cns = cns.restrictToMatchingDesignations(matchText, null, matchAlgorithm, null);
                cns = restrictToSource(cns, source);
            }
            if (cns != null)
                cns_vec.add(cns);

            CodedNodeSet.PropertyType[] propertyTypes = null;
            LocalNameList sourceList = null;
            LocalNameList contextList = null;
            NameAndValueList qualifierList = null;

            // concept code match:

            /*
            CodedNodeSet cns_code = getNodeSet(lbSvc, scheme, versionOrTag);
                    
            if (source != null) {
            cns_code = restrictToSource(cns_code, source);
            }
            CodedNodeSet.PropertyType[] propertyTypes = null;
            LocalNameList sourceList = null;
            LocalNameList contextList = null;
            NameAndValueList qualifierList = null;
            cns_code = cns_code.restrictToMatchingProperties(ConvenienceMethods
            .createLocalNameList(new String[] { "conceptCode" }),
            propertyTypes, sourceList, contextList, qualifierList,
            matchText, CODE_SEARCH_ALGORITHM, null);
            //matchText, "exactMatch", null);
                    
            */
            String code = matchText;
            CodedNodeSet cns_code = getCodedNodeSetContrainingCode(lbSvc, scheme, versionOrTag, code);

            if (cns_code != null && includeInQuickUnion(cns_code)) {
                cns_vec.add(cns_code);
            }

            //if (cns_code != null) cns_vec.add(cns_code);

            // source code match:
            CodedNodeSet cns_src_code = null;

            if (DataUtils.hasSourceCodeQualifier(scheme)) {
                String sourceAbbr = source;

                qualifierList = null;
                if (code != null && code.compareTo("") != 0) {
                    qualifierList = new NameAndValueList();
                    NameAndValue nv = new NameAndValue();
                    nv.setName("source-code");
                    nv.setContent(code);
                    qualifierList.addNameAndValue(nv);
                }

                LocalNameList propertyLnL = null;
                // sourceLnL
                Vector<String> w2 = new Vector<String>();
                LocalNameList sourceLnL = null;

                if (sourceAbbr != null
                        && (sourceAbbr.compareTo("*") == 0 || sourceAbbr.compareToIgnoreCase("ALL") == 0)) {
                    sourceLnL = null;
                } else if (sourceAbbr != null) {
                    w2.add(sourceAbbr);
                    sourceLnL = vector2LocalNameList(w2);
                }

                SortOptionList sortCriteria = null;// Constructors.createSortOptionList(new
                // String[]{"matchToQuery", "code"});
                contextList = null;

                try {
                    cns_src_code = getNodeSet(lbSvc, scheme, versionOrTag);
                    CodedNodeSet.PropertyType[] types = new PropertyType[] { PropertyType.PRESENTATION };
                    cns_src_code = cns_src_code.restrictToProperties(propertyLnL, types, sourceLnL, contextList,
                            qualifierList);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            if (cns_src_code != null)
                cns_vec.add(cns_src_code);

        }

        if (debug_flag)
            _logger.debug("searchByNameAndCode QuickUnion delay (msec): " + stopWatch.duration());

        SortOptionList sortCriteria = null;
        LocalNameList restrictToProperties = new LocalNameList();
        boolean resolveConcepts = false;
        if (ranking) {
            sortCriteria = null;// Constructors.createSortOptionList(new
                                // String[]{"matchToQuery"});
        } else {
            sortCriteria = Constructors.createSortOptionList(new String[] { "entityDescription" }); // code
            _logger.debug("*** Sort alphabetically...");
        }

        stopWatch.start();
        if (debug_flag)
            _logger.debug("Calling cns.resolve to resolve the union CNS ... ");
        ResolvedConceptReferencesIterator iterator = new QuickUnionIterator(cns_vec, sortCriteria, null,
                restrictToProperties, null, resolveConcepts);
        if (debug_flag)
            _logger.debug("Resolve CNS union delay (msec): " + stopWatch.duration());

        _logger.debug("Total search delay (msec): " + stopWatchTotal.duration());
        return new ResolvedConceptReferencesIteratorWrapper(iterator);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

public ResolvedConceptReferencesIteratorWrapper searchByNameOrCode(Vector<String> schemes,
        Vector<String> versions, String matchText, String source, String matchAlgorithm, boolean ranking,
        int maxToReturn, String searchTarget) {
    if (searchTarget == null)
        searchTarget = SEARCH_BY_NAME_ONLY;
    try {//from  w w w.j  ava  2 s .  c  o  m
        if (matchText == null || matchText.trim().length() == 0)
            return null;

        Utils.StopWatch stopWatch = new Utils.StopWatch();
        Utils.StopWatch stopWatchTotal = new Utils.StopWatch();
        boolean debug_flag = false;

        matchText = matchText.trim();
        _logger.debug("searchByName ... " + matchText);

        // p11.1-q11.1  // /100{WBC}
        if (matchAlgorithm.compareToIgnoreCase("contains") == 0) {
            matchAlgorithm = findBestContainsAlgorithm(matchText);
        }
        LexBIGService lbSvc = RemoteServerUtil.createLexBIGService();
        Vector<CodedNodeSet> cns_vec = new Vector<CodedNodeSet>();

        for (int i = 0; i < schemes.size(); i++) {
            stopWatch.start();
            String scheme = (String) schemes.elementAt(i);
            CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
            String version = (String) versions.elementAt(i);
            if (version != null) {
                versionOrTag.setVersion(version);
            }

            //Name search
            if (searchTarget.compareToIgnoreCase(SEARCH_BY_CODE_ONLY) != 0) {
                CodedNodeSet cns = getNodeSet(lbSvc, scheme, versionOrTag);
                if (cns != null) {
                    cns = cns.restrictToMatchingDesignations(matchText, null, matchAlgorithm, null);
                    cns = restrictToSource(cns, source);
                }
                if (cns != null) {
                    cns_vec.add(cns);
                }
            } else {

                CodedNodeSet.PropertyType[] propertyTypes = null;
                LocalNameList sourceList = null;
                LocalNameList contextList = null;
                NameAndValueList qualifierList = null;

                String code = matchText;
                CodedNodeSet cns_code = getCodedNodeSetContrainingCode(lbSvc, scheme, versionOrTag, code);

                if (cns_code != null && includeInQuickUnion(cns_code)) {
                    cns_vec.add(cns_code);
                }

                // source code match:
                CodedNodeSet cns_src_code = null;

                if (DataUtils.hasSourceCodeQualifier(scheme)) {
                    String sourceAbbr = source;

                    qualifierList = null;
                    if (code != null && code.compareTo("") != 0) {
                        qualifierList = new NameAndValueList();
                        NameAndValue nv = new NameAndValue();
                        nv.setName("source-code");
                        nv.setContent(code);
                        qualifierList.addNameAndValue(nv);
                    }

                    LocalNameList propertyLnL = null;
                    // sourceLnL
                    Vector<String> w2 = new Vector<String>();
                    LocalNameList sourceLnL = null;

                    if (sourceAbbr != null
                            && (sourceAbbr.compareTo("*") == 0 || sourceAbbr.compareToIgnoreCase("ALL") == 0)) {
                        sourceLnL = null;
                    } else if (sourceAbbr != null) {
                        w2.add(sourceAbbr);
                        sourceLnL = vector2LocalNameList(w2);
                    }

                    SortOptionList sortCriteria = null;// Constructors.createSortOptionList(new
                    // String[]{"matchToQuery", "code"});
                    contextList = null;

                    try {
                        cns_src_code = getNodeSet(lbSvc, scheme, versionOrTag);
                        CodedNodeSet.PropertyType[] types = new PropertyType[] { PropertyType.PRESENTATION };
                        cns_src_code = cns_src_code.restrictToProperties(propertyLnL, types, sourceLnL,
                                contextList, qualifierList);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                if (cns_src_code != null)
                    cns_vec.add(cns_src_code);
            }
        }
        if (debug_flag)
            _logger.debug("searchByNameAndCode QuickUnion delay (msec): " + stopWatch.duration());

        SortOptionList sortCriteria = null;
        LocalNameList restrictToProperties = new LocalNameList();
        boolean resolveConcepts = false;
        if (ranking) {
            sortCriteria = null;// Constructors.createSortOptionList(new
                                // String[]{"matchToQuery"});
        } else {
            sortCriteria = Constructors.createSortOptionList(new String[] { "entityDescription" }); // code
            _logger.debug("*** Sort alphabetically...");
        }

        stopWatch.start();
        if (debug_flag)
            _logger.debug("Calling cns.resolve to resolve the union CNS ... ");

        ResolvedConceptReferencesIterator iterator = new QuickUnionIterator(cns_vec, sortCriteria, null,
                restrictToProperties, null, resolveConcepts);
        if (debug_flag)
            _logger.debug("Resolve CNS union delay (msec): " + stopWatch.duration());

        _logger.debug("Total search delay (msec): " + stopWatchTotal.duration());
        return new ResolvedConceptReferencesIteratorWrapper(iterator);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.apache.webdav.lib.WebdavResource.java

/**
 * Get an array of pathnames denoting the WebDAV resources in the
 * collection denoted by this pathname./* ww  w.  j  a  v a  2s . co m*/
 *
 * @return An array of pathnames denoting the resources, null if an
 *         IOException occurs.
 */
public String[] list() {

    try {
        setNameProperties(DepthSupport.DEPTH_1);
    } catch (IOException e) {
        return null;
    }
    Enumeration hrefs = childResources.getResourceNames();

    // To be atomic.
    Vector hrefList = new Vector();
    while (hrefs.hasMoreElements()) {
        hrefList.addElement((String) hrefs.nextElement());
    }
    // Calculate the size of the string array.
    int num = hrefList.size();
    String[] pathnames = new String[num];
    for (int i = 0; i < num; i++) {
        pathnames[i] = (String) hrefList.elementAt(i);
    }

    return pathnames;
}

From source file:com.splicemachine.db.impl.sql.compile.TableElementList.java

/**
 * Validate this TableElementList.  This includes checking for
 * duplicate columns names, and checking that user types really exist.
 *
 * @param ddlStmt   DDLStatementNode which contains this list
 * @param dd      DataDictionary to use//from ww w .ja  v a  2 s.  c o  m
 * @param td      TableDescriptor for table, if existing table.
 *
 * @exception StandardException      Thrown on error
 */
void validate(DDLStatementNode ddlStmt, DataDictionary dd, TableDescriptor td) throws StandardException {
    this.td = td;
    int numAutoCols = 0;

    int size = size();
    Hashtable columnHT = new Hashtable(size + 2, (float) .999);
    Hashtable constraintHT = new Hashtable(size + 2, (float) .999);
    //all the primary key/unique key constraints for this table
    Vector constraintsVector = new Vector();

    //special case for alter table (td is not null in case of alter table)
    if (td != null) {
        //In case of alter table, get the already existing primary key and unique
        //key constraints for this table. And then we will compare them with  new
        //primary key/unique key constraint column lists.
        ConstraintDescriptorList cdl = dd.getConstraintDescriptors(td);
        ConstraintDescriptor cd;

        if (cdl != null) //table does have some pre-existing constraints defined on it
        {
            for (int i = 0; i < cdl.size(); i++) {
                cd = cdl.elementAt(i);
                //if the constraint type is not primary key or unique key, ignore it.
                if (cd.getConstraintType() == DataDictionary.PRIMARYKEY_CONSTRAINT
                        || cd.getConstraintType() == DataDictionary.UNIQUE_CONSTRAINT)
                    constraintsVector.addElement(cd);
            }
        }
    }

    int tableType = TableDescriptor.BASE_TABLE_TYPE;
    if (ddlStmt instanceof CreateTableNode)
        tableType = ((CreateTableNode) ddlStmt).tableType;

    for (int index = 0; index < size; index++) {
        TableElementNode tableElement = (TableElementNode) elementAt(index);

        if (tableElement instanceof ColumnDefinitionNode) {
            ColumnDefinitionNode cdn = (ColumnDefinitionNode) elementAt(index);
            if (tableType == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE
                    && (cdn.getType().getTypeId().isLongConcatableTypeId()
                            || cdn.getType().getTypeId().isUserDefinedTypeId())) {
                throw StandardException.newException(SQLState.LANG_LONG_DATA_TYPE_NOT_ALLOWED,
                        cdn.getColumnName());
            }
            checkForDuplicateColumns(ddlStmt, columnHT, cdn.getColumnName());
            cdn.checkUserType(td);
            cdn.bindAndValidateDefault(dd, td);

            cdn.validateAutoincrement(dd, td, tableType);

            if (tableElement instanceof ModifyColumnNode) {
                ModifyColumnNode mcdn = (ModifyColumnNode) cdn;
                mcdn.checkExistingConstraints(td);
                mcdn.useExistingCollation(td);

            } else if (cdn.isAutoincrementColumn()) {
                numAutoCols++;
            }
        } else if (tableElement.getElementType() == TableElementNode.AT_DROP_COLUMN) {
            String colName = tableElement.getName();
            if (td.getColumnDescriptor(colName) == null) {
                throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE, colName,
                        td.getQualifiedName());
            }
            break;
        }

        /* The rest of this method deals with validating constraints */
        if (!(tableElement.hasConstraint())) {
            continue;
        }

        ConstraintDefinitionNode cdn = (ConstraintDefinitionNode) tableElement;

        cdn.bind(ddlStmt, dd);

        //if constraint is primary key or unique key, add it to the vector
        if (cdn.getConstraintType() == DataDictionary.PRIMARYKEY_CONSTRAINT
                || cdn.getConstraintType() == DataDictionary.UNIQUE_CONSTRAINT) {
            /* In case of create table, the vector can have only ConstraintDefinitionNode
            * elements. In case of alter table, it can have both ConstraintDefinitionNode
            * (for new constraints) and ConstraintDescriptor(for pre-existing constraints).
            */

            Object destConstraint;
            String destName = null;
            String[] destColumnNames = null;

            for (int i = 0; i < constraintsVector.size(); i++) {

                destConstraint = constraintsVector.elementAt(i);
                if (destConstraint instanceof ConstraintDefinitionNode) {
                    ConstraintDefinitionNode destCDN = (ConstraintDefinitionNode) destConstraint;
                    destName = destCDN.getConstraintMoniker();
                    destColumnNames = destCDN.getColumnList().getColumnNames();
                } else if (destConstraint instanceof ConstraintDescriptor) {
                    //will come here only for pre-existing constraints in case of alter table
                    ConstraintDescriptor destCD = (ConstraintDescriptor) destConstraint;
                    destName = destCD.getConstraintName();
                    destColumnNames = destCD.getColumnDescriptors().getColumnNames();
                }
                //check if there are multiple constraints with same set of columns
                if (columnsMatch(cdn.getColumnList().getColumnNames(), destColumnNames))
                    throw StandardException.newException(SQLState.LANG_MULTIPLE_CONSTRAINTS_WITH_SAME_COLUMNS,
                            cdn.getConstraintMoniker(), destName);
            }
            constraintsVector.addElement(cdn);
        }

        /* Make sure that there are no duplicate constraint names in the list */
        checkForDuplicateConstraintNames(ddlStmt, constraintHT, cdn.getConstraintMoniker());

        /* Make sure that the constraint we are trying to drop exists */
        if (cdn.getConstraintType() == DataDictionary.DROP_CONSTRAINT) {
            /*
            ** If no schema descriptor, then must be an invalid
            ** schema name.
            */

            String dropConstraintName = cdn.getConstraintMoniker();

            if (dropConstraintName != null) {

                String dropSchemaName = cdn.getDropSchemaName();

                SchemaDescriptor sd = dropSchemaName == null ? td.getSchemaDescriptor()
                        : getSchemaDescriptor(dropSchemaName);

                ConstraintDescriptor cd = dd.getConstraintDescriptorByName(td, sd, dropConstraintName, false);
                if (cd == null) {
                    throw StandardException.newException(SQLState.LANG_DROP_NON_EXISTENT_CONSTRAINT,
                            (sd.getSchemaName() + "." + dropConstraintName), td.getQualifiedName());
                }
                /* Statement is dependendent on the ConstraintDescriptor */
                getCompilerContext().createDependency(cd);
            }
        }

        // validation of primary key nullability moved to validatePrimaryKeyNullability().
        if (cdn.hasPrimaryKeyConstraint()) {
            // for PRIMARY KEY, check that columns are unique
            verifyUniqueColumnList(ddlStmt, cdn);
        } else if (cdn.hasUniqueKeyConstraint()) {
            // for UNIQUE, check that columns are unique
            verifyUniqueColumnList(ddlStmt, cdn);
        } else if (cdn.hasForeignKeyConstraint()) {
            // for FOREIGN KEY, check that columns are unique
            verifyUniqueColumnList(ddlStmt, cdn);
        }
    }

    /* Can have only one autoincrement column in DB2 mode */
    if (numAutoCols > 1)
        throw StandardException.newException(SQLState.LANG_MULTIPLE_AUTOINCREMENT_COLUMNS);

}

From source file:gov.nih.nci.evs.browser.utils.DataUtils.java

public Vector getSiblingsExt(String CUI) {
    Vector v = new Vector();
    HashSet hset = new HashSet();
    List results = getAssociatedConceptsEx(CUI, "PAR", Direction.TARGETOF);

    if (results == null)
        return null;

    HashMap hmap = new HashMap();
    Vector key_vec = new Vector();

    for (int i = 0; i < results.size(); i++) {
        RelationshipTabResults result = (RelationshipTabResults) results.get(i);
        List children = getAssociatedConceptsEx(result.getCui(), "CHD", Direction.TARGETOF);

        for (int j = 0; j < children.size(); j++) {
            RelationshipTabResults sub_result = (RelationshipTabResults) children.get(j);
            String t = "SIB" + "|" + sub_result.getName() + "|" + sub_result.getCui() + "|"
                    + sub_result.getSource();
            if (!hset.contains(t) && sub_result.getCui().compareTo(CUI) != 0) {
                hset.add(t);/*from   ww w .j  av a2s . c  o  m*/
                // v.add(t);
                String key = sub_result.getSource() + "|" + sub_result.getName() + "|" + sub_result.getCui();
                hmap.put(key, t);
                key_vec.add(key);
            }
        }
    }

    key_vec = SortUtils.quickSort(key_vec);
    for (int i = 0; i < key_vec.size(); i++) {
        String key = (String) key_vec.elementAt(i);
        String value = (String) hmap.get(key);
        v.add(value);
    }

    // return SortUtils.quickSort(v);
    return v;
}

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

public ResolvedConceptReferencesIteratorWrapper searchByProperties(Vector schemes, Vector versions,
        String matchText, String source, String matchAlgorithm, boolean excludeDesignation, boolean ranking,
        int maxToReturn) {

    if (matchAlgorithm == null || matchText == null) {
        return null;
    }/*from ww  w.j  av a  2  s  . c om*/

    String matchText0 = matchText;
    String matchAlgorithm0 = matchAlgorithm;
    matchText0 = matchText0.trim();

    _logger.debug("searchByProperties..." + matchText);

    //if (matchText == null || matchText.length() == 0) {
    if (matchText.length() == 0) {
        return null;
    }

    matchText = matchText.trim();
    if (matchAlgorithm.compareToIgnoreCase("contains") == 0) {
        matchAlgorithm = findBestContainsAlgorithm(matchText);
    }

    CodedNodeSet cns = null;
    ResolvedConceptReferencesIterator iterator = null;

    String scheme = null;
    String version = null;

    try {
        LexBIGService lbSvc = new RemoteServerUtil().createLexBIGService();

        if (lbSvc == null) {
            _logger.warn("lbSvc = null");
            return null;
        }

        Vector cns_vec = new Vector();
        for (int i = 0; i < schemes.size(); i++) {
            cns = null;
            iterator = null;
            scheme = (String) schemes.elementAt(i);
            CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
            version = (String) versions.elementAt(i);
            if (version != null)
                versionOrTag.setVersion(version);

            try {
                //cns = lbSvc.getNodeSet(scheme, versionOrTag, null);
                cns = getNodeSet(lbSvc, scheme, versionOrTag);

                if (cns != null) {
                    try {
                        LocalNameList propertyNames = new LocalNameList();
                        CodedNodeSet.PropertyType[] propertyTypes = getAllPropertyTypes();

                        if (excludeDesignation) {
                            propertyTypes = getAllNonPresentationPropertyTypes();
                        }

                        String language = null;
                        try {
                            cns = cns.restrictToMatchingProperties(propertyNames, propertyTypes, matchText,
                                    matchAlgorithm, language);
                        } catch (Exception e) {
                            _logger.error("\t(*) restrictToMatchingProperties throws exceptions???: "
                                    + matchText + " matchAlgorithm: " + matchAlgorithm);
                            // e.printStackTrace();
                        }
                        try {
                            cns = restrictToSource(cns, source);
                        } catch (Exception e) {
                            _logger.error("\t(*) restrictToSource throws exceptions???: " + matchText
                                    + " matchAlgorithm: " + matchAlgorithm);
                            // e.printStackTrace();
                        }

                    } catch (Exception ex) {
                        _logger.error("\t(*) searchByProperties2 throws exceptions.");
                        // ex.printStackTrace();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                // return null;
            }
            if (cns != null) {
                cns_vec.add(cns);
            }
        }

        iterator = null;
        /*
         * cns = union(cns_vec); if (cns == null) return null;
         */

        LocalNameList restrictToProperties = null;// new LocalNameList();
        boolean resolveConcepts = false;
        SortOptionList sortCriteria = null;
        if (ranking) {
            sortCriteria = Constructors.createSortOptionList(new String[] { "matchToQuery" });

        } else {
            sortCriteria = Constructors.createSortOptionList(new String[] { "entityDescription" }); // code
            _logger.debug("*** Sort alphabetically...");
            resolveConcepts = false;
        }
        try {
            try {
                long ms = System.currentTimeMillis(), delay = 0;
                // iterator = cns.resolve(sortCriteria, null,
                // restrictToProperties, null, resolveConcepts);
                iterator = new QuickUnionIterator(cns_vec, sortCriteria, null, restrictToProperties, null,
                        resolveConcepts);

            } catch (Exception e) {
                _logger.error("Method: SearchUtil.searchByProperties");
                _logger.error("* ERROR: cns.resolve throws exceptions.");
                _logger.error("* " + e.getClass().getSimpleName() + ": " + e.getMessage());
                e.printStackTrace();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    if (!excludeDesignation) {
        int lcv = 0;
        int iterator_size = 0;
        if (iterator != null) {
            try {
                iterator_size = iterator.numberRemaining();
            } catch (Exception ex) {

            }
        }

        while (iterator_size == 0 && lcv < schemes.size()) {
            scheme = (String) schemes.elementAt(lcv);
            CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
            version = (String) versions.elementAt(lcv);
            if (version != null)
                versionOrTag.setVersion(version);

            iterator = matchConceptCode(scheme, version, matchText0, source, CODE_SEARCH_ALGORITHM);
            if (iterator != null) {
                try {
                    iterator_size = iterator.numberRemaining();
                } catch (Exception ex) {

                }
            }
            lcv++;
        }
    }
    // return iterator;
    return new ResolvedConceptReferencesIteratorWrapper(iterator);

}

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

public ResolvedConceptReferencesIteratorWrapper searchByAssociations(Vector schemes, Vector versions,
        String matchText, String source, String matchAlgorithm, boolean designationOnly, boolean ranking,
        int maxToReturn) {

    if (matchText == null)
        return null;

    Vector codingSchemeNames = new Vector();
    String matchText0 = matchText;
    String matchAlgorithm0 = matchAlgorithm;
    //matchText0 = matchText0.trim();

    boolean containsMapping = false;
    _logger.debug("searchByAssociations..." + matchText);
    long ms = System.currentTimeMillis();
    long dt = 0;/*from  w  ww  . j a  v  a2  s.  com*/
    long total_delay = 0;
    boolean timeout = false;

    boolean preprocess = true;
    //if (matchText == null || matchText.length() == 0) {
    if (matchText.length() == 0) {
        return null;
    }

    matchText = matchText.trim();
    if (matchAlgorithm.compareToIgnoreCase("contains") == 0) {
        // matchAlgorithm = Constants.CONTAIN_SEARCH_ALGORITHM; // to be
        // replaced by literalSubString
        matchAlgorithm = findBestContainsAlgorithm(matchText);
    }

    CodedNodeSet cns = null;
    ResolvedConceptReferencesIterator iterator = null;

    String scheme = null;
    String version = null;
    String message = null;

    try {
        LexBIGService lbSvc = new RemoteServerUtil().createLexBIGService();

        if (lbSvc == null) {
            _logger.warn("lbSvc = null");
            return null;
        }

        Vector cns_vec = new Vector();

        for (int i = 0; i < schemes.size(); i++) {
            cns = null;
            iterator = null;
            scheme = (String) schemes.elementAt(i);

            _logger.debug("\tsearching " + scheme);

            ms = System.currentTimeMillis();
            CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
            version = (String) versions.elementAt(i);
            if (version != null)
                versionOrTag.setVersion(version);

            // i++;

            try {
                // KLO, 022410 change failed
                //cns = lbSvc.getNodeSet(scheme, versionOrTag, null);

                cns = getNodeSet(lbSvc, scheme, versionOrTag);

                // cns = getNodeSetByEntityType(scheme, versionOrTag,
                // "concept");

                if (cns != null) {
                    try {
                        // find cns
                        if (designationOnly) {
                            try {

                                cns = cns.restrictToMatchingDesignations(matchText, null, matchAlgorithm, null);

                            } catch (Exception ex) {
                                ex.printStackTrace();
                                return null;
                            }
                        }

                        cns = restrictToSource(cns, source);

                        String associationName = null;
                        int direction = RESTRICT_TARGET;
                        // CodedNodeGraph cng =
                        // getRestrictedCodedNodeGraph(lbSvc, scheme,
                        // version, associationName, cns, direction);
                        // toNode
                        boolean resolveForward = false;
                        boolean resolveBackward = true;

                        int resolveAssociationDepth = 1;
                        // int maxToReturn = -1;
                        ConceptReference graphFocus = null;
                        // CodedNodeSet cns2 = cng.toNodeList(graphFocus,
                        // resolveForward, resolveBackward,
                        // resolveAssociationDepth, maxToReturn);
                        // CodedNodeSet difference(CodedNodeSet
                        // codesToRemove)
                        // cns = cns2.difference(cns);

                        //if (cns != null) {
                        /*
                        cns =
                            filterOutAnonymousClasses(lbSvc, scheme,
                                cns);
                        */
                        //if (cns != null) {
                        cns_vec.add(cns);
                        codingSchemeNames.add(scheme);

                        if (!containsMapping) {
                            boolean isMapping = DataUtils.isMapping(scheme, null);
                            if (isMapping) {
                                containsMapping = true;
                            }
                        }
                        //}
                        //}
                    } catch (Exception ex) {
                        // return null;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                // return null;
            }

            dt = System.currentTimeMillis() - ms;
            ms = System.currentTimeMillis();
            total_delay = total_delay + dt;

            //if (total_delay > (long) (NCItBrowserProperties.getPaginationTimeOut() * 60 * 1000)) {
            if (total_delay > Constants.MILLISECONDS_PER_MINUTE
                    * NCItBrowserProperties.getPaginationTimeOut()) {
                message = "WARNING: Search is incomplete -- please enter more specific search criteria.";
                // cont_flag = false;
                break;
            }
        }

        iterator = null;
        if (cns_vec.size() == 0) {
            return null;
        }
        /*
         * cns = union(cns_vec); if (cns == null) return null;
         */

        LocalNameList restrictToProperties = null;// new LocalNameList();
        // boolean resolveConcepts = true;
        // if (!ranking) resolveConcepts = false;
        boolean resolveConcepts = false;

        SortOptionList sortCriteria = null;

        if (ranking) {
            sortCriteria = Constructors.createSortOptionList(new String[] { "matchToQuery" });

        } else {
            sortCriteria = Constructors.createSortOptionList(new String[] { "entityDescription" }); // code
            _logger.debug("*** Sort alphabetically...");
            // resolveConcepts = false;
        }
        // Need to set to true to retrieve concept name
        resolveConcepts = true;
        try {

            try {
                boolean resolveForward = false;
                boolean resolveBackward = true;

                int resolveAssociationDepth = 1;
                // iterator = cns.resolve(sortCriteria, null,
                // restrictToProperties, null, resolveConcepts);

                if (!containsMapping) {
                    ResolvedConceptReferencesIterator quickUnionIterator = new QuickUnionIterator(cns_vec,
                            sortCriteria, null, restrictToProperties, null, resolveConcepts);
                    /*
                    try {
                    int quickIteratorNumberRemaining = quickUnionIterator.numberRemaining();
                            
                    } catch (Exception ex) {
                    ex.printStackTrace();
                    }
                    */

                    /*
                                      iterator =
                                         new SearchByAssociationIteratorDecorator(
                                            quickUnionIterator, resolveForward,
                                            resolveBackward, resolveAssociationDepth,
                                            maxToReturn);
                    */

                    iterator = createSearchByAssociationIteratorDecorator(quickUnionIterator, resolveForward,
                            resolveBackward, resolveAssociationDepth, maxToReturn);

                } else {

                    ResolvedConceptReferencesIterator quickUnionIteratorWrapper = new QuickUnionIteratorWrapper(
                            codingSchemeNames, cns_vec, sortCriteria, null, restrictToProperties, null,
                            resolveConcepts);

                    /*
                                      iterator =
                                         new SearchByAssociationIteratorDecorator(
                                            QuickUnionIteratorWrapper, resolveForward,
                                            resolveBackward, resolveAssociationDepth,
                                            maxToReturn);
                    */

                    iterator = createSearchByAssociationIteratorDecorator(quickUnionIteratorWrapper,
                            resolveForward, resolveBackward, resolveAssociationDepth, maxToReturn);

                }

            } catch (Exception e) {
                _logger.error("Method: SearchUtil.searchByAssociations");
                _logger.error("* ERROR: cns.resolve throws exceptions.");
                _logger.error("* " + e.getClass().getSimpleName() + ": " + e.getMessage());
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    // Pending LexEVS fix:
    // if (iterator != null) iterator.setMessage(message);
    // return iterator;
    return new ResolvedConceptReferencesIteratorWrapper(iterator, message);
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Adjust all the column width for the data in the column, this may be handles with JDK 1.6 (6.)
 * @param tableArg the table that should have it's columns adjusted
 *//*from  w  w w. j a  va2s.c  o  m*/
private void initColumnSizes(final JTable tableArg, final JButton theSaveBtn) throws Exception {
    TableModel tblModel = tableArg.getModel();
    TableColumn column = null;
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;

    Element uploadDefs = null;
    if (WorkbenchTask.isCustomizedSchema()) {
        uploadDefs = XMLHelper.readFileToDOM4J(
                new File(UIRegistry.getAppDataDir() + File.separator + "specify_workbench_upload_def.xml"));
    } else {
        uploadDefs = XMLHelper.readDOMFromConfigDir("specify_workbench_upload_def.xml");
    }

    //UIRegistry.getInstance().hookUpUndoableEditListener(cellEditor);

    Vector<WorkbenchTemplateMappingItem> wbtmis = new Vector<WorkbenchTemplateMappingItem>();
    wbtmis.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems());
    Collections.sort(wbtmis);

    DBTableIdMgr databaseSchema = WorkbenchTask.getDatabaseSchema();

    columnMaxWidths = new Integer[tableArg.getColumnCount()];
    for (int i = 0; i < wbtmis.size() /*tableArg.getColumnCount()*/; i++) {
        TableCellRenderer headerRenderer = tableArg.getColumnModel().getColumn(i).getHeaderRenderer();
        WorkbenchTemplateMappingItem wbtmi = wbtmis.elementAt(i);

        // Now go retrieve the data length
        int fieldWidth = WorkbenchDataItem.getMaxWBCellLength();
        DBTableInfo ti = databaseSchema.getInfoById(wbtmi.getSrcTableId());
        if (ti != null) {
            DBFieldInfo fi = ti.getFieldByName(wbtmi.getFieldName());
            if (fi != null) {
                wbtmi.setFieldInfo(fi);
                //System.out.println(fi.getName()+"  "+fi.getLength()+"  "+fi.getType());
                if (RecordTypeCodeBuilder.getTypeCode(fi) == null && fi.getLength() > 0) {
                    fieldWidth = Math.min(fi.getLength(), WorkbenchDataItem.getMaxWBCellLength());
                }
            } else {
                log.error("Can't find field with name [" + wbtmi.getFieldName() + "]");
            }
        } else {
            log.error("Can't find table [" + wbtmi.getSrcTableId() + "]");
        }
        columnMaxWidths[i] = new Integer(fieldWidth);
        GridCellEditor cellEditor = getCellEditor(wbtmi, fieldWidth, theSaveBtn, uploadDefs);
        column = tableArg.getColumnModel().getColumn(i);

        comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
        headerWidth = comp.getPreferredSize().width;

        comp = tableArg.getDefaultRenderer(tblModel.getColumnClass(i)).getTableCellRendererComponent(tableArg,
                tblModel.getValueAt(0, i), false, false, 0, i);

        cellWidth = comp.getPreferredSize().width;

        //comp.setBackground(Color.WHITE);

        int maxWidth = headerWidth + 10;
        TableModel m = tableArg.getModel();
        FontMetrics fm = comp.getFontMetrics(comp.getFont());
        for (int row = 0; row < tableArg.getModel().getRowCount(); row++) {
            String text = m.getValueAt(row, i).toString();
            maxWidth = Math.max(maxWidth, fm.stringWidth(text) + 10);
            //log.debug(i+" "+maxWidth);
        }

        //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
        //log.debug(Math.max(maxWidth, cellWidth));
        //log.debug(Math.min(Math.max(maxWidth, cellWidth), 400));
        column.setPreferredWidth(Math.min(Math.max(maxWidth, cellWidth), 400));

        column.setCellEditor(cellEditor);
    }
    //tableArg.setCellEditor(cellEditor);
}

From source file:gov.nih.nci.evs.browser.utils.DataUtils.java

public Vector getNeighborhoodSynonyms(String CUI, String sab) {
    Debug.println("(*) getNeighborhoodSynonyms ..." + sab);
    List<String> par_chd_assoc_list = new ArrayList();
    par_chd_assoc_list.add("CHD");
    par_chd_assoc_list.add("RB");
    // par_chd_assoc_list.add("RN");

    //Vector ret_vec = new Vector();

    Vector parent_asso_vec = new Vector(Arrays.asList(_hierAssocToParentNodes));
    Vector child_asso_vec = new Vector(Arrays.asList(_hierAssocToChildNodes));
    Vector sibling_asso_vec = new Vector(Arrays.asList(_assocToSiblingNodes));
    Vector bt_vec = new Vector(Arrays.asList(_assocToBTNodes));
    Vector nt_vec = new Vector(Arrays.asList(_assocToNTNodes));

    Vector w = new Vector();
    //HashSet hset = new HashSet();
    HashSet rel_hset = new HashSet();
    HashSet hasSubtype_hset = new HashSet();

    long ms_categorization_delay = 0;
    long ms_categorization;

    long ms_find_highest_rank_atom_delay = 0;
    long ms_find_highest_rank_atom;

    long ms_remove_RO_delay = 0;
    long ms_remove_RO;

    long ms_all_delay = 0;
    long ms_all;/*from  w w  w  . ja  v a 2s. c  o m*/

    String action_overall = "By source delay (total time)";
    ms_all = System.currentTimeMillis();

    long ms = System.currentTimeMillis(), delay = 0;
    String action = null;// "Retrieving distance-one relationships from the server";
    // HashMap hmap = getAssociatedConceptsHashMap(scheme, version, code,
    // sab);
    // HashMap hmap = getRelatedConceptsHashMap(scheme, version, code, sab);

    Map<String, List<BySourceTabResults>> map = null;
    Map<String, List<BySourceTabResults>> map2 = null;

    LexBIGService lbs = RemoteServerUtil.createLexBIGService();
    MetaBrowserService mbs = null;

    try {
        action = "Retrieve data from browser extension";
        ms = System.currentTimeMillis();
        mbs = (MetaBrowserService) lbs.getGenericExtension("metabrowser-extension");

        // String actionTmp = "Getting " + SOURCE_OF;
        // long msTmp = System.currentTimeMillis();
        map = mbs.getBySourceTabDisplay(CUI, sab, null, Direction.SOURCEOF);
        // Debug.println("Run time (ms) " + actionTmp + " " +
        // (System.currentTimeMillis() - msTmp));

        // actionTmp = "Getting " + TARGET_OF;
        // msTmp = System.currentTimeMillis();
        // to be modified: BT and PAR only???
        map2 = mbs.getBySourceTabDisplay(CUI, sab, par_chd_assoc_list, Direction.TARGETOF);
        // Debug.println("Run time (ms) " + actionTmp + " " +
        // (System.currentTimeMillis() - msTmp));

        delay = System.currentTimeMillis() - ms;
        Debug.println("Run time (ms) for " + action + " " + delay);
        DBG.debugDetails(delay, action, "getNeighborhoodSynonyms");
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    action = "Sort synonyms by CUI";
    ms = System.currentTimeMillis();

    Vector u = new Vector();
    HashMap cui2SynonymsMap = createCUI2SynonymsHahMap(map, map2);
    delay = System.currentTimeMillis() - ms;
    Debug.println("Run time (ms) for " + action + " " + delay);
    DBG.debugDetails(delay, action, "getNeighborhoodSynonyms");

    HashSet CUI_hashset = new HashSet();

    ms = System.currentTimeMillis();
    action = "Categorizing relationships into six categories; finding source data for each relationship";

    ms_find_highest_rank_atom_delay = 0;
    String t = null;
    if (map != null) {

        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            Entry thisEntry = (Entry) it.next();
            String rel = (String) thisEntry.getKey();
            List<BySourceTabResults> relations = (List<BySourceTabResults>) thisEntry.getValue();

            //or (String rel : map.keySet()) {
            //List<BySourceTabResults> relations = map.get(rel);
            if (rel.compareTo(INCOMPLETE) != 0) {
                String category = "Other";
                /*
                 * if (parent_asso_vec.contains(rel)) category = "Parent"; else
                 * if (child_asso_vec.contains(rel)) category = "Child"; else if
                 * (bt_vec.contains(rel)) category = "Broader"; else if
                 * (nt_vec.contains(rel)) category = "Narrower";
                 */
                if (parent_asso_vec.contains(rel))
                    category = "Child";
                else if (child_asso_vec.contains(rel))
                    category = "Parent";
                else if (bt_vec.contains(rel))
                    category = "Narrower";
                else if (nt_vec.contains(rel))
                    category = "Broader";

                else if (sibling_asso_vec.contains(rel))
                    category = "Sibling";

                for (BySourceTabResults result : relations) {
                    String code = result.getCui();
                    if (code.compareTo(CUI) != 0 && code.indexOf("@") == -1) {
                        // check CUI_hashmap containsKey(rel$code)???
                        if (!CUI_hashset.contains(rel + "$" + code)) {
                            String rela = result.getRela();
                            if (rela == null || rela.compareTo("null") == 0) {
                                rela = " ";
                            }
                            Vector v = (Vector) cui2SynonymsMap.get(code);
                            ms_find_highest_rank_atom = System.currentTimeMillis();
                            BySourceTabResults top_atom = findHighestRankedAtom(v, sab);
                            ms_find_highest_rank_atom_delay = ms_find_highest_rank_atom_delay
                                    + (System.currentTimeMillis() - ms_find_highest_rank_atom);

                            /*
                             * if (top_atom == null) { Concept c =
                             * getConceptByCode("NCI Metathesaurus", null, null,
                             * code); t = c.getEntityDescription().getContent()
                             * + "|" + Constants.EXTERNAL_TERM_TYPE + "|" +
                             * Constants.EXTERNAL_TERM_SOURCE + "|" +
                             * Constants.EXTERNAL_TERM_SOURCE_CODE; } else { t =
                             * top_atom.getTerm() + "|" + top_atom.getType() +
                             * "|" + top_atom.getSource() + "|" +
                             * top_atom.getCode(); } t = t + "|" + code + "|" +
                             * rela + "|" + category;
                             *
                             * w.add(t);
                             */

                            if (top_atom == null) {
                                for (int k = 0; k < v.size(); k++) {
                                    top_atom = (BySourceTabResults) v.elementAt(k);
                                    t = top_atom.getTerm() + "|" + top_atom.getType() + "|"
                                            + top_atom.getSource() + "|" + top_atom.getCode();
                                    t = t + "|" + code + "|" + top_atom.getRela() + "|" + category;
                                    w.add(t);
                                }
                            } else {
                                t = top_atom.getTerm() + "|" + top_atom.getType() + "|" + top_atom.getSource()
                                        + "|" + top_atom.getCode();
                                t = t + "|" + code + "|" + rela + "|" + category;
                                w.add(t);
                            }

                            CUI_hashset.add(rel + "$" + code);

                            // Temporarily save non-RO other relationships
                            if (category.compareTo("Other") == 0 && rela.compareTo("RO") != 0) {
                                if (!rel_hset.contains(code)) {
                                    rel_hset.add(code);
                                }
                            }

                            if (category.compareTo("Child") == 0 && rela.compareTo("CHD") != 0) {
                                if (!hasSubtype_hset.contains(code)) {
                                    hasSubtype_hset.add(code);
                                }
                            }

                        }
                    }
                }
            }
        }
    }

    // *** do the same for map2
    if (map2 != null) {

        Iterator it = map2.entrySet().iterator();
        while (it.hasNext()) {
            Entry thisEntry = (Entry) it.next();
            String rel = (String) thisEntry.getKey();
            List<BySourceTabResults> relations = (List<BySourceTabResults>) thisEntry.getValue();

            //for (String rel : map2.keySet()) {
            //List<BySourceTabResults> relations = map2.get(rel);
            if (rel.compareTo(INCOMPLETE) != 0) {
                String category = "Other";
                /*
                 * if (parent_asso_vec.contains(rel)) category = "Parent"; else
                 * if (child_asso_vec.contains(rel)) category = "Child"; else if
                 * (bt_vec.contains(rel)) category = "Broader"; else if
                 * (nt_vec.contains(rel)) category = "Narrower";
                 */

                if (parent_asso_vec.contains(rel))
                    category = "Child";
                else if (child_asso_vec.contains(rel))
                    category = "Parent";
                else if (bt_vec.contains(rel))
                    category = "Narrower";
                else if (nt_vec.contains(rel))
                    category = "Broader";

                else if (sibling_asso_vec.contains(rel))
                    category = "Sibling";

                for (BySourceTabResults result : relations) {
                    String code = result.getCui();

                    if (code.compareTo(CUI) != 0 && code.indexOf("@") == -1) {
                        if (!CUI_hashset.contains(rel + "$" + code)) {
                            String rela = result.getRela();
                            if (rela == null || rela.compareTo("null") == 0) {
                                rela = " ";
                            }
                            Vector v = (Vector) cui2SynonymsMap.get(code);

                            ms_find_highest_rank_atom = System.currentTimeMillis();
                            BySourceTabResults top_atom = findHighestRankedAtom(v, sab);
                            ms_find_highest_rank_atom_delay = ms_find_highest_rank_atom_delay
                                    + (System.currentTimeMillis() - ms_find_highest_rank_atom);
                            /*
                             * if (top_atom == null) { Concept c =
                             * getConceptByCode("NCI Metathesaurus", null, null,
                             * code); t = c.getEntityDescription().getContent()
                             * + "|" + Constants.EXTERNAL_TERM_TYPE + "|" +
                             * Constants.EXTERNAL_TERM_SOURCE + "|" +
                             * Constants.EXTERNAL_TERM_SOURCE_CODE; } else { t =
                             * top_atom.getTerm() + "|" + top_atom.getType() +
                             * "|" + top_atom.getSource() + "|" +
                             * top_atom.getCode(); }
                             */
                            if (top_atom == null) {
                                for (int k = 0; k < v.size(); k++) {
                                    top_atom = (BySourceTabResults) v.elementAt(k);
                                    t = top_atom.getTerm() + "|" + top_atom.getType() + "|"
                                            + top_atom.getSource() + "|" + top_atom.getCode();
                                    t = t + "|" + code + "|" + top_atom.getRela() + "|" + category;
                                    w.add(t);
                                }
                            } else {
                                t = top_atom.getTerm() + "|" + top_atom.getType() + "|" + top_atom.getSource()
                                        + "|" + top_atom.getCode();
                                t = t + "|" + code + "|" + rela + "|" + category;
                                w.add(t);
                            }

                            // w.add(t);
                            CUI_hashset.add(rel + "$" + code);

                            // Temporarily save non-RO other relationships
                            if (category.compareTo("Other") == 0 && rela.compareTo("RO") != 0) {
                                if (!rel_hset.contains(code)) {
                                    rel_hset.add(code);
                                }
                            }

                            if (category.compareTo("Child") == 0 && rela.compareTo("CHD") != 0) {
                                if (!hasSubtype_hset.contains(code)) {
                                    hasSubtype_hset.add(code);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    long total_categorization_delay = System.currentTimeMillis() - ms;
    String action_atom = "Find highest rank atom delay";
    Debug.println("Run time (ms) for " + action_atom + " " + ms_find_highest_rank_atom_delay);
    DBG.debugDetails(ms_find_highest_rank_atom_delay, action_atom, "getNeighborhoodSynonyms");

    long absolute_categorization_delay = total_categorization_delay - ms_find_highest_rank_atom_delay;
    Debug.println("Run time (ms) for " + action + " " + absolute_categorization_delay);
    DBG.debugDetails(absolute_categorization_delay, action, "getNeighborhoodSynonyms");

    ms_remove_RO_delay = System.currentTimeMillis();
    action = "Remove redundant relationships";
    for (int i = 0; i < w.size(); i++) {
        String s = (String) w.elementAt(i);
        int j = i + 1;

        Vector<String> v = parseData(s, "|");

        if (v.size() == 7) {
            String rel = (String) v.elementAt(6);
            if (rel.compareTo("Child") != 0 && rel.compareTo("Other") != 0) {
                u.add(s);
            } else if (rel.compareTo("Child") == 0) {
                String rela = (String) v.elementAt(5);
                if (rela.compareTo("CHD") != 0) {
                    u.add(s);
                } else {
                    String code = (String) v.elementAt(4);
                    if (!hasSubtype_hset.contains(code)) {
                        u.add(s);
                    }
                }
            } else if (rel.compareTo("Other") == 0) {
                String rela = (String) v.elementAt(5);
                if (rela.compareTo("RO") != 0) {
                    u.add(s);
                } else {
                    String code = (String) v.elementAt(4);
                    if (!rel_hset.contains(code)) {
                        u.add(s);
                    }
                }
            }
        } else {
            // Debug.println("(" + j + ") ??? " + s);
        }
    }
    delay = System.currentTimeMillis() - ms_remove_RO_delay;
    Debug.println("Run time (ms) for " + action + " " + delay);
    DBG.debugDetails(delay, action, "getNeighborhoodSynonyms");

    long ms_sort_delay = System.currentTimeMillis();
    u = removeRedundantRecords(u);
    SortUtils.quickSort(u);
    action = "Initial sorting";
    delay = System.currentTimeMillis() - ms_sort_delay;
    Debug.println("Run time (ms) for " + action + " " + delay);
    DBG.debugDetails(delay, action, "getNeighborhoodSynonyms");

    // DBG.debugDetails("Max Return", NCImBrowserProperties.maxToReturn);

    delay = System.currentTimeMillis() - ms_all;
    Debug.println("Run time (ms) for " + action_overall + " " + delay);
    DBG.debugDetails(delay, action_overall, "getNeighborhoodSynonyms");

    return u;
}

From source file:org.apache.catalina.servlets.DefaultServlet.java

/**
 * Serve the specified resource, optionally including the data content.
 *
 * @param context  The servlet request we are processing
 * @param content  Should the content be included?
 * @param method  Description of the Parameter
 * @throws IOException      if an input/output error occurs
 * @throws ServletException if a servlet-specified error occurs
 *//*from   w  w w .  j  a  va2s  .  c o  m*/
protected void serveResource(ActionContext context, boolean content, String method)
        throws IOException, ServletException {

    //TODO: remove this hardcoding
    debug = 2;
    // Identify the requested resource path
    String path = getRelativePath(context.getRequest());

    if (path.indexOf("/.") > -1) {
        //MAC OSX Fix
        return;
    }

    if (debug > 0) {
        if (content) {
            log("DefaultServlet.serveResource:  Serving resource '" + path + "' headers and data");
        } else {
            log("DefaultServlet.serveResource:  Serving resource '" + path + "' headers only");
        }
    }

    // Retrieve the Catalina context and Resources implementation

    Connection db = null;
    ModuleContext resources = null;
    ResourceInfo resourceInfo = null;
    SystemStatus thisSystem = null;
    boolean status = true;
    try {
        //System.out.println("DefaultServlet-> Serving Resource " + (content ? "WITH CONTENT" : "WITHOUT CONTENT"));
        db = this.getConnection(context);
        resources = getCFSResources(db, context);
        if (resources == null) {
            context.getResponse().sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }
        thisSystem = this.getSystemStatus(context);
        if (method.equals(METHOD_GET)) {
            Object current = resources.lookup(thisSystem, db, path);
        }
        resourceInfo = new ResourceInfo(thisSystem, path, resources);
    } catch (SQLException e) {
        e.printStackTrace(System.out);
        context.getResponse().sendError(CFS_SQLERROR, e.getMessage());
        status = false;
    } catch (Exception e) {
    } finally {
        this.freeConnection(db, context);
    }
    if (!status) {
        return;
    }

    if (!resourceInfo.exists) {
        context.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND, context.getRequest().getRequestURI());
        return;
    }

    // If the resource is not a collection, and the resource path
    // ends with "/" or "\", return NOT FOUND
    if (!resourceInfo.collection) {
        if (path.endsWith("/") || (path.endsWith("\\"))) {
            context.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND,
                    context.getRequest().getRequestURI());
            return;
        }
    }

    // Check if the conditions specified in the optional If headers are
    // satisfied.
    if (!resourceInfo.collection) {

        // Checking If headers
        boolean included = (context.getRequest().getAttribute(Globals.INCLUDE_CONTEXT_PATH_ATTR) != null);
        if (!included && !checkIfHeaders(context.getRequest(), context.getResponse(), resourceInfo)) {
            return;
        }
    }

    // Find content type
    String contentType = getServletContext().getMimeType(resourceInfo.clientFilename);

    Vector ranges = null;

    if (resourceInfo.collection) {

        // Skip directory listings if we have been configured to
        // suppress them
        if (!listings) {
            context.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND,
                    context.getRequest().getRequestURI());
            return;
        }
        contentType = "text/html;charset=UTF-8";

    } else {
        // Parse range specifier
        ranges = parseRange(context.getRequest(), context.getResponse(), resourceInfo);
        // ETag header
        context.getResponse().setHeader("ETag", getETag(resourceInfo));
        // Last-Modified header
        if (debug > 0) {
            log("DefaultServlet.serveFile:  lastModified='" + (new Timestamp(resourceInfo.date)).toString()
                    + "'");
        }
        context.getResponse().setHeader("Last-Modified", resourceInfo.httpDate);
    }

    ServletOutputStream ostream = null;
    PrintWriter writer = null;

    if (content) {
        // Trying to retrieve the servlet output stream
        try {
            ostream = context.getResponse().getOutputStream();
        } catch (IllegalStateException e) {
            // If it fails, we try to get a Writer instead if we're
            // trying to serve a text file
            if ((contentType == null) || (contentType.startsWith("text"))) {
                writer = context.getResponse().getWriter();
            } else {
                throw e;
            }
        }
    }

    if ((resourceInfo.collection) || (((ranges == null) || (ranges.isEmpty()))
            && (context.getRequest().getHeader("Range") == null))) {

        // Set the appropriate output headers
        if (contentType != null) {
            if (debug > 0) {
                log("DefaultServlet.serveFile:  contentType='" + contentType + "'");
            }
            context.getResponse().setContentType(contentType);
        }
        long contentLength = resourceInfo.length;
        if ((!resourceInfo.collection) && (contentLength >= 0)) {
            if (debug > 0) {
                log("DefaultServlet.serveFile:  contentLength=" + contentLength);
            }
            context.getResponse().setContentLength((int) contentLength);
        }
        if (resourceInfo.collection) {
            if (content) {
                // Serve the directory browser
                resourceInfo.setStream(render(context.getRequest().getContextPath(), resourceInfo));
            }
        }
        // Copy the input stream to our output stream (if requested)
        if (content) {
            try {
                context.getResponse().setBufferSize(output);
            } catch (IllegalStateException e) {
                // Silent catch
            }
            if (ostream != null) {
                copy(resourceInfo, ostream);
            } else {
                copy(resourceInfo, writer);
            }
        }
    } else {
        if ((ranges == null) || (ranges.isEmpty())) {
            return;
        }
        // Partial content response.
        context.getResponse().setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
        if (ranges.size() == 1) {
            Range range = (Range) ranges.elementAt(0);
            context.getResponse().addHeader("Content-Range",
                    "bytes " + range.start + "-" + range.end + "/" + range.length);
            context.getResponse().setContentLength((int) (range.end - range.start + 1));

            if (contentType != null) {
                if (debug > 0) {
                    log("DefaultServlet.serveFile:  contentType='" + contentType + "'");
                }
                context.getResponse().setContentType(contentType);
            }

            if (content) {
                try {
                    context.getResponse().setBufferSize(output);
                } catch (IllegalStateException e) {
                    // Silent catch
                }
                if (ostream != null) {
                    copy(resourceInfo, ostream, range);
                } else {
                    copy(resourceInfo, writer, range);
                }
            }
        } else {

            context.getResponse().setContentType("multipart/byteranges; boundary=" + mimeSeparation);

            if (content) {
                try {
                    context.getResponse().setBufferSize(output);
                } catch (IllegalStateException e) {
                    // Silent catch
                }
                if (ostream != null) {
                    copy(resourceInfo, ostream, ranges.elements(), contentType);
                } else {
                    copy(resourceInfo, writer, ranges.elements(), contentType);
                }
            }
        }
    }
}