Example usage for java.util Vector add

List of usage examples for java.util Vector add

Introduction

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

Prototype

public synchronized boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this Vector.

Usage

From source file:net.dataforte.commons.resources.ClassUtils.java

private static String joinParts(String separator, String... paths) {
    Vector<String> trimmed = new Vector<String>();
    int pos = 0;/*from ww  w .j av a 2  s. co  m*/
    int last = paths.length - 1;
    for (String path : paths) {
        String trimmedPath;
        if (pos == 0)
            trimmedPath = StringUtils.stripEnd(path, separator);
        else if (pos == last)
            trimmedPath = StringUtils.stripStart(path, separator);
        else
            trimmedPath = StringUtils.strip(path, separator);
        trimmed.add(trimmedPath);
        pos += 1;
    }
    String joined = String.join(separator, trimmed);
    return joined;
}

From source file:com.qmetry.qaf.automation.util.FileUtil.java

public static Collection<File> getFiles(File directory, String extension, boolean recurse) {
    // List of files / directories
    Vector<File> files = new Vector<File>();

    // Get files / directories in the directory
    File[] entries = directory.listFiles();
    FilenameFilter filter = getFileFilterFor(extension, StringComparator.Suffix);
    // Go over entries
    for (File entry : entries) {
        if ((filter == null) || filter.accept(directory, entry.getName())) {
            files.add(entry);
        }//from   ww  w  .  j  av  a  2 s. c  o  m

        // If the file is a directory and the recurse flag
        // is set, recurse into the directory
        if (recurse && entry.isDirectory()) {
            files.addAll(listFiles(entry, filter, recurse));
        }
    }

    // Return collection of files
    return files;
}

From source file:Main.java

public static Vector<String> getHandsets(String file) throws Exception {
    Vector<String> vec = new Vector();
    DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();
    DocumentBuilder dombuilder = domfac.newDocumentBuilder();
    FileInputStream is = new FileInputStream(file);

    Document doc = dombuilder.parse(is);
    NodeList nodeList = doc.getElementsByTagName("devices");
    if (nodeList != null && nodeList.getLength() >= 1) {
        Node deviceNode = nodeList.item(0);
        NodeList children = deviceNode.getChildNodes();
        if (children != null && children.getLength() >= 1) {
            for (int i = 0; i < children.getLength(); i++) {
                vec.add(children.item(i).getTextContent());
            }//from  www  .j  a v  a 2  s.  c  o m
        }
    }
    return vec;
}

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

/**
 * Performs a spatio-temporal aggregate query on an indexed directory
 * @param inFile/*from   w ww. java 2  s. co  m*/
 * @param params
 * @throws ParseException 
 * @throws IOException 
 * @throws InterruptedException 
 */
public static AggregateQuadTree.Node aggregateQuery(Path inFile, OperationsParams params)
        throws ParseException, IOException, InterruptedException {
    // 1- Find matching temporal partitions
    final FileSystem fs = inFile.getFileSystem(params);
    Vector<Path> matchingPartitions = selectTemporalPartitions(inFile, params);

    // 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());
        }
    }

    //noinspection SizeReplaceableByIsEmpty
    if (allMatchingFiles.isEmpty())
        return null;

    final int resolution = AggregateQuadTree.getResolution(fs, allMatchingFiles.get(0));

    // 3- Query all matching files in parallel
    List<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++) {
                        Path matchingFile = allMatchingFiles.get(i_file);
                        try {
                            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) * resolution);
                            int y1 = (int) (Math.max(translated.y1, 0) * resolution);
                            int x2 = (int) (Math.min(translated.x2, 1.0) * resolution);
                            int y2 = (int) (Math.min(translated.y2, 1.0) * resolution);
                            AggregateQuadTree.Node fileResult = AggregateQuadTree.aggregateQuery(fs,
                                    matchingFile, new java.awt.Rectangle(x1, y1, (x2 - x1), (y2 - y1)));
                            threadResult.accumulate(fileResult);
                        } catch (Exception e) {
                            throw new RuntimeException("Error reading file " + matchingFile, e);
                        }
                    }
                    return threadResult;
                }
            });
    AggregateQuadTree.Node finalResult = new AggregateQuadTree.Node();
    for (Node threadResult : threadsResults) {
        finalResult.accumulate(threadResult);
    }
    numOfTreesTouchesInLastRequest = allMatchingFiles.size();
    return finalResult;
}

