List of usage examples for java.util Vector add
public synchronized boolean add(E e)
From source file:eionet.gdem.dcm.business.WorkqueueManager.java
/** * Adds new jobs into the workqueue by the given XML Schema * * @param user//w w w. j a v a2 s . c om * Loggedin user name. * @param sourceUrl * Source URL of XML file. * @param schemaUrl * XML Schema URL. * @return List of job IDs. * @throws DCMException */ public List<String> addSchemaScriptsToWorkqueue(String user, String sourceUrl, String schemaUrl) throws DCMException { List<String> result = new ArrayList<String>(); try { if (!SecurityUtil.hasPerm(user, "/" + Names.ACL_WQ_PATH, "i")) { LOGGER.debug("You don't have permissions jobs into workqueue!"); throw new DCMException(BusinessConstants.EXCEPTION_AUTORIZATION_QASCRIPT_UPDATE); } } catch (DCMException e) { throw e; } catch (Exception e) { LOGGER.error("Error adding job to workqueue", e); throw new DCMException(BusinessConstants.EXCEPTION_GENERAL); } XQueryService xqE = new XQueryService(); xqE.setTrustedMode(false); try { Hashtable h = new Hashtable(); Vector files = new Vector(); files.add(sourceUrl); h.put(schemaUrl, files); Vector v_result = xqE.analyzeXMLFiles(h); if (v_result != null) { for (int i = 0; i < v_result.size(); i++) { Vector v = (Vector) v_result.get(i); result.add((String) v.get(0)); } } } catch (Exception e) { e.printStackTrace(); LOGGER.error("Error adding job to workqueue", e); throw new DCMException(BusinessConstants.EXCEPTION_GENERAL); } return result; }
From source file:de.escidoc.core.test.om.container.ContainerReferenceIT.java
/** * References that are to skip (or non valid GET refs). * * @param ref The reference (path)./*from w w w . ja va 2 s.c o m*/ * @return True if the reference is to skip, false otherwise. */ private boolean skipRefCheck(final String ref) { Vector<String> skipList = new Vector<String>(); skipList.add("members/filter"); skipList.add("members/filter/refs"); for (int i = 0; i < skipList.size(); i++) { if (ref.endsWith(skipList.get(i))) { return (true); } } return false; }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.shared.interfaces.PriceChart.java
/** Constructs the securities Vector, used for transferring price chart data from * server to client *//*from w ww . ja v a2 s .c om*/ public Vector getSecurities() { securities = new Vector(); Enumeration en = lines.elements(); while (en.hasMoreElements()) { Vector secVect = new Vector(); XYSeries series = (XYSeries) en.nextElement(); String name = series.getName(); secVect.add(name); for (int i = 0; i < series.getItemCount(); i++) { XYDataItem point = series.getDataItem(i); float time = ((Number) point.getX()).floatValue(); float price = ((Number) point.getY()).floatValue(); float[] p = new float[2]; p[0] = time; p[1] = price; secVect.add(p); } securities.add(secVect); } return securities; }
From source file:api.v2.LabdooClient.java
public boolean updateLaptop(Laptop newLaptop) throws APIException { Vector<Object> params = new Vector<Object>(); params.add(newLaptop.toMap()); Map<String, Object> response; try {/* w w w .jav a 2 s . c om*/ client.execute(METHOD_NODE_UPDATE, params); } catch (XmlRpcException e) { log.error(e.getMessage(), e.getCause()); APIException apiException = new APIException(); apiException.initCause(e.getCause()); throw apiException; } return true; }
From source file:api.v2.LabdooClient.java
public String addLaptop(Laptop laptop) throws APIException { Vector<Object> params = new Vector<Object>(); params.add(laptop.toMap()); Map<String, Object> response; try {//from w w w .j a va2 s . co m response = (Map<String, Object>) client.execute(METHOD_NODE_CREATE, params); } catch (XmlRpcException e) { log.error(e.getMessage(), e.getCause()); APIException apiException = new APIException(); apiException.initCause(e.getCause()); throw apiException; } return (String) response.get("nid"); }
From source file:api.v2.LabdooClient.java
public Laptop getLaptop(String nid) throws APIException { HashMap<String, Object> node = new HashMap<String, Object>(); node.put("nid", "" + nid); Vector<Object> params = new Vector<Object>(); params.add(node); Map<String, Object> response; try {//from ww w . j av a 2s . c o m response = (Map<String, Object>) client.execute(METHOD_NODE_RETRIEVE, params); } catch (XmlRpcException e) { log.error(e.getMessage(), e.getCause()); APIException apiException = new APIException(); apiException.initCause(e.getCause()); throw apiException; } return Laptop.newInstance(response); }
From source file:api.v2.LabdooClient.java
public String createNewUser(User user) throws APIException { Vector<Object> params = new Vector<Object>(); params.add(user.toMap()); Map<String, Object> response; try {// w ww .j ava2 s .co m response = (Map<String, Object>) client.execute(METHOD_USER_CREATE, params); } catch (XmlRpcException e) { log.error(e.getMessage(), e.getCause()); APIException apiException = new APIException(); apiException.initCause(e.getCause()); throw apiException; } return (String) response.get("nid"); }
From source file:edu.umn.cs.spatialHadoop.nasa.StockQuadTree.java
/** * Merges a set of indexes into larger indexes * @param fs//from w w w. j a va 2 s .c om * @param srcIndexDir * @param dstIndexDir * @param srcFormat * @param dstFormat * @param params * @throws IOException * @throws ParseException * @throws InterruptedException */ private static void mergeIndexes(final FileSystem fs, Path srcIndexDir, Path dstIndexDir, SimpleDateFormat srcFormat, SimpleDateFormat dstFormat, final OperationsParams params) throws IOException, ParseException, InterruptedException { TimeRange timeRange = params.get("time") != null ? new TimeRange(params.get("time")) : null; final FileStatus[] sourceIndexes = timeRange == null ? fs.listStatus(srcIndexDir) : fs.listStatus(srcIndexDir, timeRange); Arrays.sort(sourceIndexes); // Alphabetical sort acts as sort-by-date here // Scan the source indexes and merge each consecutive run belonging to the // same unit int i1 = 0; while (i1 < sourceIndexes.length) { final String indexToCreate = dstFormat.format(srcFormat.parse(sourceIndexes[i1].getPath().getName())); int i2 = i1 + 1; // Keep scanning as long as the source index belongs to the same dest index while (i2 < sourceIndexes.length && dstFormat .format(srcFormat.parse(sourceIndexes[i2].getPath().getName())).equals(indexToCreate)) i2++; // Merge all source indexes in the range [i1, i2) into one dest index // Copy i1, i2 to other variables as final to be accessible from threads final int firstIndex = i1; final int lastIndex = i2; final Path destIndex = new Path(dstIndexDir, indexToCreate); // For each tile, merge all values in all source indexes /*A regular expression to catch the tile identifier of a MODIS grid cell*/ final Pattern MODISTileID = Pattern.compile("^.*(h\\d\\dv\\d\\d).*$"); final FileStatus[] tilesInFirstDay = fs.listStatus(sourceIndexes[i1].getPath()); // Shuffle the array for better load balancing across threads Random rand = new Random(); for (int i = 0; i < tilesInFirstDay.length - 1; i++) { // Swap the entry at i with any following entry int j = i + rand.nextInt(tilesInFirstDay.length - i - 1); FileStatus temp = tilesInFirstDay[i]; tilesInFirstDay[i] = tilesInFirstDay[j]; tilesInFirstDay[j] = temp; } Parallel.forEach(tilesInFirstDay.length, new RunnableRange<Object>() { @Override public Object run(int i_file1, int i_file2) { for (int i_file = i_file1; i_file < i_file2; i_file++) { try { FileStatus tileInFirstDay = tilesInFirstDay[i_file]; // Extract tile ID Matcher matcher = MODISTileID.matcher(tileInFirstDay.getPath().getName()); if (!matcher.matches()) { LOG.warn("Cannot extract tile id from file " + tileInFirstDay.getPath()); continue; } final String tileID = matcher.group(1); Path destIndexFile = new Path(destIndex, tileID); PathFilter tileFilter = new PathFilter() { @Override public boolean accept(Path path) { return path.getName().contains(tileID); } }; // Find matching tiles in all source indexes to merge Vector<Path> filesToMerge = new Vector<Path>(lastIndex - firstIndex); filesToMerge.add(tileInFirstDay.getPath()); for (int iDailyIndex = firstIndex + 1; iDailyIndex < lastIndex; iDailyIndex++) { FileStatus[] matchedTileFile = fs.listStatus(sourceIndexes[iDailyIndex].getPath(), tileFilter); if (matchedTileFile.length == 0) LOG.warn("Could not find tile " + tileID + " in dir " + sourceIndexes[iDailyIndex].getPath()); else if (matchedTileFile.length == 1) filesToMerge.add(matchedTileFile[0].getPath()); } if (fs.exists(destIndexFile)) { // Destination file already exists // Check the date of the destination and source files to see // whether it needs to be updated or not long destTimestamp = fs.getFileStatus(destIndexFile).getModificationTime(); boolean needsUpdate = false; for (Path fileToMerge : filesToMerge) { long sourceTimestamp = fs.getFileStatus(fileToMerge).getModificationTime(); if (sourceTimestamp > destTimestamp) { needsUpdate = true; break; } } if (!needsUpdate) continue; else LOG.info("Updating file " + destIndexFile.getName()); } // Do the merge Path tmpFile; do { tmpFile = new Path((int) (Math.random() * 1000000) + ".tmp"); } while (fs.exists(tmpFile)); tmpFile = tmpFile.makeQualified(fs); LOG.info("Merging tile " + tileID + " into file " + destIndexFile); AggregateQuadTree.merge(params, filesToMerge.toArray(new Path[filesToMerge.size()]), tmpFile); synchronized (fs) { Path destDir = destIndexFile.getParent(); if (!fs.exists(destDir)) fs.mkdirs(destDir); } fs.rename(tmpFile, destIndexFile); } catch (IOException e) { e.printStackTrace(); } } return null; } }); i1 = i2; } }
From source file:api.v2.LabdooClient.java
public boolean deleteLaptop(String nid) throws APIException { HashMap<String, Object> node = new HashMap<String, Object>(); node.put("nid", "" + nid); Vector<Object> params = new Vector<Object>(); params.add(node); Map<String, Object> response; try {/*from w w w. j a v a 2 s .c om*/ client.execute(METHOD_NODE_DELETE, params); } catch (XmlRpcException e) { log.error(e.getMessage(), e.getCause()); APIException apiException = new APIException(); apiException.initCause(e.getCause()); throw apiException; } return true; }
From source file:api.v2.LabdooClient.java
public List<Laptop> listLaptops(Map<String, String> filters, int numIndex, int size) throws APIException { Vector<Object> params = new Vector<Object>(); params.add(filters); Map<String, Object> response; List<Laptop> laptops = new ArrayList<Laptop>(); try {//www . ja va 2s . c om response = (Map<String, Object>) client.execute(METHOD_NODE_LIST, params); Set<String> keys = response.keySet(); for (String key : keys) { Map<String, Object> value = (Map<String, Object>) response.get(key); laptops.add(Laptop.newInstance(value)); } } catch (XmlRpcException e) { log.error(e.getMessage(), e.getCause()); APIException apiException = new APIException(); apiException.initCause(e.getCause()); throw apiException; } return laptops; }