List of usage examples for java.util Vector contains
public boolean contains(Object o)
From source file:Main.java
/** * @param context/*from ww w . j a v 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); }
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;/* w w w . j av a2 s . c o m*/ 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:org.oscarehr.util.MiscUtils.java
License:asdf
public static Vector findUniqueElementVector(Vector v) { Vector retVec = new Vector(); for (int i = 0; i < v.size(); i++) { if (!retVec.contains(v.get(i))) retVec.add(v.get(i));// ww w. jav a2s. c o m } return retVec; }
From source file:StringUtils.java
public static String[] split(String string, char[] separatorChars) { if (string == null || string.equals("")) return new String[] { string }; int len = string.length(); Vector separators = new Vector(separatorChars.length); for (int s = 0; s < separatorChars.length; s++) separators.addElement(new Character(separatorChars[s])); Vector list = new Vector(); int i = 0;//from ww w . ja v a 2 s .c o m int start = 0; boolean match = false; while (i < len) { if (separators.contains(new Character(string.charAt(i)))) { if (match) { list.addElement(string.substring(start, i)); match = false; } start = ++i; continue; } match = true; i++; } if (match) { list.addElement(string.substring(start, i)); } String[] arr = new String[list.size()]; list.copyInto(arr); return arr; }
From source file:org.apache.axis2.xmlbeans.CodeGenerationUtility.java
/** * Converts a given vector of schemaDocuments to XmlBeans processable schema objects. One * drawback we have here is the non-inclusion of untargeted namespaces * * @param vec/*from w ww . j a v a 2 s .c om*/ * @return schema array */ private static SchemaDocument.Schema[] convertToSchemaArray(List vec) { SchemaDocument[] schemaDocuments = (SchemaDocument[]) vec.toArray(new SchemaDocument[vec.size()]); //remove duplicates Vector uniqueSchemas = new Vector(schemaDocuments.length); Vector uniqueSchemaTns = new Vector(schemaDocuments.length); SchemaDocument.Schema s; for (int i = 0; i < schemaDocuments.length; i++) { s = schemaDocuments[i].getSchema(); if (!uniqueSchemaTns.contains(s.getTargetNamespace())) { uniqueSchemas.add(s); uniqueSchemaTns.add(s.getTargetNamespace()); } else if (s.getTargetNamespace() == null) { uniqueSchemas.add(s); } } return (SchemaDocument.Schema[]) uniqueSchemas.toArray(new SchemaDocument.Schema[uniqueSchemas.size()]); }
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 a v a 2 s. co 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:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java
/** * Given a list of locale pairs, remove them from the list of all locale * pairs. Then create a hashtable where the key is the source locale, and * the value is all possible target locales. * //from w w w . j a v a 2 s . c o m */ public static Hashtable getRemainingLocales(List currentLocales) throws EnvoyServletException { Hashtable remaining = new Hashtable(); Vector sourceLocales = UserHandlerHelper.getAllSourceLocales(); for (int i = 0; i < sourceLocales.size(); i++) { GlobalSightLocale curLocale = (GlobalSightLocale) sourceLocales.elementAt(i); Vector validTargets = UserHandlerHelper.getTargetLocales(curLocale); remaining.put(curLocale, validTargets); } // Now that we have a hashtable of all valid source locales and // their target locales, removes the ones that already exist for // this vendor. for (int i = 0; i < currentLocales.size(); i++) { LocalePair pair = (LocalePair) currentLocales.get(i); GlobalSightLocale target = pair.getTarget(); Vector targets = (Vector) remaining.get(pair.getSource()); if (targets != null && targets.contains(target)) { targets.remove(target); if (targets.size() == 0) { // no valid targets left so remove the entry in the hash remaining.remove(pair.getSource()); } } } return remaining; }
From source file:Main.java
/** Returns true if these zip files act like equivalent sets. * The order of the zip entries is not important: if they contain * exactly the same contents, this returns true. * @param zip1 one zip file /* www . java 2 s. c o m*/ * @param zip2 another zip file * @return true if the two zip archives are equivalent sets * @throws IOException */ public static boolean zipEquals(File zip1, File zip2) throws IOException { if (zip1.equals(zip2)) return true; InputStream in = null; ZipInputStream zipIn = null; try { in = new FileInputStream(zip1); zipIn = new ZipInputStream(in); ZipEntry e = zipIn.getNextEntry(); Vector<String> entries = new Vector<String>(); while (e != null) { entries.add(e.getName()); InputStream other = getZipEntry(zip2, e.getName()); if (other == null) { return false; } if (equals(zipIn, other) == false) { return false; } e = zipIn.getNextEntry(); } //now we've established everything in zip1 is in zip2 //but what if zip2 has entries zip1 doesn't? zipIn.close(); in.close(); in = new FileInputStream(zip2); zipIn = new ZipInputStream(in); e = zipIn.getNextEntry(); while (e != null) { if (entries.contains(e.getName()) == false) { return false; } e = zipIn.getNextEntry(); } //the entries are exactly the same return true; } finally { try { zipIn.close(); } catch (Throwable t) { } try { in.close(); } catch (Throwable t) { } } }
From source file:com.opensymphony.xwork2.util.ClassPathFinderTest.java
public void testFinder() { ClassPathFinder finder = new ClassPathFinder(); finder.setPattern("**/xwork-test-wildcard-*.xml"); Vector<String> found = finder.findMatches(); assertEquals(found.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-1.xml"), true); assertEquals(found.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-2.xml"), true); assertEquals(found.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-include.xml"), true);// w ww.ja v a 2 s .c o m assertEquals(found.contains("com/opensymphony/xwork2/config/providers/xwork-test-results.xml"), false); ClassPathFinder finder2 = new ClassPathFinder(); finder2.setPattern("com/*/xwork2/config/providers/xwork-test-wildcard-1.xml"); Vector<String> found2 = finder2.findMatches(); assertEquals(found2.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-1.xml"), true); assertEquals(found2.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-2.xml"), false); ClassPathFinder finder3 = new ClassPathFinder(); finder3.setPattern("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-1.xml"); Vector<String> found3 = finder3.findMatches(); assertEquals(found3.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-1.xml"), true); assertEquals(found3.contains("com/opensymphony/xwork2/config/providers/xwork-test-wildcard-2.xml"), false); ClassPathFinder finder4 = new ClassPathFinder(); finder4.setPattern("no/matches/*"); Vector<String> found4 = finder4.findMatches(); assertEquals(found4.isEmpty(), true); }
From source file:org.parosproxy.paros.core.spider.Collector.java
private boolean isDuplicateInSameHtml(Vector list, HttpMessage msg) { if (list.contains(msg)) { return true; } else {/*www . j a va 2s.c om*/ list.add(msg); } return false; }