From source file:com.bluexml.xforms.demo.Util.java

public static Set<Vector<String>> getDefinitions(String alfrescohost, String user) {
    Set<Vector<String>> result = new HashSet<Vector<String>>();
    try {// www  . j  av  a  2s  .  c om
        PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow");
        post.setParameter("username", user);
        post.setParameter("method", "getDefinitions");
        HttpClient client = new HttpClient();
        client.executeMethod(post);

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(post.getResponseBodyAsStream());

        Node root = document.getDocumentElement();
        root = findNode(root.getChildNodes(), "list");

        for (int i = 0; i < root.getChildNodes().getLength(); i++) {
            Node n = root.getChildNodes().item(i);
            if (n.getNodeType() == Element.ELEMENT_NODE) {
                Vector<String> v = new Vector<String>();
                v.add(findNode(n.getChildNodes(), "id").getTextContent());
                v.add(findNode(n.getChildNodes(), "version").getTextContent());
                v.add(findNode(n.getChildNodes(), "title").getTextContent());
                v.add(findNode(n.getChildNodes(), "description").getTextContent());
                v.add(findNode(n.getChildNodes(), "name").getTextContent());
                result.add(v);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

private static Vector<int[]> setpartition(int n) {
    Vector<int[]> subsetv = new Vector<int[]>();

    //set partition by setpart2 algorithm
    int[] c = new int[n + 1];
    int[] b = new int[n + 1];
    int r = 1;/*w  w w  . j av a 2  s  . c o  m*/
    c[1] = 1;
    int j = 0;
    b[0] = 1;
    int n1 = n - 1;

    do {
        while (r < n1) {
            r = r + 1;
            c[r] = 1;
            j++;
            b[j] = r;
        }

        for (int i = 1; i <= n - j; ++i) {
            c[n] = i;
            int[] set = new int[n];
            for (int k = 0; k < n; ++k) {
                set[k] = c[k + 1];
            }
            subsetv.add(set);
        }

        r = b[j];
        c[r]++;
        if (c[r] > r - j) {
            j--;
        }

    } while (r != 1);

    return subsetv;
}

From source file:com.bluexml.xforms.demo.Util.java

private static Collection<? extends Vector<String>> getInstancesById(String alfrescohost, String user,
        String id) throws Exception {
    Set<Vector<String>> result = new HashSet<Vector<String>>();

    PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow");
    post.setParameter("username", user);
    post.setParameter("method", "getActiveWorkflows");
    post.setParameter("arg0", id);
    HttpClient client = new HttpClient();
    client.executeMethod(post);/*from   w ww.  jav  a2s .  co  m*/

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(post.getResponseBodyAsStream());
    Node root = document.getDocumentElement();

    for (int i = 0; i < root.getChildNodes().getLength(); i++) {
        Node n = root.getChildNodes().item(i);
        if (n.getNodeType() == Element.ELEMENT_NODE) {
            Vector<String> v = new Vector<String>();
            v.add(findNode(n.getChildNodes(), "id").getTextContent());
            v.add(findNode(n.getChildNodes(), "startDate").getTextContent());

            String initiator = findNode(findNode(n.getChildNodes(), "initiator").getChildNodes(), "id")
                    .getTextContent();
            String protocol = findNode(
                    findNode(findNode(n.getChildNodes(), "initiator").getChildNodes(), "storeRef")
                            .getChildNodes(),
                    "protocol").getTextContent();
            String identifier = findNode(
                    findNode(findNode(n.getChildNodes(), "initiator").getChildNodes(), "storeRef")
                            .getChildNodes(),
                    "identifier").getTextContent();

            String username = getUserName(alfrescohost, user, protocol, identifier, initiator);
            v.add(username);
            v.add(findNode(findNode(n.getChildNodes(), "definition").getChildNodes(), "version")
                    .getTextContent());

            result.add(v);
        }
    }

    return result;
}

From source file:com.thoughtworks.go.util.SelectorUtils.java

/**
 * Breaks a path up into a Vector of path elements, tokenizing on
 *
 * @param path Path to tokenize. Must not be <code>null</code>.
 * @param separator the separator against which to tokenize.
 *
 * @return a Vector of path elements from the tokenized path
 * @since Ant 1.6// w w  w  . ja v a2 s.c o  m
 */
public static Vector tokenizePath(String path, String separator) {
    Vector ret = new Vector();
    if (FileUtil.isAbsolutePath(path)) {
        String[] s = FileUtil.dissect(path);
        ret.add(s[0]);
        path = s[1];
    }
    StringTokenizer st = new StringTokenizer(path, separator);
    while (st.hasMoreTokens()) {
        ret.addElement(st.nextToken());
    }
    return ret;
}

From source file:net.nosleep.superanalyzer.analysis.views.SummaryView.java

public static Vector createStatPairs(Analysis analysis) {

    Stat trackStats = analysis.getStats(Analysis.KIND_TRACK, null);

    String name;/*from  ww w  . ja va2 s . c  om*/
    String value;
    String description;
    StringTriple triple;

    Vector statPairs = new Vector();

    name = Misc.getString("TRACK_COUNT");
    value = Misc.getFormattedCountAsInt(trackStats.getTrackCount(), Misc.getString("TRACK"),
            Misc.getString("TRACKS"));
    description = Misc.getString("TRACK_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("PLAY_COUNT");
    value = Misc.getFormattedCountAsInt(trackStats.getPlayCount(), Misc.getString("TRACK"),
            Misc.getString("TRACKS")) + " " + Misc.getString("PLAYED");
    description = Misc.getString("PLAY_COUNT_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("TOTAL_TIME");
    value = Misc.getFormattedDuration(trackStats.getTotalTime());
    description = Misc.getString("TOTAL_TIME_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("TOTAL_PLAY_TIME");
    value = Misc.getFormattedDuration(trackStats.getTotalPlayTime());
    description = Misc.getString("TOTAL_PLAY_TIME_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("ARTIST_COUNT");
    value = Misc.getFormattedCountAsInt(analysis.getHash(Analysis.KIND_ARTIST).size(), Misc.getString("ARTIST"),
            Misc.getString("ARTISTS"));
    description = Misc.getString("ARTIST_COUNT_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("ALBUM_COUNT");
    value = Misc.getFormattedCountAsInt(analysis.getHash(Analysis.KIND_ALBUM).size(), Misc.getString("ALBUM"),
            Misc.getString("ALBUMS"));
    description = Misc.getString("ALBUM_COUNT_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("GENRE_COUNT");
    value = Misc.getFormattedCountAsInt(analysis.getHash(Analysis.KIND_GENRE).size(), Misc.getString("GENRE"),
            Misc.getString("GENRES"));
    description = Misc.getString("GENRE_COUNT_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("MOST_SONGS_PLAYED_AT");
    int hour = trackStats.getPopularHour();
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, 0);
    SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT);
    value = formatter.format(c.getTime()) + " " + Misc.getString("HOUR_SUFFIX");
    description = Misc.getString("MOST_SONGS_PLAYED_AT_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("AVERAGE_TRACK_LENGTH");
    value = Misc.getFormattedDuration(trackStats.getAvgLength());
    description = Misc.getString("AVERAGE_TRACK_LENGTH_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("AVERAGE_PLAY_COUNT");
    value = Misc.getFormattedCount(trackStats.getAvgPlayCount(), Misc.getString("PLAY"),
            Misc.getString("PLAYS")) + " " + Misc.getString("PER_SONG");
    description = Misc.getString("AVERAGE_PLAY_COUNT_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("AVERAGE_ALBUM_COMPLETENESS");
    value = Misc.getFormattedPercentage(analysis.getAvgAlbumCompleteness()) + " " + Misc.getString("COMPLETE");
    description = Misc.getString("AVERAGE_ALBUM_COMPLETENESS_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("COMPLETE_ALBUMS");
    value = Misc.getFormattedPercentage(analysis.getAvgCompleteAlbums()) + " " + Misc.getString("ARE_COMPLETE");
    description = Misc.getString("COMPLETE_ALBUMS_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("AVERAGE_BIT_RATE");
    value = Misc.getFormattedBitrate(analysis.getAvgBitRate());
    description = Misc.getString("AVERAGE_BIT_RATE_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("AVERAGE_FILE_SIZE");
    value = Misc.getFormattedByteCount(analysis.getAvgFileSize());
    description = Misc.getString("AVERAGE_FILE_SIZE_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("TOTAL_LIBRARY_SIZE");
    value = Misc.getFormattedByteCount(analysis.getTotalLibrarySize());
    description = Misc.getString("TOTAL_LIBRARY_SIZE_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("ALL_SONGS_PLAYED");
    value = Misc.getFormattedPercentage(analysis.getAvgTracksPlayedAtLeastOnce()) + " "
            + Misc.getString("PLAYED_AT_LEAST_ONCE");
    description = Misc.getString("ALL_SONGS_PLAYED_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("COMPILATIONS");
    value = Misc.getFormattedPercentage(trackStats.getTrackCompilationPercentage());
    description = Misc.getString("COMPILATIONS_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("LIBRARY_AGE");
    value = Misc.getFormattedDuration(analysis.getLibraryAge());
    description = Misc.getString("LIBRARY_AGE_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    name = Misc.getString("AVERAGE_GROWTH_RATE");
    value = Misc.getFormattedCount(analysis.getAverageGrowthRate(), Misc.getString("SONG"),
            Misc.getString("SONGS")) + "/" + Misc.capitalizeByLocale(Misc.getString("WEEK"));
    description = Misc.getString("AVERAGE_GROWTH_RATE_TOOLTIP");
    triple = new StringTriple(name, value, description);
    statPairs.add(triple);

    return statPairs;
}

From source file:edu.umass.cs.msocket.gns.GnsIntegration.java

/**
 * Lookup the IP address(es) of an MServerSocket by its Human Readable Name
 * registered in the GNS.//from w  ww  .j a  v  a2 s  .  c om
 * throws UnknownHostException, so that it is similar to
 * exception thrown on DNS failure
 * @param name Human readable name of the MServerSocket
 * @param gnsCredentials GNS credentials to use
 * @return list of IP addresses or null if not found
 * @throws Exception
 */
public static List<InetSocketAddress> getSocketAddressFromGNS(String name, GnsCredentials gnsCredentials)
        throws UnknownHostException {
    try {
        log.trace("Retrieving IP of " + name);

        if (gnsCredentials == null) {
            gnsCredentials = GnsCredentials.getDefaultCredentials();
        }

        UniversalGnsClient gnsClient = gnsCredentials.getGnsClient();
        String guidString = gnsClient.lookupGuid(name);
        log.trace("GUID lookup " + guidString);

        JSONArray resultArray;
        // Read from the GNS
        synchronized (gnsClient) {
            resultArray = gnsClient.fieldRead(guidString, GnsConstants.SERVER_REG_ADDR, null);
        }
        Vector<InetSocketAddress> resultVector = new Vector<InetSocketAddress>();
        for (int i = 0; i < resultArray.length(); i++) {
            String str = resultArray.getString(i);
            log.trace("Value returned from GNS " + str);
            String[] Parsed = str.split(":");
            InetSocketAddress socketAddress = new InetSocketAddress(Parsed[0], Integer.parseInt(Parsed[1]));
            resultVector.add(socketAddress);
        }

        return resultVector;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new UnknownHostException(ex.toString());
    }
}