Example usage for java.util Vector contains

List of usage examples for java.util Vector contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this vector contains the specified element.

Usage

From source file:org.opencastproject.util.ZipUtilTest.java

@Test
public void zipNoRecStrFile() throws Exception {

    File destFile = new File(destDir, "noRecStrFile.zip");

    Vector<String> names = new Vector<String>();
    names.add(srcFileName);//from  w  ww  .  j  a v  a  2 s  .c om
    names.add(nestedSrcFileName);

    File test = ZipUtil.zip(new String[] { srcFile.getCanonicalPath(), nestedSrcFile.getCanonicalPath(),
            nestedSrcDir.getCanonicalPath() }, destFile, false, ZipUtil.NO_COMPRESSION);
    Assert.assertTrue(test.exists());
    ZipFile zip = new ZipFile(test);
    Assert.assertEquals(2, zip.size());
    Enumeration<? extends ZipEntry> entries = zip.entries();

    try {
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            Assert.assertTrue(names.contains(entry.getName()));
        }
    } catch (AssertionError ae) {
        zip.close();
        throw ae;
    }

    zip.close();
}

From source file:org.openxdata.server.sms.FormSmsParser.java

/**
 * Get the skip logic error messages in a filled form. (eg pregnant males)
 * //from  w w w .jav a2s . c  om
 * @param formData the form data to validate.
 * @param ruleRequiredQtns a list of questions which become required after rule firing.
 * @return a comma separated list of validation error messages if any, else null.
 */
