Example usage for java.util Vector size

List of usage examples for java.util Vector size

Introduction

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

Prototype

public synchronized int size() 

Source Link

Document

Returns the number of components in this vector.

Usage

From source file:net.sf.javaml.clustering.AQBC.java

/**
 * returns true if this step converged//from  w  ww . j  a  v a2s .c o  m
 */
private boolean wan_shr_adap(Vector<TaggedInstance> A, double EXTTRESH) {
    int samples = A.size();
    double[] CE = new double[samples];
    int MAXITER = 100;
    double NRWAN = 30;
    // System.out.println("FIRSTA = "+A.get(0));
    double[] ME1 = mean(A);
    // System.out.println("A = "+A);
    // System.out.println("ME1 = " + Arrays.toString(ME1));
    // System.out.println("EXTTRESH = "+EXTTRESH);
    double[] DMI = calculateDistances(A, ME1);
    // System.out.println("DMI = "+Arrays.toString(DMI));
    double maxDMI = DMI[0];
    double minDMI = DMI[0];
    for (int i = 1; i < DMI.length; i++) {
        if (DMI[i] > maxDMI)
            maxDMI = DMI[i];
        if (DMI[i] < minDMI)
            minDMI = DMI[i];
    }
    EXTTRESH2 = maxDMI;
    double MDIS = minDMI;
    if (MathUtils.eq(MDIS, EXTTRESH2)) {
        ME = ME1;
        for (int i = 0; i < CE.length; i++)
            CE[i] = 1;
        EXTTRESH2 += 0.000001;
        System.out.println("Cluster center localisation did not reach preliminary estimate of radius!");
        return true;// TODO check if it should really be true, false is more
        // logical

    }
    double DELTARAD = (EXTTRESH2 - EXTTRESH) / NRWAN;
    double RADPR = EXTTRESH2;
    EXTTRESH2 = EXTTRESH2 - DELTARAD;
    if (EXTTRESH2 <= MDIS) {
        EXTTRESH2 = (RADPR + MDIS) / 2;
    }
    Vector<Integer> Q = findLower(DMI, EXTTRESH2);
    for (int i = 0; Q.size() != 0 && i < MAXITER; i++) {
        double[] ME2 = mean(select(A, Q));
        if (MathUtils.eq(ME1, ME2) && MathUtils.eq(RADPR, EXTTRESH2)) {
            ME = ME2;
            for (Integer index : Q) {
                CE[index] = 1;
            }
            return true;
        }
        RADPR = EXTTRESH2;
        DMI = calculateDistances(A, ME2);
        if (EXTTRESH2 > EXTTRESH) {
            EXTTRESH2 = Math.max(EXTTRESH, EXTTRESH2 - DELTARAD);
            if (EXTTRESH2 < MathUtils.min(DMI)) {
                EXTTRESH2 = RADPR;
            }
        }
        Q = findLower(DMI, EXTTRESH2);
        ME1 = ME2;

    }
    System.out.println("Preliminary cluster location did not converge");
    // System.out.println("\t DMI = "+Arrays.toString(DMI));
    System.out.println("\t EXTTRESH2 = " + EXTTRESH2);
    return false;
}

From source file:net.sf.javaml.clustering.AQBC.java

private double[] mean(Vector<TaggedInstance> a) {
    double[] out = new double[a.get(0).inst.noAttributes()];
    for (int i = 0; i < a.size(); i++) {
        // System.out.println("Instance "+i+" = "+a.get(i));
        for (int j = 0; j < a.get(0).inst.noAttributes(); j++)
            out[j] += a.get(i).inst.value(j);
    }//from ww  w . j  a  v  a2 s .co m
    // System.out.println("OUT = "+Arrays.toString(out));
    for (int j = 0; j < a.get(0).inst.noAttributes(); j++) {
        out[j] /= a.size();
    }
    return out;

}

From source file:net.rim.ejde.internal.packaging.PackagingManager.java

static private boolean existingJar(Vector<ImportedJar> vec, ImportedJar jar) {
    if (jar == null) {
        return false;
    }//from w  w w.j a v  a2  s  . c o m
    for (int i = 0; i < vec.size(); i++) {
        if (vec.get(i).getPath().equalsIgnoreCase(jar.getPath())) {
            return true;
        }
    }
    return false;
}

From source file:imapi.IMAPIClass.java

