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:de.mpg.escidoc.services.common.util.Util.java

/**
 * Converts a Format Vector into a Format Array.
 * @param formatsV as Vector/*from ww w  . jav  a2  s . com*/
 * @return Format[]
 */
public static Format[] formatVectorToFormatArray(Vector<Format> formatsV) {
    Format[] formatsA = new Format[formatsV.size()];
    for (int i = 0; i < formatsV.size(); i++) {
        formatsA[i] = (Format) formatsV.get(i);
    }
    return formatsA;
}

From source file:com.ecyrd.jspwiki.ui.TemplateManager.java

/**
 *  Returns resource requests for a particular type.  If there are no resources,
 *  returns an empty array./*from w w  w . j  ava 2  s . com*/
 *
 *  @param ctx WikiContext
 *  @param type The resource request type
 *  @return a String array for the resource requests
 */

@SuppressWarnings("unchecked")
public static String[] getResourceRequests(WikiContext ctx, String type) {
    HashMap<String, Vector<String>> hm = (HashMap<String, Vector<String>>) ctx.getVariable(RESOURCE_INCLUDES);

    if (hm == null)
        return new String[0];

    Vector<String> resources = hm.get(type);

    if (resources == null)
        return new String[0];

    String[] res = new String[resources.size()];

    return resources.toArray(res);
}

From source file:Mopex.java

/**
 * Returns a Method array of the methods to which instances of the specified
 * respond except for those methods defined in the class specifed by limit
 * or any of its superclasses. Note that limit is usually used to eliminate
 * them methods defined by java.lang.Object.
 * /*from  w ww  .  j  a v a2 s . c  o m*/
 * @return Method[]
 * @param cls
 *            java.lang.Class
 * @param limit
 *            java.lang.Class
 */
//start extract getSupportedMethods
public static Method[] getSupportedMethods(Class cls, Class limit) {
    Vector supportedMethods = new Vector();
    for (Class c = cls; c != limit; c = c.getSuperclass()) {
        Method[] methods = c.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            boolean found = false;
            for (int j = 0; j < supportedMethods.size(); j++)
                if (equalSignatures(methods[i], (Method) supportedMethods.elementAt(j))) {
                    found = true;
                    break;
                }
            if (!found)
                supportedMethods.add(methods[i]);
        }
    }
    Method[] mArray = new Method[supportedMethods.size()];
    for (int k = 0; k < mArray.length; k++)
        mArray[k] = (Method) supportedMethods.elementAt(k);
    return mArray;
}

From source file:StringUtils.java

public static String[] split(String string, char[] separatorChars) {
    if (string == null || string.equals(""))
        return new String[] { string };
    int len = string.length();
    Vector separators = new Vector(separatorChars.length);
    for (int s = 0; s < separatorChars.length; s++)
        separators.addElement(new Character(separatorChars[s]));
    Vector list = new Vector();
    int i = 0;//from   w  w w .j  a  va 2s  . co  m
    int start = 0;
    boolean match = false;
    while (i < len) {
        if (separators.contains(new Character(string.charAt(i)))) {
            if (match) {
                list.addElement(string.substring(start, i));
                match = false;
            }
            start = ++i;
            continue;
        }
        match = true;
        i++;
    }
    if (match) {
        list.addElement(string.substring(start, i));
    }
    String[] arr = new String[list.size()];
    list.copyInto(arr);
    return arr;
}

From source file:de.betterform.agent.web.WebUtil.java

/**
 * stores cookies that may exist in request and passes them on to processor for usage in
 * HTTPConnectors. Instance loading and submission then uses these cookies. Important for
 * applications using auth.// ww  w  . j ava2s  .  com
 * <p/>
 * NOTE: this method should be called *before* the Adapter is initialized cause the cookies may
 * already be needed for setup (e.g. loading of XForms via Http)
 */
