List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:com.phonemetra.account.util.AccountUtils.java
public static String getUniqueDeviceId(Context context) { SharedPreferences prefs = context.getSharedPreferences(Account.SETTINGS_PREFERENCES, Context.MODE_PRIVATE); String udid = prefs.getString(KEY_UDID, null); if (udid != null) return udid; String wifiInterface = SystemProperties.get("wifi.interface"); if (wifiInterface != null) { try {//from w ww . jav a 2s . c o m List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface networkInterface : interfaces) { if (wifiInterface.equals(networkInterface.getDisplayName())) { byte[] mac = networkInterface.getHardwareAddress(); if (mac != null) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < mac.length; i++) buf.append(String.format("%02X:", mac[i])); if (buf.length() > 0) buf.deleteCharAt(buf.length() - 1); if (Account.DEBUG) Log.d(TAG, "using wifi mac for id : " + buf.toString()); return digest(prefs, context.getPackageName() + buf.toString()); } } } } catch (SocketException e) { Log.e(TAG, "Unable to get wifi mac address", e); } } //If we fail, just use android id. return digest(prefs, context.getPackageName() + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID)); }
From source file:org.apache.james.mailbox.cassandra.mail.CassandraMailboxMapper.java
private String constructEscapedRegexForMailboxNameMatching(MailboxPath path) { return Collections.list(new StringTokenizer(path.getName(), WILDCARD, true)).stream() .map(this::tokenToPatternPart).collect(Collectors.joining()); }
From source file:org.jkcsoft.java.util.JndiHelper.java
public static void logLdap(Log plog, int level, int nth, Object dirEntry) throws NamingException { try {/*from w w w.j ava 2s . co m*/ if (dirEntry instanceof NamingEnumeration) { NamingEnumeration nameEnum = (NamingEnumeration) dirEntry; JndiHelper.logLevel(plog, level, nth, "Naming Enumeration: " + nameEnum); try { int nthThis = 0; List nameList = new Vector(Collections.list(nameEnum)); Collections.sort(nameList, new Comparator() { public int compare(Object o1, Object o2) { if (o1 instanceof Attribute) { return String.CASE_INSENSITIVE_ORDER.compare(((Attribute) o1).getID(), ((Attribute) o2).getID()); } return 0; } }); Iterator nameIter = nameList.iterator(); while (nameIter.hasNext()) { logLdap(plog, level + 1, nthThis++, nameIter.next()); } } catch (NamingException ex) { plog.error("Exception iterating thru NamingEnumeration: " + ex.getMessage()); } } else if (dirEntry instanceof Attribute) { Attribute dirAttr = (Attribute) dirEntry; JndiHelper.logLevel(plog, level, nth, "Attribute: [" + dirAttr + "]"); } else if (dirEntry instanceof DirContext) { DirContext lctx = (DirContext) dirEntry; JndiHelper.logLevel(plog, level, nth, "LDAP Context: DN [" + lctx.getNameInNamespace() + "]" + " Attributes ==>"); logLdap(plog, level, nth, lctx.getAttributes("").getAll()); } else if (dirEntry instanceof SearchResult) { SearchResult sr = (SearchResult) dirEntry; JndiHelper.logLevel(plog, level, nth, "SearchResult: ClassName of Bound Object [" + sr.getClassName() + "]" + " Name: [" + sr.getName() + "]" + " Bound Object ==>"); // sr.s logLdap(plog, level, nth, sr.getObject()); logLdap(plog, level, nth, sr.getAttributes().getAll()); } else { JndiHelper.logLevel(plog, level, nth, "(?) class of entry: [" + dirEntry + "]"); } nth++; } catch (NamingException e1) { plog.error("Naming Exception (will try to continue): " + e1.getMessage()); } }
From source file:org.sonar.classloader.ClassloaderBuilderTest.java
/** * - parent contains B and version 1 of A * - child contains version 2 of A -> sees B and version 2 of A *//*from w ww . ja v a 2 s. c o m*/ @Test public void self_first_ordering() throws Exception { Map<String, ClassLoader> newClassloaders = sut.newClassloader("the-parent") .addURL("the-parent", new File("tester/a.jar").toURL()) .addURL("the-parent", new File("tester/b.jar").toURL()) .newClassloader("the-child").addURL("the-child", new File("tester/a_v2.jar").toURL()) .setParent("the-child", "the-parent", Mask.ALL) .setLoadingOrder("the-child", ClassloaderBuilder.LoadingOrder.SELF_FIRST).build(); ClassLoader parent = newClassloaders.get("the-parent"); assertThat(canLoadMethod(parent, "A", "version1")).isTrue(); assertThat(canLoadMethod(parent, "A", "version2")).isFalse(); assertThat(IOUtils.toString(parent.getResource("a.txt"))).startsWith("version 1 of a.txt"); ClassLoader child = newClassloaders.get("the-child"); assertThat(canLoadClass(child, "B")).isTrue(); assertThat(canLoadMethod(child, "A", "version1")).isFalse(); assertThat(canLoadMethod(child, "A", "version2")).isTrue(); assertThat(IOUtils.toString(child.getResource("a.txt"))).startsWith("version 2 of a.txt"); assertThat(Collections.list(child.getResources("b.txt"))).hasSize(1); ArrayList<URL> resources = Collections.list(child.getResources("a.txt")); assertThat(resources).hasSize(2); assertThat(IOUtils.toString(resources.get(0))).startsWith("version 2 of a.txt"); assertThat(IOUtils.toString(resources.get(1))).startsWith("version 1 of a.txt"); }
From source file:org.apache.solr.response.transform.TestSubQueryTransformer.java
@Test public void testRowsStartForSubqueryAndScores() throws Exception { String johnDeptsIds = h/*from w w w . j av a2 s .co m*/ .query(req(new String[] { "q", "{!join from=dept_ss_dv to=dept_id_s}name_s:john", "wt", "csv", "csv.header", "false", "fl", "id", "rows", "" + deptMultiplier, "sort", "id_i desc" })); ArrayList<Object> deptIds = Collections.list(new StringTokenizer(johnDeptsIds)); final int a = random().nextInt(deptMultiplier + 1); final int b = random().nextInt(deptMultiplier + 1); final int start = Math.min(a, b); final int toIndex = Math.max(a, b); List<Object> expectIds = deptIds.subList(start, toIndex); ArrayList<String> assertions = new ArrayList<>(); // count((//result/doc/str[@name='name_s_dv'][.='john']/../result[@name='depts'])[1]/doc/str[@name='id']) // random().nextInt(peopleMultiplier); assertions.add("count((//result/doc/str[@name='name_s_dv'][.='john']/.." + "/result[@name='depts'][@numFound='" + deptMultiplier + "'][@start='" + start + "'])[" + (random().nextInt(peopleMultiplier) + 1) + "]/doc/str[@name='id'])=" + (toIndex - start)); // System.out.println(expectIds); for (int i = 0; i < expectIds.size(); i++) { // (//result/doc/str[@name='name_s_dv'][.='john']/../result[@name='depts'])[1]/doc[1]/str[@name='id']='15' String ithDoc = "(//result/doc/str[@name='name_s_dv'][.='john']/.." + "/result[@name='depts'][@numFound='" + deptMultiplier + "'][@start='" + start + "'])[" + (random().nextInt(peopleMultiplier) + 1) + "]/doc[" + (i + 1) + "]"; assertions.add(ithDoc + "/str[@name='id'][.='" + expectIds.get(i) + "']"); // let's test scores right there assertions.add(ithDoc + "/float[@name='score'][.='" + expectIds.get(i) + ".0']"); } String[] john = new String[] { "q", "name_s:john", "indent", "true", "fl", "dept_ss_dv,name_s_dv,depts:[subquery]", "rows", "" + (2 * peopleMultiplier), "depts.q", "+{!term f=dept_id_s v=$row.dept_ss_dv}^=0 _val_:id_i", "depts.fl", "id", "depts.fl", "score", "depts.indent", "true", "depts.rows", "" + (toIndex - start), "depts.start", "" + start }; assertQ(req(john), assertions.toArray(new String[] {})); }
From source file:org.apache.storm.utils.ServerUtils.java
/** * Determines if a zip archive contains a particular directory. * * @param zipfile path to the zipped file * @param target directory being looked for in the zip. * @return boolean whether or not the directory exists in the zip. *//* w w w .j a v a 2 s .c o m*/ public static boolean zipDoesContainDir(String zipfile, String target) throws IOException { List<ZipEntry> entries = (List<ZipEntry>) Collections.list(new ZipFile(zipfile).entries()); String targetDir = target + "/"; for (ZipEntry entry : entries) { String name = entry.getName(); if (name.startsWith(targetDir)) { return true; } } return false; }
From source file:io.personium.engine.rs.AbstractService.java
/** * Service./*from www.jav a 2 s .c om*/ * @param cell Cell?? * @param schema URI * @param svcName ??? * @param req Request * @param res Response * @param is * @return Response */ public final Response run(final String cell, final String schema, final String svcName, final HttpServletRequest req, final HttpServletResponse res, final InputStream is) { StringBuilder msg = new StringBuilder(); msg.append("[" + PersoniumEngineConfig.getVersion() + "] " + ">>> Request Started "); msg.append(" method:"); msg.append(req.getMethod()); msg.append(" method:"); msg.append(req.getRequestURL()); msg.append(" url:"); msg.append(cell); msg.append(" schema:"); msg.append(schema); msg.append(" svcName:"); msg.append(svcName); log.info(msg); // ? ???? Enumeration<String> multiheaders = req.getHeaderNames(); for (String headerName : Collections.list(multiheaders)) { Enumeration<String> headers = req.getHeaders(headerName); for (String header : Collections.list(headers)) { log.debug("RequestHeader['" + headerName + "'] = " + header); } } this.setServiceName(svcName); // ?URL?? String targetCell = cell; if (cell == null) { targetCell = getCell(); } String targetSchema = schema; if (schema == null) { targetSchema = getSchemaURI(); } String targetServiceName = svcName; String baseUrl; try { baseUrl = parseRequestUri(req, res); } catch (MalformedURLException e) { // URL??????? return makeErrorResponse("Server Error", PersoniumEngineException.STATUSCODE_SERVER_ERROR); } Response response = null; PersoniumEngineContext pecx = null; try { try { pecx = new PersoniumEngineContext(); } catch (PersoniumEngineException e) { return errorResponse(e); } // ??? try { this.sourceManager = this.getServiceCollectionManager(); pecx.setSourceManager(this.sourceManager); this.serviceSubject = this.sourceManager.getServiceSubject(); } catch (PersoniumEngineException e) { return errorResponse(e); } // ?? pecx.loadGlobalObject(baseUrl, targetCell, targetSchema, targetSchema, targetServiceName); // ??? String source = ""; try { String sourceName = this.sourceManager.getScriptNameForServicePath(targetServiceName); source = this.sourceManager.getSource(sourceName); } catch (PersoniumEngineException e) { return errorResponse(e); } catch (Exception e) { log.info("User Script not found to targetCell(" + targetCell + ", targetschema(" + targetSchema + "), targetServiceName(" + targetServiceName + ")"); log.info(e.getMessage(), e); return errorResponse(new PersoniumEngineException("404 Not Found (User Script)", PersoniumEngineException.STATUSCODE_NOTFOUND)); } // JSGI try { response = pecx.runJsgi(source, req, res, is, this.serviceSubject); } catch (PersoniumEngineException e) { return errorResponse(e); } catch (Exception e) { log.warn(" unknown Exception(" + e.getMessage() + ")"); return errorResponse(new PersoniumEngineException("404 Not Found (Service Execute Error)", PersoniumEngineException.STATUSCODE_NOTFOUND)); } } finally { IOUtils.closeQuietly(pecx); } return response; }
From source file:com.facebook.buck.util.unarchive.Unzip.java
/** * Get a listing of all files in a zip file * * @param zip The zip file to scan/*from ww w . j av a 2 s . c o m*/ * @param relativePath The relative path where the extraction will be rooted * @return The list of paths in {@code zip} sorted by path so dirs come before contents. */ private static SortedMap<Path, ZipArchiveEntry> getZipFilePaths(ZipFile zip, Path relativePath, PatternsMatcher entriesToExclude) { SortedMap<Path, ZipArchiveEntry> pathMap = new TreeMap<>(); for (ZipArchiveEntry entry : Collections.list(zip.getEntries())) { String entryName = entry.getName(); if (entriesToExclude.matchesAny(entryName)) { continue; } Path target = relativePath.resolve(entryName).normalize(); pathMap.put(target, entry); } return pathMap; }
From source file:cn.com.ebmp.freesql.io.ResolverUtil.java
/** * Scans for classes starting at the package provided and descending into * subpackages. Each class is offered up to the Test as it is discovered, * and if the Test returns true the class is retained. Accumulated classes * can be fetched by calling {@link #getClasses()}. * //from w w w .ja v a 2 s .com * @param test * an instance of {@link Test} that will be used to filter * classes * @param packageName * the name of the package from which to start scanning for * classes, e.g. {@code net.sourceforge.stripes} */ public ResolverUtil<T> find(Test test, String packageName) { String path = getPackagePath(packageName); try { List<URL> urls = Collections.list(getClassLoader().getResources(path)); for (URL url : urls) { List<String> children = listClassResources(url, path); for (String child : children) { addIfMatching(test, child); } } } catch (IOException ioe) { log.error("Could not read package: " + packageName + " -- ", ioe); } return this; }
From source file:com.enioka.jqm.tools.JndiContext.java
@Override public Object lookup(Name name) throws NamingException { return this.lookup(StringUtils.join(Collections.list(name.getAll()), "/")); }