List of usage examples for java.util Vector add
public synchronized boolean add(E e)
From source file:Main.java
/** * Retrieves the given DOM element's child elements with the specified name. * If name is null, all children are retrieved. *//*from w w w.j a v a 2 s. co m*/ public static Element[] getChildren(final Element el, final String name) { final Vector v = new Vector(); final NodeList nodes = el.getChildNodes(); final int len = nodes.getLength(); for (int i = 0; i < len; i++) { final Node node = nodes.item(i); if (!(node instanceof Element)) continue; final Element e = (Element) node; if (name == null || e.getTagName().equals(name)) v.add(e); } final Element[] els = new Element[v.size()]; v.copyInto(els); return els; }
From source file:edu.umn.cs.spatialHadoop.nasa.SpatioAggregateQueries.java
/** * Return all matching partitions according to a time range * @param inFile //w ww . j av a2 s . c o m * @param params * @return * @throws ParseException * @throws IOException */ private static Vector<Path> selectTemporalPartitions(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>(); System.out.println(new TimeRange(params.get("time"))); 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) { 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(); return matchingPartitions; }
From source file:com.chinamobile.bcbsp.fault.tools.Zip.java
/** * To get a directory's all files./*from w w w . j a v a 2 s.co m*/ * @param sourceFile * : the source directory * @return the files' collection */ private static Vector<File> getAllFiles(File sourceFile) { Vector<File> fileVector = new Vector<File>(); if (sourceFile.isDirectory()) { File[] files = sourceFile.listFiles(); for (int i = 0; i < files.length; i++) { fileVector.addAll(getAllFiles(files[i])); } } else { fileVector.add(sourceFile); } return fileVector; }
From source file:de.fabianonline.telegram_backup.Utils.java
static Vector<String> getAccounts() { Vector<String> accounts = new Vector<String>(); File folder = new File(Config.FILE_BASE); File[] files = folder.listFiles(); if (files != null) for (File f : files) { if (f.isDirectory() && f.getName().startsWith("+")) { accounts.add(f.getName()); }//ww w.ja v a 2 s .c om } return accounts; }
From source file:net.sf.jabref.exporter.layout.WSITools.java
/** * @param vcr {@link java.util.Vector} of <tt>String</tt> * @param s Description of the Parameter * @param delimstr Description of the Parameter * @param limit Description of the Parameter * @return Description of the Return Value *//* www . j av a2s .c o m*/ public static boolean tokenize(Vector<String> vcr, String s, String delimstr, int limit) { LOGGER.warn("Tokenize \"" + s + '"'); vcr.clear(); s = s + '\n'; int endpos; int matched = 0; StringTokenizer st = new StringTokenizer(s, delimstr); while (st.hasMoreTokens()) { String tmp = st.nextToken(); vcr.add(tmp); matched++; if (matched == limit) { endpos = s.lastIndexOf(tmp); vcr.add(s.substring(endpos + tmp.length())); break; } } return true; }
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;//w ww .j av a 2 s.c o m } 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:helpers.Methods.java
/** * This method will return the links which are in RAM and are not processed * by threads.//from ww w. j a v a 2s. com * * @return The list of un-fetched URLs or null if any error occur. */ public static synchronized Vector<WebDocument> getRemainingProfileLinks() { Vector<WebDocument> temp = new Vector<>(); try { for (; profileCounter < links.size(); profileCounter++) { temp.add(links.get(profileCounter)); } } catch (IndexOutOfBoundsException ex) { return null; } return temp; }
From source file:modnlp.capte.AlignerUtils.java
public static String removeLongWhiteSpace(String s) { s = s.trim();//www. ja v a 2 s. co m while (s.contains(" ")) // two white spaces { s = s.replaceAll(" ", " "); // the first arg should contain 2 spaces, the second only 1 } //System.out.println("Length before UTF8 cleaning " + s.length()); CharsetDecoder utf8Decoder = Charset.forName("UTF-8").newDecoder(); utf8Decoder.onMalformedInput(CodingErrorAction.IGNORE); utf8Decoder.onUnmappableCharacter(CodingErrorAction.IGNORE); try { ByteBuffer bytes; bytes = ByteBuffer.wrap(s.getBytes()); CharBuffer parsed = utf8Decoder.decode(bytes); s = parsed.toString(); } catch (Exception e) { e.printStackTrace(); } //This code removes all of the bytes with value of zero // Gerard 21st March 2012: Solved, bug with random spaces in segments byte[] b = s.getBytes(); Vector<Byte> vb = new Vector(); for (int i = 0; i < b.length; i++) { if (b[i] != 0) { vb.add(b[i]); } } Object[] ba = vb.toArray(); Byte[] bya = new Byte[ba.length]; byte[] byta = new byte[ba.length]; for (int i = 0; i < ba.length; i++) { bya[i] = (Byte) ba[i]; byta[i] = bya[i].byteValue(); } s = new String(byta); return s; }
From source file:nz.net.catalyst.MaharaDroid.upload.http.RestClient.java
public static JSONObject AuthSync(String url, String token, String username, Long lastsync, String notifications, Context context) { Vector<String> pNames = new Vector<String>(); Vector<String> pVals = new Vector<String>(); if (token != null) { pNames.add("token"); pVals.add(token);//from w ww. ja v a 2 s.c o m } if (username != null) { pNames.add("username"); pVals.add(username); } if (lastsync != null) { pNames.add("lastsync"); pVals.add(lastsync.toString()); } if (lastsync != null) { pNames.add("lastsync"); pVals.add(lastsync.toString()); } if (notifications != null) { pNames.add("notifications"); pVals.add(notifications); } String[] paramNames, paramVals; paramNames = paramVals = new String[] {}; paramNames = pNames.toArray(paramNames); paramVals = pVals.toArray(paramVals); return CallFunction(url, paramNames, paramVals, context); }
From source file:de.alpharogroup.collections.ListExtensions.java
/** * Converts the given enumaration to a Vector. * * @param <T>//from ww w . j av a2 s . c o m * the generic type * @param enumaration * The Enumeration to convert. * * @return A new Vector with the content of the given Enumeration. */ public static <T> Vector<T> toVector(final Enumeration<T> enumaration) { final Vector<T> vector = new Vector<T>(); while (enumaration.hasMoreElements()) { vector.add(enumaration.nextElement()); } return vector; }