public int performComparison(Hashtable<Float, Vector<ResultSourceTargetPair>> resultInstances) {

    //Utilities/*w  w w. j a v  a2 s .c  o m*/
    DataRetrievalOperations retrieveData = new DataRetrievalOperations(this);
    BaseComparisonClass compClass = new BaseComparisonClass(this);

    //Internal structures used        
    SourceDataHolder inputSourceInfo = new SourceDataHolder();
    Hashtable<SourceTargetPair, SequenceSimilarityResultVector> pairSimilaritiesInSequences = new Hashtable<SourceTargetPair, SequenceSimilarityResultVector>();

    //If Comaprison with online database is selected check if it is avaliable
    if (this.userConfig.getComparisonMode() != ApiConstants.TargetSourceChoice.FILE_COMPARISON) {

        OnlineDatabase db = this.conf.getOnlineDb(this.userConfig.getComparisonMode());

        if (db == null) {
            this.setErrorMessage(ApiConstants.IMAPIFailCode, "Not supported Database");
            return ApiConstants.IMAPIFailCode;
        }

        OnlineDatabaseActions qSource = new OnlineDatabaseActions(this, db);
        int ret = qSource.checkIfDBisAvailable();
        if (ret != ApiConstants.IMAPISuccessCode) {
            return ret;
        }
    }

    //retrieve all needed namespaces from internet
    Hashtable<String, Model> allRetrievedModels = retrieveData.retrieveAllDeclaredNamespacesModels();

    //read Source Files info
    Vector<CidocCrmCompatibleFile> inputFiles = this.userConfig.getSourceInputFiles();
    for (int inputFileIndex = 0; inputFileIndex < inputFiles.size(); inputFileIndex++) {

        CidocCrmCompatibleFile inputFile = inputFiles.get(inputFileIndex);
        try {
            int ret = retrieveData.retrieveDataFrom_SourceFile(inputFile, allRetrievedModels, inputSourceInfo);

            if (ret != ApiConstants.IMAPISuccessCode) {
                return ret;
            }
        } catch (FileNotFoundException ex) {
            Utilities.handleException(ex);
            return ApiConstants.IMAPIFailCode;
        }
        if (inputFileIndex < (inputFiles.size() - 1))
            ;
        System.out.println("=======================================");
    }

    int totalNumberOfSourceInstanceValuesFound = 0;
    Enumeration<String> fileEnum = inputSourceInfo.keys();
    while (fileEnum.hasMoreElements()) {
        String fpath = fileEnum.nextElement();
        totalNumberOfSourceInstanceValuesFound += inputSourceInfo.get(fpath).keySet().size();
    }

    //print what data was found in source files
    System.out.println("\n\n============================================================");
    System.out.println("============================================================");
    System.out.println("============================================================");
    System.out.println("Found " + totalNumberOfSourceInstanceValuesFound
            + " instances in all \"\"SOURCE\"\" input files.");
    printSourceInfo(inputSourceInfo);

    /*
    if(IMAPIClass.DEBUG){
            
    if(inputSourceInfo!=null){
        System.out.println("Found: " + inputSourceInfo.size() +" instances.");
        return ApiConstants.IMAPISuccessCode;
    }
    }
            
    */
    //make an analysis if quick method can be followed
    Utilities u = new Utilities(this);
    Vector<Boolean> canQuickFilteringMethodBeFollowedForeachSequence = new Vector<Boolean>();
    u.canAllSequencesFollowFastApproach(this.userConfig.getUserQueriesCopy(), inputSourceInfo,
            canQuickFilteringMethodBeFollowedForeachSequence);

    //Read Info from Target Files or Online Database
    System.out.println("\n=======================================");
    System.out.println("=======================================");
    System.out.println("=======================================\n\n");

    ApiConstants.TargetSourceChoice comparisonChoice = this.userConfig.getComparisonMode();
    System.out.println("Starting queries on TARGET source: " + comparisonChoice.toString() + "\n\n");
    boolean targetDataCollectedCorrectly = false;
    switch (comparisonChoice) {
    case FILE_COMPARISON: {
        Vector<CidocCrmCompatibleFile> targetFiles = this.userConfig.getTargetInputFiles();
        for (int targetFileIndex = 0; targetFileIndex < targetFiles.size(); targetFileIndex++) {

            CidocCrmCompatibleFile targetFile = targetFiles.get(targetFileIndex);
            try {
                int ret = retrieveData.retrieveDataFrom_TargetFileAndCollectSimilarities(targetFile,
                        allRetrievedModels, inputSourceInfo, canQuickFilteringMethodBeFollowedForeachSequence,
                        pairSimilaritiesInSequences);
                if (ret == ApiConstants.IMAPISuccessCode) {
                    targetDataCollectedCorrectly = true;
                } else {
                    return ret;
                }
            } catch (FileNotFoundException ex) {
                Utilities.handleException(ex);
                return ApiConstants.IMAPIFailCode;
            }

        }
        break;
    }
    // a target online db is selected
    default: {
        OnlineDatabase db = this.conf.getOnlineDb(comparisonChoice);
        if (db == null) {
            this.setErrorMessage(ApiConstants.IMAPIFailCode,
                    "TargetSourceChoice not set correctly check user configuration xml file again.");
            return ApiConstants.IMAPIFailCode;
        } else {

            /*
            if(db.getDbType().equals("owlim")){
                int ret = retrieveData.retrieveDataFrom_OWLIM_DB(db,allRetrievedModels, inputSourceInfo, pairSimilaritiesInSequences);
                if(ret==ApiConstants.IMAPISuccessCode){
                    targetDataCollectedCorrectly = true;
                }
            }
            else{
                */
            int ret = retrieveData.retrieveDataFrom_OnlineDatabaseAndCollectSimilarities(db, allRetrievedModels,
                    inputSourceInfo, canQuickFilteringMethodBeFollowedForeachSequence,
                    pairSimilaritiesInSequences);
            if (ret == ApiConstants.IMAPISuccessCode) {
                targetDataCollectedCorrectly = true;
            }
            //}

        }
        break;

    }
    }

    inputSourceInfo = null;

    //start comparing
    //find out the denominator in order to normalize results
    double similarityDenominator = 0;

    int maxNumberOfQueriesIndex = this.userConfig.getNumberOfSequences();
    for (int i = 0; i < maxNumberOfQueriesIndex; i++) {
        similarityDenominator += this.userConfig.getWeightAtUserQueryIndex(i);
    }

    //PRINT OUT
    //System.out.println("Total Number of results with similarity > 0:\r\n#################  " + allSimilaritiesHash.keySet().size() + "  ##################");
    System.out.println("\n\n============================================================");
    System.out.println("============================================================");
    System.out.println("============================================================");

    //for each sequence save the parameter name - type compared values and the similarity
    Enumeration<SourceTargetPair> similarityIterator = pairSimilaritiesInSequences.keys();
    while (similarityIterator.hasMoreElements()) {

        SourceTargetPair pair = similarityIterator.nextElement();

        SequenceSimilarityResultVector similarities = pairSimilaritiesInSequences.get(pair);

        //Vector<SequenceSimilarityResult> similarityResults = new Vector<SequenceSimilarityResult>();

        int calculatedSimilarity = 0;
        if (pair.getSourceInstance().getInstanceUri().equals(pair.getTargetInstance().getInstanceUri())) {
            calculatedSimilarity = 100;
        } else {
            calculatedSimilarity = compClass.calculateFinalSimilarity(similarities, similarityDenominator);
        }
        if (calculatedSimilarity >= (userConfig.getResultsThreshold() * 100)) {

            float floatVal = (float) ((float) calculatedSimilarity / 100f);
            SequenceSimilarityResultVector tripVec = pairSimilaritiesInSequences.get(pair);

            if (resultInstances.containsKey(floatVal)) {
                ResultSourceTargetPair newVal = new ResultSourceTargetPair(pair, tripVec);
                resultInstances.get(floatVal).add(newVal);
            } else {
                Vector<ResultSourceTargetPair> newVal = new Vector<ResultSourceTargetPair>();
                newVal.add(new ResultSourceTargetPair(pair, tripVec));
                resultInstances.put(floatVal, newVal);
            }

        }
    }

    if (targetDataCollectedCorrectly == false) {
        System.out.println("Note that while collected data from target Error Occurred");
    }

    return ApiConstants.IMAPISuccessCode;
}