public static void storeCookies(List<Cookie> requestCookies, XFormsProcessor processor) {
    Vector<BasicClientCookie> commonsCookies = new Vector<BasicClientCookie>();

    if (requestCookies != null && requestCookies.size() > 0) {
        commonsCookies = saveAsBasicClientCookie(requestCookies.iterator(), commonsCookies);
    }

    /*
    if (responseCookies != null && responseCookies.size() > 0) {
    commonsCookies= saveAsBasicClientCookie(responseCookies.iterator(), commonsCookies);
    }
    */
    if (commonsCookies.size() == 0) {
        BasicClientCookie sessionCookie = new BasicClientCookie("JSESSIONID",
                ((WebProcessor) processor).httpSession.getId());
        sessionCookie.setSecure(false);
        sessionCookie.setDomain(null);
        sessionCookie.setPath(null);

        commonsCookies.add(sessionCookie);

    }
    processor.setContextParam(AbstractHTTPConnector.REQUEST_COOKIE,
            commonsCookies.toArray(new BasicClientCookie[0]));
}

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

/**
 * Generate a stacked bar graph representing the total number of tests in
 * in each build. /*from  w w  w . j a va2s  .  c o  m*/
 *
 * @param   builds  List of builds 
 * 
 * @return  Stacked graph representing automated tests across all builds 
 */
public static final JFreeChart getTestCountChart(Vector<CMnDbBuildData> builds) {
    JFreeChart chart = null;

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

        // Collect build test numbers for each of the builds in the list 
        Collections.sort(builds, new CMnBuildIdComparator());
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {

            // Process the test summary for the current build
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            Hashtable testSummary = build.getTestSummary();
            if ((testSummary != null) && (testSummary.size() > 0)) {
                Enumeration keys = testSummary.keys();
                while (keys.hasMoreElements()) {
                    String testType = (String) keys.nextElement();
                    Integer buildId = new Integer(build.getId());
                    CMnDbTestSummaryData tests = (CMnDbTestSummaryData) testSummary.get(testType);
                    // Record the total number of tests
                    dataset.addValue(tests.getTotalCount(), testType, buildId);
                }
            }

        } // while list has elements

    } // if list has elements

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

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

    return chart;
}

From source file:com.almarsoft.GroundhogReader.lib.MessageTextProcessor.java

public static String getAttachmentsHtml(Vector<HashMap<String, String>> mimePartsVector) {

    if (mimePartsVector == null || mimePartsVector.size() == 0)
        return "<!-- No attachments -->\n";

    String retString = null;/*  w  w  w  .  j  a  va  2 s . c  om*/

    if (mimePartsVector == null || mimePartsVector.size() == 0)
        retString = "";

    else {

        StringBuilder returnHtml = new StringBuilder();
        returnHtml.append("<I>Attachments:</i><BR/>\n");
        returnHtml.append("<hr>");
        returnHtml.append("<table>\n");

        for (HashMap<String, String> attachData : mimePartsVector) {
            returnHtml.append("<tr bgcolor=\"#FFFF00\">");
            returnHtml.append("<td>\n");
            returnHtml.append("<A HREF=\"attachment://fake.com/" + attachData.get("md5") + "\">"
                    + attachData.get("name") + "</A><BR/>\n");
            returnHtml.append("</td>\n");

            returnHtml.append("<td>\n");
            returnHtml.append(attachData.get("type"));
            returnHtml.append("</td>\n");

            returnHtml.append("<td>\n");
            returnHtml.append(new Integer(attachData.get("size")) / 1024);
            returnHtml.append(" KB");
            returnHtml.append("</td>\n");

            returnHtml.append("</tr>\n");
        }

        returnHtml.append("</table>\n");
        returnHtml.append("<hr>");
        retString = returnHtml.toString();
    }
    return retString;
}

From source file:de.mpg.escidoc.services.common.util.Util.java

/**
 * Merges a Vector of Format[] into Format[].
 * @param allFormatsV as Format[] Vector
 * @return Format[]//w  w  w.  ja  va  2 s  .  c o  m
 */
