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.rim.ejde.internal.builders.PreprocessingBuilder.java

/**
 * Get all preprocess defines: JRE leve, workspace level and project level.
 *
 * @param BBProject//from  w w  w. ja v a 2 s  . c om
 * @param ignoreInActive
 * @return
 */
static public Vector<String> getDefines(BlackBerryProject BBProject, boolean ignoreInActive) {
    List<PreprocessorTag> workspaceDefines = PreprocessorPreferences.getPreprocessDefines();
    PreprocessorTag[] projectDefines = BBProject.getProperties()._compile.getPreprocessorDefines();
    Vector<String> newDefines = new Vector<String>();
    for (PreprocessorTag ppDefine : workspaceDefines) {
        if (!ignoreInActive || ppDefine.isActive()) {
            newDefines.add(EnvVarUtils.replaceRIAEnvVars(ppDefine.getPreprocessorDefine()));
        }
    }
    for (int i = 0; i < projectDefines.length; i++) {
        if (!ignoreInActive || projectDefines[i].isActive()) {
            newDefines.add(EnvVarUtils.replaceRIAEnvVars(projectDefines[i].getPreprocessorDefine()));
        }
    }
    String cpDefine = VMUtils.getJREDirective(BBProject);
    if (!StringUtils.isBlank(cpDefine)) {
        newDefines.add(cpDefine);
    }
    return newDefines;
}

From source file:edu.umn.cs.spatialHadoop.operations.CatUnion.java

/**
 * Calculates the union of a set of shapes categorized by some user defined
 * category.// w w  w .j  ava  2  s  .  co  m
 * @param shapeFile
 * @param categoryFile
 * @return
 * @throws IOException
 */
public static Map<Integer, OGCGeometry> unionLocal(Path shapeFile, Path categoryFile) throws IOException {
    long t1 = System.currentTimeMillis();
    // 1- Build a hashtable of categories (given their size is small)
    Map<Integer, Integer> idToCategory = new HashMap<Integer, Integer>();
    readCategories(categoryFile, idToCategory);
    long t2 = System.currentTimeMillis();

    // 2- Read shapes from the shape file and relate each one to a category

    // Prepare a hash that stores shapes in each category
    Map<Integer, Vector<OGCGeometry>> categoryShapes = new HashMap<Integer, Vector<OGCGeometry>>();

    FileSystem fs1 = shapeFile.getFileSystem(new Configuration());
    long file_size1 = fs1.getFileStatus(shapeFile).getLen();

    ShapeIterRecordReader shapeReader = new ShapeIterRecordReader(fs1.open(shapeFile), 0, file_size1);
    Rectangle cellInfo = shapeReader.createKey();
    ShapeIterator shapes = shapeReader.createValue();

    while (shapeReader.next(cellInfo, shapes)) {
        for (Shape shape : shapes) {
            //int shape_zip = Integer.parseInt(shape.extra.split(",", 7)[5]);
            //Integer category = idToCategory.get(shape_zip);
            Integer category = null;
            if (category != null) {
                Vector<OGCGeometry> geometries = categoryShapes.get(category);
                if (geometries == null) {
                    geometries = new Vector<OGCGeometry>();
                    categoryShapes.put(category, geometries);
                }
                geometries.add(((OGCESRIShape) shape).geom);
            }
        }
    }

    shapeReader.close();
    long t3 = System.currentTimeMillis();

    // 3- Find the union of each category
    Map<Integer, OGCGeometry> final_result = new HashMap<Integer, OGCGeometry>();
    for (Map.Entry<Integer, Vector<OGCGeometry>> category : categoryShapes.entrySet()) {
        if (!category.getValue().isEmpty()) {
            OGCGeometryCollection geom_collection = new OGCConcreteGeometryCollection(category.getValue(),
                    category.getValue().firstElement().esriSR);
            OGCGeometry union = geom_collection.union(category.getValue().firstElement());
            final_result.put(category.getKey(), union);
            // Free up some memory
            category.getValue().clear();
        }
    }
    long t4 = System.currentTimeMillis();

    System.out.println("Time reading categories: " + (t2 - t1) + " millis");
    System.out.println("Time reading records: " + (t3 - t2) + " millis");
    System.out.println("Time union categories: " + (t4 - t3) + " millis");

    return final_result;
}

From source file:net.firejack.platform.core.utils.StringUtils.java

/**
 * @param text//from   w  w w  . j  a va 2 s . co m
 * @param len
 * @return
 */