From source file:edu.umd.cfar.lamp.viper.util.StringHelp.java

/**
 * Split using a seperator.//from ww w. j  a  v a2s .  co  m
 *
 * @param line The String to be seperated.
 * @param sep The seperator character, eg a comma
 * @return An array of Strings containing the seperated data.
 * @see #splitBySeparatorAndParen(String line, char sep)
 */
public static String[] splitBySeparator(String line, char sep) {
    String newLine = line;
    Vector temp = new Vector();
    while (true) {
        int separatorIndex = newLine.indexOf(sep);
        if (separatorIndex == -1) {
            String lastNum = newLine.substring(separatorIndex + 1);
            temp.addElement(lastNum.trim());
            break;
        } else {
            String newNum = newLine.substring(0, separatorIndex);
            temp.addElement(newNum.trim());
        }
        newLine = newLine.substring(separatorIndex + 1);
    }
    String[] result = new String[temp.size()];
    for (int i = 0; i < result.length; i++) {
        result[i] = (String) temp.elementAt(i);
    }
    return (result);
}

From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java

/**
 * Fetches the children of this file, if not already cached.
 * //from ww  w. j ava  2  s. c o m
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void doGetChildren() throws IOException {
    if (children != null) {
        return;
    }

    final GridFTPClient client = ftpFs.getClient();
    try {
        // String key =
        // GsiFtpFileSystemConfigBuilder.getInstance().getEntryParser(getFileSystem().getFileSystemOptions());

        /** required to perform multiple requests **/
        client.setLocalPassive();
        client.setActive();

        final Vector tmpChildren = client.list(getName().getPath());

        if (tmpChildren == null || tmpChildren.size() == 0) {
            children = EMPTY_FTP_FILE_MAP;
        } else {
            children = new TreeMap();

            // Remove '.' and '..' elements
            for (int i = 0; i < tmpChildren.size(); i++) {
                // final FTPFile child = tmpChildren[i];
                final FileInfo child = (FileInfo) tmpChildren.get(i);

                if (child == null) {
                    if (log.isDebugEnabled()) {
                        log.debug(Messages.getString("vfs.provider.ftp/invalid-directory-entry.debug",
                                new Object[] { new Integer(i), relPath }));
                    }
                    continue;
                }
                if (!".".equals(child.getName()) && !"..".equals(child.getName())) {
                    children.put(child.getName(), child);
                }
            }
        }
    } catch (ServerException se) {
        se.printStackTrace();
        // System.err.println("GsiFtpFileObject " + se);
        throw new IOException(se.getMessage());
    } catch (ClientException ce) {
        throw new IOException(ce.getMessage());
    } finally {
        ftpFs.putClient(client);
    }
}