public static Format[] mergeFormats(Vector<Format[]> allFormatsV) {
    Vector<Format> tmpV = new Vector<Format>();
    Format[] tmpA;

    for (int i = 0; i < allFormatsV.size(); i++) {
        tmpA = allFormatsV.get(i);
        if (tmpA != null) {
            for (int x = 0; x < tmpA.length; x++) {
                tmpV.add(tmpA[x]);
                //System.out.println(tmpA[x].getName());
            }
        }
    }
    tmpV = getRidOfDuplicatesInVector(tmpV);
    return formatVectorToFormatArray(tmpV);
}

From source file:edu.umn.cs.spatialHadoop.nasa.SpatioTemporalAggregateQuery.java

/**
 * Performs a spatio-temporal aggregate query on an indexed directory
 * @param inFile/* w  w  w . j  a  va2  s . co  m*/
 * @param params
 * @throws ParseException 
 * @throws IOException 
 */
public static AggregateQuadTree.Node aggregateQuery(Path inFile, OperationsParams params)
        throws ParseException, IOException {
    // 1- Run a temporal filter step to find all matching temporal partitions
    Vector<Path> matchingPartitions = new Vector<Path>();
    // List of time ranges to check. Initially it contains one range as
    // specified by the user. Eventually, it can be split into at most two
    // partitions if partially matched by a partition.
    Vector<TimeRange> temporalRanges = new Vector<TimeRange>();
    temporalRanges.add(new TimeRange(params.get("time")));
    Path[] temporalIndexes = new Path[] { new Path(inFile, "yearly"), new Path(inFile, "monthly"),
            new Path(inFile, "daily") };
    int index = 0;
    final FileSystem fs = inFile.getFileSystem(params);
    while (index < temporalIndexes.length && !temporalRanges.isEmpty()) {
        Path indexDir = temporalIndexes[index];
        LOG.info("Checking index dir " + indexDir);
        TemporalIndex temporalIndex = new TemporalIndex(fs, indexDir);
        for (int iRange = 0; iRange < temporalRanges.size(); iRange++) {
            TimeRange range = temporalRanges.get(iRange);
            TemporalPartition[] matches = temporalIndex.selectContained(range.start, range.end);
            if (matches != null) {
                LOG.info("Matched " + matches.length + " partitions in " + indexDir);
                for (TemporalPartition match : matches) {
                    LOG.info("Matched temporal partition: " + match.dirName);
                    matchingPartitions.add(new Path(indexDir, match.dirName));
                }
                // Update range to remove matching part
                TemporalPartition firstMatch = matches[0];
                TemporalPartition lastMatch = matches[matches.length - 1];
                if (range.start < firstMatch.start && range.end > lastMatch.end) {
                    // Need to split the range into two
                    temporalRanges.setElementAt(new TimeRange(range.start, firstMatch.start), iRange);
                    temporalRanges.insertElementAt(new TimeRange(lastMatch.end, range.end), iRange);
                } else if (range.start < firstMatch.start) {
                    // Update range in-place
                    range.end = firstMatch.start;
                } else if (range.end > lastMatch.end) {
                    // Update range in-place
                    range.start = lastMatch.end;
                } else {
                    // Current range was completely covered. Remove it
                    temporalRanges.remove(iRange);
                }
            }
        }
        index++;
    }

    numOfTemporalPartitionsInLastQuery = matchingPartitions.size();

    // 2- Find all matching files (AggregateQuadTrees) in matching partitions
    final Rectangle spatialRange = params.getShape("rect", new Rectangle()).getMBR();
    // Convert spatialRange from lat/lng space to Sinusoidal space
    double cosPhiRad = Math.cos(spatialRange.y1 * Math.PI / 180);
    double southWest = spatialRange.x1 * cosPhiRad;
    double southEast = spatialRange.x2 * cosPhiRad;
    cosPhiRad = Math.cos(spatialRange.y2 * Math.PI / 180);
    double northWest = spatialRange.x1 * cosPhiRad;
    double northEast = spatialRange.x2 * cosPhiRad;
    spatialRange.x1 = Math.min(northWest, southWest);
    spatialRange.x2 = Math.max(northEast, southEast);
    // Convert to the h v space used by MODIS
    spatialRange.x1 = (spatialRange.x1 + 180.0) / 10.0;
    spatialRange.x2 = (spatialRange.x2 + 180.0) / 10.0;
    spatialRange.y2 = (90.0 - spatialRange.y2) / 10.0;
    spatialRange.y1 = (90.0 - spatialRange.y1) / 10.0;
    // Vertically flip because the Sinusoidal space increases to the south
    double tmp = spatialRange.y2;
    spatialRange.y2 = spatialRange.y1;
    spatialRange.y1 = tmp;
    // Find the range of cells in MODIS Sinusoidal grid overlapping the range
    final int h1 = (int) Math.floor(spatialRange.x1);
    final int h2 = (int) Math.ceil(spatialRange.x2);
    final int v1 = (int) Math.floor(spatialRange.y1);
    final int v2 = (int) Math.ceil(spatialRange.y2);
    PathFilter rangeFilter = new PathFilter() {
        @Override
        public boolean accept(Path p) {
            Matcher matcher = MODISTileID.matcher(p.getName());
            if (!matcher.matches())
                return false;
            int h = Integer.parseInt(matcher.group(1));
            int v = Integer.parseInt(matcher.group(2));
            return h >= h1 && h < h2 && v >= v1 && v < v2;
        }
    };

    final Vector<Path> allMatchingFiles = new Vector<Path>();

    for (Path matchingPartition : matchingPartitions) {
        // Select all matching files
        FileStatus[] matchingFiles = fs.listStatus(matchingPartition, rangeFilter);
        for (FileStatus matchingFile : matchingFiles) {
            allMatchingFiles.add(matchingFile.getPath());
        }
    }

    // 3- Query all matching files in parallel
    Vector<Node> threadsResults = Parallel.forEach(allMatchingFiles.size(),
            new RunnableRange<AggregateQuadTree.Node>() {
                @Override
                public Node run(int i1, int i2) {
                    Node threadResult = new AggregateQuadTree.Node();
                    for (int i_file = i1; i_file < i2; i_file++) {
                        try {
                            Path matchingFile = allMatchingFiles.get(i_file);
                            Matcher matcher = MODISTileID.matcher(matchingFile.getName());
                            matcher.matches(); // It has to match
                            int h = Integer.parseInt(matcher.group(1));
                            int v = Integer.parseInt(matcher.group(2));
                            // Clip the query region and normalize in this tile
                            Rectangle translated = spatialRange.translate(-h, -v);
                            int x1 = (int) (Math.max(translated.x1, 0) * 1200);
                            int y1 = (int) (Math.max(translated.y1, 0) * 1200);
                            int x2 = (int) (Math.min(translated.x2, 1.0) * 1200);
                            int y2 = (int) (Math.min(translated.y2, 1.0) * 1200);
                            AggregateQuadTree.Node fileResult = AggregateQuadTree.aggregateQuery(fs,
                                    matchingFile, new java.awt.Rectangle(x1, y1, (x2 - x1), (y2 - y1)));
                            threadResult.accumulate(fileResult);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    return threadResult;
                }
            });
    AggregateQuadTree.Node finalResult = new AggregateQuadTree.Node();
    for (Node threadResult : threadsResults)
        finalResult.accumulate(threadResult);
    numOfTreesTouchesInLastRequest = allMatchingFiles.size();
    return finalResult;
}

From source file:de.mpg.escidoc.services.common.util.Util.java

/**
 * Eliminates duplicates in a Vector.//from  www.  j a va 2  s . c o  m
 * @param dirtyVector as Format Vector
 * @return Vector with unique entries
 */
public static Vector<Format> getRidOfDuplicatesInVector(Vector<Format> dirtyVector) {
    Vector<Format> cleanVector = new Vector<Format>();
    Format format1;
    Format format2;

    for (int i = 0; i < dirtyVector.size(); i++) {
        boolean duplicate = false;
        format1 = (Format) dirtyVector.get(i);
        for (int x = i + 1; x < dirtyVector.size(); x++) {
            format2 = (Format) dirtyVector.get(x);
            if (isFormatEqual(format1, format2)) {
                duplicate = true;
            }
        }
        if (!duplicate) {
            cleanVector.add(format1);
        }
    }

    return cleanVector;
}