public static String[] wrapText(String text, int len) {
    // return empty array for null text
    if (text == null)
        return new String[] {};

    // return text if len is zero or less
    if (len <= 0)
        return new String[] { text };

    // return text if less than length
    if (text.length() <= len)
        return new String[] { text };

    char[] chars = text.toCharArray();
    Vector lines = new Vector();
    StringBuilder line = new StringBuilder();
    StringBuilder word = new StringBuilder();

    for (char aChar : chars) {
        word.append(aChar);

        if (aChar == ' ') {
            if ((line.length() + word.length()) > len) {
                lines.add(line.toString());
                line.delete(0, line.length());
            }

            line.append(word);
            word.delete(0, word.length());
        }
    }

    // handle any extra chars in current word
    if (word.length() > 0) {
        if ((line.length() + word.length()) > len) {
            lines.add(line.toString());
            line.delete(0, line.length());
        }
        line.append(word);
    }

    // handle extra line
    if (line.length() > 0) {
        lines.add(line.toString());
    }

    String[] ret = new String[lines.size()];
    int c = 0; // counter
    for (Enumeration e = lines.elements(); e.hasMoreElements(); c++) {
        ret[c] = (String) e.nextElement();
    }

    return ret;
}

From source file:it.eng.spagobi.tools.downloadFiles.service.DownloadZipAction.java

/** getSortedArray.
 * /*from w ww .j  ava2 s .c o  m*/
 * @return File[]
 */
static public final File[] getSortedArray(File directory, String prefix) {
    File[] allFiles = directory.listFiles();
    Vector labelFilesVector = new Vector<File>();
    for (int i = 0; i < allFiles.length; i++) {
        String fileName = allFiles[i].getName();
        if (fileName.startsWith(prefix)) {
            labelFilesVector.add(allFiles[i]);
        }
    }

    if (labelFilesVector.size() == 0) {
        return null;
    }

    // I need an array
    int j = 0;
    File[] labelFiles = new File[labelFilesVector.size()];
    for (Iterator iterator = labelFilesVector.iterator(); iterator.hasNext();) {
        File object = (File) iterator.next();
        labelFiles[j] = object;
        j++;
    }

    Arrays.sort(labelFiles, new Comparator() {
        public int compare(final Object o1, final Object o2) {

            if (((File) o1).lastModified() > ((File) o2).lastModified()) {
                return +1;
            } else if (((File) o1).lastModified() < ((File) o2).lastModified()) {
                return -1;
            } else {
                return 0;
            }
        }

    });

    return labelFiles;
}

From source file:jenkins.plugins.coverity.CoverityUtils.java

public static Collection<File> listFiles(File directory, FilenameFilter filter, boolean recurse) {
    Vector<File> files = new Vector<File>();
    File[] entries = directory.listFiles();
    if (entries == null) {
        return files;
    }/* w  w  w.j  a va  2  s.  c o m*/

    for (File entry : entries) {
        if (filter == null || filter.accept(directory, entry.getName())) {
            files.add(entry);
        }

        if (recurse && entry.isDirectory()) {
            files.addAll(listFiles(entry, filter, recurse));
        }
    }

    return files;
}

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