From source file:com.toughra.mlearnplayer.idevices.MCQIdevice.java

/**
 * Will make a table layout including questions, answers and feedback
 * //from  w ww.java  2s  .com
 * @return 
 */
public Form getForm() {
    form = new Form();

    //GridLayout gLayout = new GridLayout(totalQuestions + totalAnswers, 1);
    TableLayout tLayout = new TableLayout(totalQuestions + totalAnswers, 1);
    /*TableLayout tLayout = new TableLayout((totalQuestions*2) + totalAnswers,
        2);
    TableLayout.setMinimumSizePerColumn(20);
    form.setLayout(tLayout);
    */
    form.setLayout(tLayout);

    selectedAnswers = new int[totalQuestions];

    Component toFocus = null;

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

        HTMLComponent qHTML = hostMidlet.makeHTMLComponent(questions.elementAt(i).toString());
        qHTML.setFocusable(false);
        form.addComponent(qHTML);

        Vector questionAnswers = (Vector) answers.elementAt(i);
        String qId = String.valueOf(i);

        MCQAnswerItem[] itemArr = new MCQAnswerItem[questionAnswers.size()];

        for (int j = 0; j < questionAnswers.size(); j++) {
            Answer currentAnswer = (Answer) questionAnswers.elementAt(j);
            HTMLComponent answerComp = hostMidlet.makeHTMLComponent(currentAnswer.answerText);
            MCQAnswerItem thisItem = new MCQAnswerItem(this, answerComp, currentAnswer);

            thisItem.updateStyle();
            itemArr[j] = thisItem;
            TableLayout.Constraint tConst = tLayout.createConstraint();
            tConst.setWidthPercentage(100);
            form.addComponent(tConst, thisItem);

            if (i == 0 && j == 0) {
                form.setFocused(thisItem);
                thisItem.setFocus(true);
                thisItem.updateStyle();
            }
            thisItem.addActionListener(this);
        }

        for (int j = 0; j < questionAnswers.size(); j++) {
            if (j > 0) {
                itemArr[j].setNextFocusUp(itemArr[j - 1]);
            }
            if (j < questionAnswers.size() - 1) {
                itemArr[j].setNextFocusDown(itemArr[j + 1]);
            }
        }

    }

    return form;
}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a stacked bar graph representing test counts for each product area. 
 *
 * @param   builds   List of builds//from  w ww . jav  a 2s. c o m
 * @param   suites   List of test suites
 * @param   areas    List of product areas 
 * 
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAreaTestCountChart(Vector<CMnDbBuildData> builds,
        Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) {
    JFreeChart chart = null;

    // Collect the total times for each build, organized by area
    // This hashtable maps a build to the area/time information for that build
    Hashtable<Integer, Hashtable> buildTotals = new Hashtable<Integer, Hashtable>();

    // Generate placeholders for each build so the chart maintains a 
    // format consistent with the other charts that display build information
    if (builds != null) {
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            // Create the empty area list
            buildTotals.put(new Integer(build.getId()), new Hashtable<String, Integer>());
        }
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if ((suites != null) && (suites.size() > 0)) {

        // Collect build test numbers for each of the builds in the list 
        Enumeration suiteList = suites.elements();
        while (suiteList.hasMoreElements()) {

            // Process the test summary for the current build
            CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement();
            Integer buildId = new Integer(suite.getParentId());
            Integer testCount = new Integer(suite.getTestCount());

            // Parse the build information so we can track the time by build
            Hashtable<String, Integer> areaCount = null;
            if (buildTotals.containsKey(buildId)) {
                areaCount = (Hashtable) buildTotals.get(buildId);
            } else {
                areaCount = new Hashtable<String, Integer>();
                buildTotals.put(buildId, areaCount);
            }

            // Iterate through each product area to determine who owns this suite
            CMnDbFeatureOwnerData area = null;
            Iterator iter = areas.iterator();
            while (iter.hasNext()) {
                CMnDbFeatureOwnerData currentArea = (CMnDbFeatureOwnerData) iter.next();
                if (currentArea.hasFeature(suite.getGroupName())) {
                    area = currentArea;
                }
            }

            // Add the elapsed time for the current suite to the area total
            Integer totalValue = null;
            String areaName = area.getDisplayName();
            if (areaCount.containsKey(areaName)) {
                Integer oldTotal = (Integer) areaCount.get(areaName);
                totalValue = oldTotal + testCount;
            } else {
                totalValue = testCount;
            }
            areaCount.put(areaName, totalValue);

        } // while list has elements

        // Make sure every area is represented in the build totals
        Enumeration bt = buildTotals.keys();
        while (bt.hasMoreElements()) {
            // Get the build ID for the current build
            Integer bid = (Integer) bt.nextElement();

            // Get the list of area totals for the current build
            Hashtable<String, Integer> ac = (Hashtable<String, Integer>) buildTotals.get(bid);
            Iterator a = areas.iterator();
            while (a.hasNext()) {
                // Add a value of zero if no total was found for the current area
                CMnDbFeatureOwnerData area = (CMnDbFeatureOwnerData) a.next();
                if (!ac.containsKey(area.getDisplayName())) {
                    ac.put(area.getDisplayName(), new Integer(0));
                }
            }
        }

        // Populate the data set with the area times for each build
        Collections.sort(builds, new CMnBuildIdComparator());
        Enumeration bList = builds.elements();
        while (bList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) bList.nextElement();
            Integer buildId = new Integer(build.getId());
            Hashtable areaCount = (Hashtable) buildTotals.get(buildId);

            Enumeration areaKeys = areaCount.keys();
            while (areaKeys.hasMoreElements()) {
                String area = (String) areaKeys.nextElement();
                Integer count = (Integer) areaCount.get(area);
                dataset.addValue(count, area, buildId);
            }
        }

    } // if list has elements

    // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls)
    chart = ChartFactory.createStackedBarChart("Automated Tests by Area", "Builds", "Test Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    chartFormatter.formatAreaChart(plot, dataset);

    return chart;
}

From source file:org.martus.client.swingui.PureFxMainWindow.java

public File showFileOpenDialog(String title, File directory, Vector<FormatFilter> filters) {
    FileChooser fileChooser = createFileChooser(title, directory,
            filters.toArray(new FormatFilter[filters.size()]));

    return fileChooser.showOpenDialog(getActiveStage());
}

From source file:com.ricemap.spateDB.util.CommandLineArguments.java

public Prism[] getPrisms() {
    Vector<Prism> Prisms = new Vector<Prism>();
    for (String arg : args) {
        if (arg.startsWith("rect:") || arg.startsWith("prism:") || arg.startsWith("mbr:")) {
            Prism rect = new Prism();
            rect.fromText(new Text(arg.substring(arg.indexOf(':') + 1)));
            Prisms.add(rect);//from  w  ww . j a  va2 s.c  o  m
        }
    }
    return Prisms.toArray(new Prism[Prisms.size()]);
}