@SuppressWarnings("unchecked")
private String getSkipErrorMsg(org.openxdata.model.FormData formData, Vector<QuestionData> ruleRequiredQtns) {
    String sErrors = null;

    //Check if form has any questions.
    Vector<PageData> pages = formData.getPages();
    if (pages == null || pages.size() == 0) {
        sErrors = MSG_FORM_HAS_NO_QUESTIONS;
        return sErrors;
    }

    //Check if form has any skip rules.
    Vector<SkipRule> rules = formData.getDef().getSkipRules();
    if (rules == null)
        return sErrors;

    //Deal with the user supplied validation rules
    for (int index = 0; index < rules.size(); index++) {
        SkipRule rule = (SkipRule) rules.elementAt(index);
        Vector<QuestionData> answeredQtns = getAnsweredQuestions(formData, rule.getActionTargets());

        rule.fire(formData);

        //Get the question text of the first condition. This could be improved with a user supplied skip logic error message, in future.
        String qtnText = formData.getQuestion(((Condition) rule.getConditions().elementAt(0)).getQuestionId())
                .getText();

        boolean mandatoryRule = (rule.getAction() & OpenXdataConstants.ACTION_MAKE_MANDATORY) != 0;

        Vector<Byte> ids = rule.getActionTargets();
        for (byte i = 0; i < ids.size(); i++) {
            QuestionData questionData = formData.getQuestion(Byte.parseByte(ids.elementAt(i).toString()));

            //Check if the user answered a question they were supposed to skip.
            if (!questionData.isAnswered() && answeredQtns.contains(questionData))
                sErrors = addErrorMsg(sErrors, MSG_DUE_TO_ANSWER_FOR + " " + qtnText + ", "
                        + MSG_NO_ANSWER_EXPECTED_FOR + " " + questionData.getDef().getText());

            //Check is the user has not answered a question which has become required after an answer to some other question.
            if (mandatoryRule && questionData.getDef().isMandatory() && !questionData.isAnswered())
                sErrors = addErrorMsg(sErrors, MSG_DUE_TO_ANSWER_FOR + " " + qtnText + ", "
                        + MSG_NO_ANSWER_EXPECTED_FOR + " " + questionData.getDef().getText());

            if (mandatoryRule)
                ruleRequiredQtns.add(questionData);
        }
    }

    return sErrors;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.BarCharts.java

public Dataset filterDatasetCatGroups(Dataset dataset, Vector groups) {
    logger.debug("IN");
    DefaultCategoryDataset catDataset = (DefaultCategoryDataset) dataset;

    //keeps track of wich series has to be shown
    currentCatGroups = groups;/*from   w  w w.  j a  v  a  2 s . c o m*/
    String catGroup = "";
    //List rowKeys=new Vector();

    //List rowKeys=new Vector(catDataset.getRowKeys());
    List colKeys = new Vector(catDataset.getColumnKeys());

    for (Iterator iterator = colKeys.iterator(); iterator.hasNext();) {
        String col = (String) iterator.next();
        // iterate on cols, get their group and see if it has to be kept
        catGroup = (String) catGroups.get(col);
        if (!(groups.contains(catGroup))) {
            catDataset.removeColumn(col);
            catGroupNames.remove(col);
        }
    }

    logger.debug("OUT");
    return catDataset;

}

From source file:com.genentech.application.property.SDFCalculate.java

private void calcProperties(OEGraphMol mol, Vector<String> propsList) {
    TPSA myTPSA = new TPSA();
    int numHeavy = 0;
    int hPolar_neu = 0;
    double tpsa = 0.0;
    double mw = 0;
    int LipinskiHBA = 0, LipinskiHBD = 0;
    int aromaticRingCount = 0, carboAromaticRingCount = 0, aliphaticRingCount = 0, carboAliphaticRingCount = 0;
    final double R = 8.314510, J2kcal = 0.001 * (1. / 4.184), T = 300.0, RT = R * J2kcal * T;

    // assign OEChem default aromatic model and hybridazation
    oechem.OEAssignAromaticFlags(mol);//from  w w  w  .  jav a 2 s . c  o m
    oechem.OEAssignHybridization(mol);
    // transform molecule to protonateCNOS and deprotonateNP
    // explicit hydrogens are added to neutralMol
    OEGraphMol neutralMol = neutralizeMol(mol);
    // convert neutralMol to smiles, print smiles
    //String cansmi = oechem.OECreateSmiString(neutralMol);
    //System.err.println("SMILES: " + cansmi);

    //TPSA RotBonds H_polar N O NH OH Heavy_Atoms Rings MW RO5 cLogP_read Charge
    if (propsList.contains("TPSA") || propsList.contains("CNS_MPO") || propsList.contains("all")) {
        tpsa = myTPSA.calculateTPSA(neutralMol, countP, countS);
        if (tpsa <= 0.0)
            tpsa = 0.0;
        oechem.OESetSDData(mol, "TPSA", Integer.toString((int) tpsa));
    }
    if (propsList.contains("Charge") || propsList.contains("all")) {
        int netCharge = oechem.OENetCharge(mol);
        oechem.OESetSDData(mol, "Charge", Integer.toString(netCharge));
    }
    if (propsList.contains("RotBonds") || propsList.contains("all")) {
        /* use SMARTS to calculate the following properties */
        int singleBonds = SmartsSearch.search(mol, smartsMap.get("SingleBond"));
        int amideCount = SmartsSearch.search(mol, smartsMap.get("Amide"));
        int tripleBondCount = SmartsSearch.search(mol, smartsMap.get("TripleBondAtom"));
        int rotBonds = singleBonds - amideCount - tripleBondCount;
        oechem.OESetSDData(mol, "RotBonds", Integer.toString(rotBonds));
    }
    if (propsList.contains("Rings") || propsList.contains("all")) {
        //oechem.OEFindRingAtomsAndBonds(mol); // doesn't seem to be necessary
        int numRings = oechem.OEDetermineRingSystems(mol, new int[mol.GetMaxAtomIdx()]);
        oechem.OESetSDData(mol, "Rings", Integer.toString(numRings));
    }
    if (propsList.contains("Heavy_Atoms") || propsList.contains("cIC50atLE0.3") || propsList.contains("all")) {
        numHeavy = SmartsSearch.search(mol, smartsMap.get("HeavyAtom"));
        oechem.OESetSDData(mol, "Heavy_Atoms", Integer.toString(numHeavy));
    }
    if (propsList.contains("cIC50atLE0.3") || propsList.contains("all")) {
        double cIC50atLE0_3 = Math.exp((-1.0 * 0.3 * numHeavy) / RT) * 1000000; // multiply by 1000000 to convert to uM units
        oechem.OESetSDData(mol, "cIC50atLE0.3", String.format("%.5f", cIC50atLE0_3));
    }
    if (propsList.contains("cIC50atLE0.35") || propsList.contains("all")) {
        double cIC50atLE0_3 = Math.exp((-1.0 * 0.35 * numHeavy) / RT) * 1000000; // multiply by 1000000 to convert to uM units
        oechem.OESetSDData(mol, "cIC50atLE0.35", String.format("%.5f", cIC50atLE0_3));
    }
    if (propsList.contains("cIC50atLE0.4") || propsList.contains("all")) {
        double cIC50atLE0_3 = Math.exp((-1.0 * 0.4 * numHeavy) / RT) * 1000000; // multiply by 1000000 to convert to uM units
        oechem.OESetSDData(mol, "cIC50atLE0.4", String.format("%.5f", cIC50atLE0_3));
    }
    if (propsList.contains("NH+OH") || propsList.contains("RO5") || propsList.contains("CNS_MPO")
            || propsList.contains("all")) {
        hPolar_neu = countHPolar(neutralMol);
        LipinskiHBD = hPolar_neu;
        oechem.OESetSDData(mol, "NH+OH", Integer.toString(hPolar_neu));
    }
    if (propsList.contains("H_polar") || propsList.contains("all")) {
        int hPolar = countHPolar(mol);
        oechem.OESetSDData(mol, "H_polar", Integer.toString(hPolar));
    }
    if (propsList.contains("N+O") || propsList.contains("RO5") || propsList.contains("all")) {
        int nCount = SmartsSearch.search(mol, smartsMap.get("NCount"));
        int oCount = SmartsSearch.search(mol, smartsMap.get("OCount"));
        LipinskiHBA = nCount + oCount;
        oechem.OESetSDData(mol, "N+O", String.format("%d", LipinskiHBA));
    }
    if (propsList.contains("MW") || propsList.contains("CNS_MPO") || propsList.contains("RO5")
            || propsList.contains("all")) {
        mw = oechem.OECalculateMolecularWeight(neutralMol, true);
        oechem.OESetSDData(mol, "MW", String.format("%.2f ", mw));
    }
    if (propsList.contains("AromaticRings") || propsList.contains("HeteroAromaticRings")
            || propsList.contains("Solubility_Index") || propsList.contains("all")) {
        int aCount = SmartsSearch.search(mol, smartsMap.get("Aromatic5Rings"));
        aCount += SmartsSearch.search(mol, smartsMap.get("Aromatic6Rings"));
        aCount += SmartsSearch.search(mol, smartsMap.get("Aromatic7Rings"));
        aromaticRingCount = aCount;
        oechem.OESetSDData(mol, "AromaticRings", String.format("%d", aCount));
    }
    if (propsList.contains("CarboAromaticRings") || propsList.contains("HeteroAromaticRings")
            || propsList.contains("all")) {
        int caCount = SmartsSearch.search(mol, smartsMap.get("CarboAromatic5Rings"));
        caCount += SmartsSearch.search(mol, smartsMap.get("CarboAromatic6Rings"));
        caCount += SmartsSearch.search(mol, smartsMap.get("CarboAromatic7Rings"));
        carboAromaticRingCount = caCount;
        oechem.OESetSDData(mol, "CarboAromaticRings", String.format("%d", caCount));
    }
    if (propsList.contains("HeteroAromaticRings") || propsList.contains("all")) {
        int haCount = aromaticRingCount - carboAromaticRingCount;
        oechem.OESetSDData(mol, "HeteroAromaticRings", String.format("%d", haCount));
    }
    if (propsList.contains("AliphaticRings") || propsList.contains("HeteroAliphaticRings")
            || propsList.contains("all")) {
        int aCount = SmartsSearch.searchAliphaticRings(mol, smartsMap.get("Aliphatic3Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("Aliphatic4Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("Aliphatic5Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("Aliphatic6Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("Aliphatic7Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("Aliphatic8Rings"));
        aliphaticRingCount = aCount;
        oechem.OESetSDData(mol, "AliphaticRings", String.format("%d", aCount));
    }

    if (propsList.contains("CarboAliphaticRings") || propsList.contains("HeteroAliphaticRings")
            || propsList.contains("all")) {
        int aCount = SmartsSearch.searchAliphaticRings(mol, smartsMap.get("CarboAliphatic3Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("CarboAliphatic4Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("CarboAliphatic5Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("CarboAliphatic6Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("CarboAliphatic7Rings"));
        aCount += SmartsSearch.searchAliphaticRings(mol, smartsMap.get("CarboAliphatic8Rings"));
        carboAliphaticRingCount = aCount;
        oechem.OESetSDData(mol, "CarboAliphaticRings", String.format("%d", aCount));
    }
    if (propsList.contains("HeteroAliphaticRings") || propsList.contains("all")) {
        int count = aliphaticRingCount - carboAliphaticRingCount;
        oechem.OESetSDData(mol, "HeteroAliphaticRings", String.format("%d", count));
    }

    if (propsList.contains("AromaticFraction") || propsList.contains("all")) {
        int aCount = SmartsSearch.search(mol, smartsMap.get("AromaticAtom"));
        int heavyCount = SmartsSearch.search(mol, smartsMap.get("HeavyAtom"));
        double aromaticFraction = aCount / (heavyCount + 0.001); // so you don't divide by zero
        oechem.OESetSDData(mol, "AromaticFraction", String.format("%.2f", aromaticFraction));
    }
    if (propsList.contains("CarboAromaticFraction") || propsList.contains("all")) {
        int cCount = SmartsSearch.search(mol, smartsMap.get("AromaticCarbonAtom"));
        int heavyCount = SmartsSearch.search(mol, smartsMap.get("HeavyAtom"));
        double carboAromaticFraction = cCount / (heavyCount + 0.001); // so you don't divide by zero
        oechem.OESetSDData(mol, "CarboAromaticFraction", String.format("%.2f", carboAromaticFraction));
    }

    if (propsList.contains("NonSp3Fraction") || propsList.contains("all")) {
        int nonSp3Count = SmartsSearch.search(mol, smartsMap.get("sp3"));
        int heavyCount = SmartsSearch.search(mol, smartsMap.get("HeavyAtom"));
        double nonSp3Fraction = (heavyCount - nonSp3Count) / (heavyCount + 0.001); // so you don't divide by zero
        oechem.OESetSDData(mol, "NonSp3Fraction", String.format("%.2f", nonSp3Fraction));
    }

    if (propsList.contains("CarboAromaticRings") || propsList.contains("HetereoAromaticRings")
            || propsList.contains("all")) {
        int caCount = SmartsSearch.search(mol, smartsMap.get("CarboAromatic5Rings"));
        caCount += SmartsSearch.search(mol, smartsMap.get("CarboAromatic6Rings"));
        caCount += SmartsSearch.search(mol, smartsMap.get("CarboAromatic7Rings"));
        carboAromaticRingCount = caCount;
        oechem.OESetSDData(mol, "CarboAromaticRings", String.format("%d", caCount));
    }

    if (propsList.contains("Csp3") || propsList.contains("all")) {
        int count = SmartsSearch.search(mol, smartsMap.get("Csp3"));
        oechem.OESetSDData(mol, "Csp3", String.format("%d", count));

        count = SmartsSearch.search(mol, smartsMap.get("CSsp3"));
        oechem.OESetSDData(mol, "CSsp3", String.format("%d", count));

        count = SmartsSearch.search(mol, smartsMap.get("CS2sp3"));
        oechem.OESetSDData(mol, "CS2sp3", String.format("%d", count));
    }

    if (propsList.contains("Csp3Fraction") || propsList.contains("all")) {
        int heavyCount = SmartsSearch.search(mol, smartsMap.get("HeavyAtom"));
        int count = SmartsSearch.search(mol, smartsMap.get("Csp3"));
        double Csp3Fraction = (count / (heavyCount + 0.001)); // so you don't divide by zero
        oechem.OESetSDData(mol, "Csp3Fraction", String.format("%.2f", Csp3Fraction));
    }

    // get cLogP for RO5 and CNS_MPO calculation
    double cLogP = Double.NaN;
    if (propsList.contains("RO5") || propsList.contains("CNS_MPO") || propsList.contains("all")) {
        if (cLogPTag != null) {
            if (oechem.OEHasSDData(mol, cLogPTag)) {
                try {
                    cLogP = Double.valueOf(oechem.OEGetSDData(mol, cLogPTag));
                } catch (Exception e) {
                    System.err.println(mol.GetTitle() + " " + oechem.OEGetSDData(mol, cLogPTag));
                }
            }
        }
    }

    //get cLogD74 for CNS_MPO and Solubility_index calculation
    double cLogD74 = Double.NaN;
    if (propsList.contains("CNS_MPO") || propsList.contains("Solubility_Index") || propsList.contains("all")) {
        if (oechem.OEHasSDData(mol, CLOGD74_Tag)) {
            try {
                cLogD74 = Double.valueOf(oechem.OEGetSDData(mol, CLOGD74_Tag));
            } catch (Exception e) {
                System.err.println("mol: " + mol.GetTitle() + " " + CLOGD74_Tag + ": "
                        + oechem.OEGetSDData(mol, CLOGD74_Tag));
                cLogD74 = Double.NaN;
            }
        }
    }

    if (propsList.contains("Solubility_Index") || propsList.contains("all")) {
        if (Double.isNaN(cLogD74)) { // do Solubility_Index if cLogD74 is not found
            System.err.println("mol: " + mol.GetTitle() + " Solubility_Index error, cLogD74 is not defined");
        } else {
            double solIdx = cLogD74 + aromaticRingCount;
            oechem.OESetSDData(mol, "Solubility_Index", String.format("%.1f", solIdx));
        }
    }

    if (propsList.contains("RO5") || propsList.contains("all")) {
        /*rule of Five violations, include cLogP if it is provided */
        int ruleOf5Violation = 0;
        if (mw > 500.0)
            ruleOf5Violation++;
        if (LipinskiHBA > 10)
            ruleOf5Violation++;
        if (LipinskiHBD > 5)
            ruleOf5Violation++;
        if (cLogP > 5.0)
            ruleOf5Violation++;
        if (Double.isNaN(cLogP)) { // do not calculate RO5 violation if cLogP is not found
            System.err.println("mol: " + mol.GetTitle() + " RO5 error: cLogP is not defined");
        } else {
            oechem.OESetSDData(mol, "RO5", Integer.toString(ruleOf5Violation));
        }
    }
    if (propsList.contains("CNS_MPO") || propsList.contains("all")) {
        double c_pKa_MB = Double.NaN;
        String c_pKa_MB_Tag = "c_pKa_MB";
        // if c_pKa_MB does not exist, add one to CNS_MPO score
        if (oechem.OEHasSDData(mol, c_pKa_MB_Tag)) {
            try {
                c_pKa_MB = Double.valueOf(oechem.OEGetSDData(mol, c_pKa_MB_Tag));
            } catch (Exception e) {
                System.err.println(
                        "mol: " + mol.GetTitle() + " c_pKa_MB: " + oechem.OEGetSDData(mol, c_pKa_MB_Tag));
                c_pKa_MB = Double.NaN;
            }
        } else {
            c_pKa_MB = 0.0; // the step function will assign a CNS_MPO_pKa score of 1 for this pka_MB value
        }

        if (Double.isNaN(cLogP) || Double.isNaN(cLogD74) || Double.isNaN(c_pKa_MB)) {
            //oechem.OESetSDData(mol, "CNS_MPO_score", "error");
            System.err.println("mol: " + mol.GetTitle() + " CNS_MPO_score error");
        } else {
            double CNS_MPO_cLogP = StepFunction.linearScore(5, 3, cLogP);
            double CNS_MPO_cLogD = StepFunction.linearScore(4, 2, cLogD74);
            double CNS_MPO_MW = StepFunction.linearScore(500, 360, mw);
            double CNS_MPO_TPSA = StepFunction.humpScore(20, 40, 90, 120, tpsa);
            double CNS_MPO_HBD = StepFunction.linearScore(3.5, 0.5, hPolar_neu);
            double CNS_MPO_pKa = StepFunction.linearScore(10, 8, c_pKa_MB);

            double CNS_MPO = CNS_MPO_cLogP + CNS_MPO_cLogD + CNS_MPO_MW + CNS_MPO_TPSA + CNS_MPO_HBD
                    + CNS_MPO_pKa;
            oechem.OESetSDData(mol, "CNS_MPO_score", String.format("%.2f", CNS_MPO));

            // store MPO scores for the individual parts
            oechem.OESetSDData(mol, "CNS_MPO_cLogP", String.format("%.2f", CNS_MPO_cLogP));
            oechem.OESetSDData(mol, "CNS_MPO_cLogD", String.format("%.2f", CNS_MPO_cLogD));
            oechem.OESetSDData(mol, "CNS_MPO_MW", String.format("%.2f", CNS_MPO_MW));
            oechem.OESetSDData(mol, "CNS_MPO_TPSA", String.format("%.2f", CNS_MPO_TPSA));
            oechem.OESetSDData(mol, "CNS_MPO_HBD", String.format("%.2f", CNS_MPO_HBD));
            oechem.OESetSDData(mol, "CNS_MPO_pKa", String.format("%.2f", CNS_MPO_pKa));
        }
    }

}

From source file:org.openbravo.erpCommon.utility.Utility.java

/**
 * Returns a Vector<String> with the elements that appear in both v1 and v2 Vectors
 * /*from  w  ww .j  av  a  2 s .c  o m*/
 * @param v1
 * @param v2
 * @return the combination of v1 and v2 without duplicates
 */
public static Vector<String> getIntersectionVector(Vector<String> v1, Vector<String> v2) {
    final Vector<String> v = new Vector<String>();
    for (int i = 0; i < v1.size(); i++) {
        if (v2.contains(v1.elementAt(i)) && !v.contains(v1.elementAt(i)))
            v.add(v1.elementAt(i));
    }
    return v;
}

From source file:org.opencastproject.util.ZipUtilTest.java

@Test
public void zipNoRecStrStr() throws Exception {

    File destFile = new File(destDir, "noRecStrStr.zip");

    Vector<String> names = new Vector<String>();
    names.add(srcFileName);/*from  w w w .j av a  2  s. c  o  m*/
    names.add(nestedSrcFileName);

    File test = ZipUtil.zip(
            new String[] { srcFile.getCanonicalPath(), nestedSrcFile.getCanonicalPath(),
                    nestedSrcDir.getCanonicalPath() },
            destFile.getCanonicalPath(), false, ZipUtil.NO_COMPRESSION);
    Assert.assertTrue(test.exists());
    ZipFile zip = new ZipFile(test);
    Assert.assertEquals(2, zip.size());
    Enumeration<? extends ZipEntry> entries = zip.entries();

    try {
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            Assert.assertTrue(names.contains(entry.getName()));
        }
    } catch (AssertionError ae) {
        zip.close();
        throw ae;
    }

    zip.close();
}

From source file:org.openflexo.foundation.ie.IEWOComponent.java

public Vector<TabComponentDefinition> getAllTabComponents(Vector<TabComponentDefinition> reply) {
    for (IESequenceTab container : getAllTabContainers()) {
        for (ITabWidget itab : container.getInnerWidgets()) {
            for (IETabWidget tab : itab.getAllTabs()) {
                TabComponentDefinition tabcd = tab.getTabComponentDefinition();
                if (!reply.contains(tabcd)) {
                    reply.add(tabcd);/*from   w  w w .j  av a  2s .c  o  m*/
                    // tabcd.getWOComponent().getAllTabComponents(reply);
                }
            }
        }
    }
    return reply;
}

From source file:com.tapjoy.TapjoyConnectCore.java

/**
 * Handles the response from calling Connect.
 * @param response               HTTP response from the server.
 * @return                     TRUE if the response is handled and notifier has been called, FALSE otherwise.
 *///from  w  ww  .  ja v  a  2s.c o m
private static boolean handleConnectResponse(String response) {
    // Create a document so we can parse the XML easily.
    Document document = TapjoyUtil.buildDocument(response);

    if (document != null) {
        String nodeValue = TapjoyUtil.getNodeTrimValue(document.getElementsByTagName("PackageNames"));

        // Parse package names.
        if (nodeValue != null && nodeValue.length() > 0) {
            String data = nodeValue;
            Vector<String> allPackageNames = new Vector<String>();

            int current = 0;
            int index = -1;

            while (true) {
                index = data.indexOf(',', current);

                // No commas left, grab the rest of the string.
                if (index == -1) {
                    // Trim whitespace.
                    TapjoyLog.i(TAPJOY_CONNECT, "parse: " + data.substring(current).trim());
                    allPackageNames.add(data.substring(current).trim());
                    break;
                }
                // Comma found, so get the substring.
                else {
                    // Trim whitespace.
                    TapjoyLog.i(TAPJOY_CONNECT, "parse: " + data.substring(current, index).trim());
                    allPackageNames.add(data.substring(current, index).trim());
                    current = index + 1;
                }
            }

            matchingPackageNames = "";

            List<ApplicationInfo> applications = context.getPackageManager().getInstalledApplications(0);
            for (ApplicationInfo appInfo : applications) {
                // System app.
                if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
                    //android.util.Log.i(TAPJOY, "system: " + appInfo.packageName);
                }
                // User installed app.
                else {
                    if (allPackageNames.contains(appInfo.packageName)) {
                        TapjoyLog.i(TAPJOY_CONNECT, "MATCH: installed packageName: " + appInfo.packageName);

                        // Comma separate if there are previous entries.
                        if (matchingPackageNames.length() > 0)
                            matchingPackageNames += ",";

                        matchingPackageNames += appInfo.packageName;
                    }
                }
            }
        }

        nodeValue = TapjoyUtil.getNodeTrimValue(document.getElementsByTagName("Success"));

        // The Tapjoy Connect call was successful.
        if (nodeValue != null && nodeValue.equals("true")) {
            //TapjoyLog.i(TAPJOY_CONNECT, "Successfully connected to tapjoy site.");
            return true;
        }
        //         else
        //         {
        //            TapjoyLog.e(TAPJOY_CONNECT, "Tapjoy Connect call failed.");
        //         }
    }

    return true;
}

From source file:com.duroty.application.bookmark.manager.BookmarkManager.java

/**
 * DOCUMENT ME!//w w  w.j a  v  a2  s . c om
 *
 * @param repositoryName DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws SearchException DOCUMENT ME!
 * @throws BookmarkException DOCUMENT ME!
 */
public Vector getKeywords(String repositoryName) throws SearchException, BookmarkException {
    Vector keywords = new Vector();

    String lucenePath = "";

    if (!defaultLucenePath.endsWith(File.separator)) {
        lucenePath = defaultLucenePath + File.separator + repositoryName + File.separator
                + Constants.BOOKMARK_LUCENE_BOOKMARK;
    } else {
        lucenePath = defaultLucenePath + repositoryName + File.separator + Constants.BOOKMARK_LUCENE_BOOKMARK;
    }

    Searcher searcher = null;

    try {
        searcher = BookmarkIndexer.getSearcher(lucenePath);

        Query query = new MatchAllDocsQuery();

        Hits hits = searcher.search(query);

        if (hits != null) {
            for (int i = 0; i < hits.length(); i++) {
                Document doc = hits.doc(i);
                String[] auxk = doc.getValues(Field_keywords);

                if (auxk != null) {
                    for (int j = 0; j < auxk.length; j++) {
                        if ((auxk[j] != null) && !auxk[j].trim().equals("") && !keywords.contains(auxk[j])) {
                            keywords.addElement(auxk[j].toLowerCase());
                        }
                    }
                }
            }
        }

        Collections.sort(keywords);
    } catch (IOException e) {
        throw new SearchException(e);
    } catch (Exception e) {
        throw new SearchException(e);
    } finally {
        if (searcher != null) {
            try {
                searcher.close();
            } catch (IOException e) {
            }
        }
    }

    return keywords;
}

From source file:org.opencastproject.util.ZipUtilTest.java

@Test
public void zipRecFileFile() throws Exception {

    File destFile = new File(destDir, "recFileFile.zip");

    Vector<String> names = new Vector<String>();
    names.add(srcFileName);//  w  ww.  j av a  2 s  .co m
    names.add(nestedSrcDirName + File.separator);
    names.add(nestedSrcDirName + File.separator + nestedSrcFileName);

    File test = ZipUtil.zip(srcDir.listFiles(), destFile, true, ZipUtil.NO_COMPRESSION);
    Assert.assertTrue(test.exists());
    ZipFile zip = new ZipFile(test);
    Assert.assertEquals(3, zip.size());
    Enumeration<? extends ZipEntry> entries = zip.entries();

    try {
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            // The 'replace' method is used because the filesystem directory separator may not be the same as the Zip
            // files's
            Assert.assertTrue(names.contains(entry.getName().replace('/', File.separatorChar)));
        }
    } catch (AssertionError ae) {
        zip.close();
        throw ae;
    }

    zip.close();
}