public static Collection<File> getFiles(File directory, String name, StringComparator c, 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(name, c);
    // Go over entries
    for (File entry : entries) {
        if ((filter == null) || filter.accept(directory, entry.getName())) {
            files.add(entry);
        }/* w w w .  j  a v  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:edu.umn.cs.spatialHadoop.nasa.SpatioAggregateQueries.java

/**
 * Performs a spatio-temporal aggregate query on an indexed directory
 * @param inFile// w ww  .j  av a 2  s.  c o  m
 * @param params
 * @throws ParseException 
 * @throws IOException 
 * @throws InterruptedException 
 */
public static long selectionQuery(Path inFile, final ResultCollector<NASAPoint> output, 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 the matching tile and the position in that tile
    final Point queryPoint = (Point) params.getShape("point");
    final double userQueryLon = queryPoint.x;
    final double userQueryLat = queryPoint.y;
    // Convert query point from lat/lng space to Sinusoidal space
    double cosPhiRad = Math.cos(queryPoint.y * Math.PI / 180);
    double projectedX = queryPoint.x * cosPhiRad;
    queryPoint.x = (projectedX + 180.0) / 10.0;
    queryPoint.y = (90.0 - queryPoint.y) / 10.0;
    final int h = (int) Math.floor(queryPoint.x);
    final int v = (int) Math.floor(queryPoint.y);
    final String tileID = String.format("h%02dv%02d", h, v);
    PathFilter rangeFilter = new PathFilter() {
        @Override
        public boolean accept(Path p) {
            return p.getName().indexOf(tileID) >= 0;
        }
    };

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

    // All matching files are supposed to have the same resolution
    final int resolution = AggregateQuadTree.getResolution(fs, allMatchingFiles.get(0));

    final java.awt.Point queryInMatchingTile = new java.awt.Point();
    queryInMatchingTile.x = (int) Math.floor((queryPoint.x - h) * resolution);
    queryInMatchingTile.y = (int) Math.floor((queryPoint.y - v) * resolution);

    // 3- Query all matching files in parallel
    List<Long> threadsResults = Parallel.forEach(allMatchingFiles.size(), new RunnableRange<Long>() {
        @Override
        public Long run(int i1, int i2) {
            ResultCollector<AggregateQuadTree.PointValue> internalOutput = output == null ? null
                    : new ResultCollector<AggregateQuadTree.PointValue>() {
                        NASAPoint middleValue = new NASAPoint(userQueryLon, userQueryLat, 0, 0);

                        @Override
                        public void collect(AggregateQuadTree.PointValue value) {
                            middleValue.value = value.value;
                            middleValue.timestamp = value.timestamp;
                            output.collect(middleValue);
                        }
                    };

            long numOfResults = 0;
            for (int i_file = i1; i_file < i2; i_file++) {
                try {
                    Path matchingFile = allMatchingFiles.get(i_file);
                    java.awt.Rectangle query = new java.awt.Rectangle(queryInMatchingTile.x,
                            queryInMatchingTile.y, 1, 1);
                    AggregateQuadTree.selectionQuery(fs, matchingFile, query, internalOutput);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return numOfResults;
        }
    });
    long totalResults = 0;
    for (long result : threadsResults) {
        totalResults += result;
    }
    return totalResults;
}

From source file:Main.java

private static int extractConditionsOperatorTokens(String relevant, int startPos, Vector<String> list) {
    int pos, pos2, opSize = 5;

    pos = relevant.toUpperCase().indexOf(" AND ", startPos);
    if (pos < 0) {
        pos = relevant.toUpperCase().indexOf(" OR ", startPos);
        opSize = 4;/*from w ww.ja  v  a  2 s  . c o m*/
    }

    //AND may be the last token when we have starting ORs hence skipping them. eg (relevant="/data/question10=7 OR /data/question6=4    OR  /data/question8=1 AND /data/question1='daniel'")
    pos2 = relevant.toUpperCase().indexOf(" OR ", startPos);
    if (pos2 > 0 && pos2 < pos) {
        pos = pos2;
        opSize = 4;
    }

    if (pos < 0) {
        list.add(relevant.substring(startPos).trim());
        opSize = 0;
    } else
        list.add(relevant.substring(startPos, pos).trim());

    return pos + opSize;
}

From source file:Main.java

public static void getScripts(File project, Vector<String> scripts, String projectPath) throws IOException {
    if (project != null && project.isFile()) {
        String canonicalPath = project.getCanonicalPath();
        //System.out.println("bbbbbbbbbbb:" + canonicalPath + "  " + projectPath);
        int index = canonicalPath.indexOf(projectPath);//lastIndexOf(System.getProperty("file.separator") + "workspace" + System.getProperty("file.separator"));
        String relativePath = canonicalPath.substring(projectPath.length(), canonicalPath.length());
        //System.out.println("bbbbbbbbbbb:" + relativePath);
        //scripts.add(project.getCanonicalPath());
        scripts.add(relativePath);
    } else if (project != null && project.isDirectory()) {
        File[] files = project.listFiles();
        for (int i = 0; i < files.length; i++) {
            getScripts(files[i], scripts, projectPath);
        }/*www  . j a v  a2s .c o m*/
    }
}

From source file:android.framework.util.jar.JarVerifier.java

/**
 * Returns a {@code Vector} of all of the
 * {@link java.security.cert.Certificate}s that are associated with the
 * signing of the named signature file./* w  w w.  j ava2s.  c  o m*/
 *
 * @param signatureFileName
 *            the name of a signature file.
 * @param certificates
 *            a {@code Map} of all of the certificate chains discovered so
 *            far while attempting to verify the JAR that contains the
 *            signature file {@code signatureFileName}. This object is
 *            previously set in the course of one or more calls to
 *            {@link #verifyJarSignatureFile(String, String, String, Map, Map)}
 *            where it was passed as the last argument.
 * @return all of the {@code Certificate} entries for the signer of the JAR
 *         whose actions led to the creation of the named signature file.
 */
public static Vector<Certificate> getSignerCertificates(String signatureFileName,
        Map<String, Certificate[]> certificates) {
    Vector<Certificate> result = new Vector<Certificate>();
    Certificate[] certChain = certificates.get(signatureFileName);
    if (certChain != null) {
        for (Certificate element : certChain) {
            result.add(element);
        }
    }
    return result;
}