List of usage examples for java.util Vector size
public synchronized int size()
From source file:Main.java
public static synchronized Element[] getChildElements(Element element, String childName) { if (element == null || childName == null || childName.length() == 0) { return null; }/*from w ww . jav a2 s . co m*/ Vector childs = new Vector(); for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) { if (node instanceof Element) { childs.add((Element) node); } } Element[] elmt = new Element[childs.size()]; childs.toArray(elmt); return elmt; }
From source file:it.acubelab.smaph.learn.GenerateModel.java
public static String getModelFileNameBaseEF(Integer[] ftrs, double wPos, double wNeg, double editDistance, double gamma, double C) { Vector<Integer> features = new Vector<Integer>(Arrays.asList(ftrs)); Collections.sort(features);// w w w .ja v a2 s . co m String filename = "models/model_"; for (int f : features) filename += f + (f == features.get(features.size() - 1) ? "" : ","); filename += String.format("_%.5f_%.5f_%.3f_%.8f_%.8f", wPos, wNeg, editDistance, gamma, C); return filename; }
From source file:it.acubelab.smaph.learn.GenerateModel.java
public static String getModelFileNameBaseEQF(Integer[] ftrs, double wPos, double wNeg) { Vector<Integer> features = new Vector<Integer>(Arrays.asList(ftrs)); Collections.sort(features);//from w ww. java2s. c o m String filename = "models/EQ_model_"; for (int f : features) filename += f + (f == features.get(features.size() - 1) ? "" : ","); filename += String.format("_%.5f_%.5f", wPos, wNeg); return filename; }
From source file:FileUtil.java
public static boolean hasDuplicates(Vector v) { int i = 0;/*w w w . java 2 s . co m*/ int j = 0; boolean duplicates = false; for (i = 0; i < v.size() - 1; i++) { for (j = (i + 1); j < v.size(); j++) { if (v.elementAt(i).toString().equalsIgnoreCase(v.elementAt(j).toString())) { duplicates = true; } } } return duplicates; }
From source file:eu.amidst.core.utils.Utils.java
/** * Returns the sumNonStateless of the elements in a given vector. * @param vector a {@link Vector} object. * @return a {@code double} that represents the sumNonStateless of the vector elements. *//*w w w.ja v a 2 s . c om*/ public static double sum(Vector vector) { double sum = 0; for (int i = 0; i < vector.size(); i++) { sum += vector.get(i); } return sum; }
From source file:Main.java
/** * Returns an array containing the element objects in the provided node list. * //from w w w . j av a 2 s. com * @param nodeList The DOM node objects to extract elements from. * @return The array of DOM elements found in the node list. */ @SuppressWarnings("unchecked") public static Element[] getElementsOfNodeList(NodeList nodeList) { Element[] ret = null; @SuppressWarnings("rawtypes") Vector v = new Vector(); for (int n = 0; n < nodeList.getLength(); n++) { Node item = nodeList.item(n); if (item.getNodeType() == Node.ELEMENT_NODE) { v.addElement(item); } } ret = new Element[v.size()]; for (int n = 0; n < ret.length; n++) { ret[n] = (Element) v.elementAt(n); } return ret; }
From source file:com.ricemap.spateDB.mapred.FileSplitUtil.java
/** * Combines a number of input splits into the given numSplits. * @param conf/*from w w w . j av a 2 s . c o m*/ * @param inputSplits * @param numSplits * @return * @throws IOException */ public static InputSplit[] autoCombineSplits(JobConf conf, Vector<FileSplit> inputSplits, int numSplits) throws IOException { LOG.info("Combining " + inputSplits.size() + " splits into " + numSplits); Map<String, Vector<FileSplit>> blocksPerHost = new HashMap<String, Vector<FileSplit>>(); for (FileSplit fsplit : inputSplits) { // Get locations for this split final Path path = fsplit.getPath(); final FileSystem fs = path.getFileSystem(conf); BlockLocation[] blockLocations = fs.getFileBlockLocations(fs.getFileStatus(path), fsplit.getStart(), fsplit.getLength()); for (BlockLocation blockLocation : blockLocations) { for (String hostName : blockLocation.getHosts()) { if (!blocksPerHost.containsKey(hostName)) blocksPerHost.put(hostName, new Vector<FileSplit>()); blocksPerHost.get(hostName).add(fsplit); } } } // If the user requested a fewer number of splits, start to combine them InputSplit[] combined_splits = new InputSplit[numSplits]; int splitsAvailable = inputSplits.size(); for (int i = 0; i < numSplits; i++) { // Decide how many splits to combine int numSplitsToCombine = splitsAvailable / (numSplits - i); Vector<FileSplit> splitsToCombine = new Vector<FileSplit>(); while (numSplitsToCombine > 0) { // Choose the host with minimum number of splits Map.Entry<String, Vector<FileSplit>> minEntry = null; for (Map.Entry<String, Vector<FileSplit>> entry : blocksPerHost.entrySet()) { if (minEntry == null || entry.getValue().size() < minEntry.getValue().size()) { minEntry = entry; } } // Combine all or some of blocks in this host for (FileSplit fsplit : minEntry.getValue()) { if (!splitsToCombine.contains(fsplit)) { splitsToCombine.add(fsplit); if (--numSplitsToCombine == 0) break; } } if (numSplitsToCombine != 0) { // Remove this host so that it is not selected again blocksPerHost.remove(minEntry.getKey()); } } combined_splits[i] = combineFileSplits(conf, splitsToCombine, 0, splitsToCombine.size()); for (Map.Entry<String, Vector<FileSplit>> entry : blocksPerHost.entrySet()) { entry.getValue().removeAll(splitsToCombine); } splitsAvailable -= splitsToCombine.size(); } LOG.info("Combined splits " + combined_splits.length); return combined_splits; }
From source file:Main.java
static public Element[] findChildElements(Node first, Node last, String name) { Vector v = new Vector(); while (first != last) { if (first.getNodeType() == Node.ELEMENT_NODE) { if (first.getNodeName().equals(name)) v.addElement(first);/* w w w. j a va2 s . c o m*/ } first = first.getNextSibling(); } Element array[] = new Element[v.size()]; for (int i = 0; i < array.length; ++i) { array[i] = (Element) v.elementAt(i); } return array; }
From source file:Main.java
public static Vector<Integer> mergeSet(Vector<Integer> leftSet, Vector<Integer> rightSet, String mergeType) { if (leftSet == null || rightSet == null) return null; if (mergeType.trim().compareToIgnoreCase("or") == 0) { // OR set Vector<Integer> orSet = new Vector<Integer>(); orSet = leftSet;//from w w w.j a va 2 s. com for (int i = 0; i < rightSet.size(); i++) { if (orSet.contains(rightSet.get(i)) == false) orSet.add(rightSet.get(i)); } return orSet; } else if (mergeType.trim().compareToIgnoreCase("and") == 0) { // AND // set Vector<Integer> andSet = new Vector<Integer>(); if (leftSet.size() > rightSet.size()) { for (int i = 0; i < rightSet.size(); i++) { if (leftSet.contains(rightSet.get(i)) == true) andSet.add(rightSet.get(i)); } } else { for (int i = 0; i < leftSet.size(); i++) { if (rightSet.contains(leftSet.get(i)) == true) andSet.add(leftSet.get(i)); } } return andSet; } else if (mergeType.trim().compareToIgnoreCase("xor") == 0) { // XoR // set // Left is Universal Set and right Set is getting Exclusive XoR Vector<Integer> xorSet = new Vector<Integer>(); for (int i = 0; i < leftSet.size(); i++) { if (rightSet.contains(leftSet.get(i)) == false) xorSet.add(leftSet.get(i)); } return xorSet; } return leftSet; }
From source file:Main.java
/** * @param context/*from www .j av a 2 s . c o m*/ * this method is used for retrieving email accounts of device * @return */ public static String[] getAccount(Context context) { final AccountManager accountManager = AccountManager.get(context); final Account[] accounts = accountManager.getAccounts(); final Vector<String> accountVector = new Vector<String>(); for (int i = 0; i < accounts.length; i++) { if (!accountVector.contains(accounts[i].name) && isValidEmail(accounts[i].name)) { accountVector.addElement(accounts[i].name); } } final String accountArray[] = new String[accountVector.size()]; return accountVector.toArray(accountArray); }