List of usage examples for java.util LinkedList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:de.metanome.backend.algorithm_loading.AlgorithmFinder.java
/** * @param algorithmSubclass Class of algorithms to retrieve, or null if all subclasses * @return an array with the names of the available algorithms * @throws java.io.IOException if the algorithm folder could not be opened * @throws java.lang.ClassNotFoundException if an algorithm contains a not supported algorithm subclass */// www .j a v a 2s. c o m public String[] getAvailableAlgorithmFileNames(Class<?> algorithmSubclass) throws IOException, ClassNotFoundException { LinkedList<String> availableAlgorithms = new LinkedList<>(); String pathToFolder = ""; try { pathToFolder = Thread.currentThread().getContextClassLoader().getResource("algorithms").getPath(); } catch (NullPointerException e) { // The algorithm folder does not exist return new String[] {}; } File[] jarFiles = retrieveJarFiles(pathToFolder); for (File jarFile : jarFiles) { if (algorithmSubclass == null || getAlgorithmInterfaces(jarFile).contains(algorithmSubclass)) { availableAlgorithms.add(jarFile.getName()); } } String[] stringArray = new String[availableAlgorithms.size()]; return availableAlgorithms.toArray(stringArray); }
From source file:org.kalypso.jts.JTSUtilities.java
/** * This function calculates the distance from the start point to a point, lying on the line. * //w w w . jav a 2s . co m * @param line * The line. * @param point * One point lying on the line. * @return The distance of the point on the line. * @deprecated This method is too slow for long chains. Use {@link com.vividsolutions.jts.linearref.LengthIndexedLine} instead. And does not work for last line segment!!!! */ @Deprecated public static double pointDistanceOnLine(final LineString line, final Point point) { /* Check for intersection. */ if (point.distance(line) >= TOLERANCE) throw new IllegalStateException("The point does not lie on the line..."); if (line.getEndPoint().equals(point)) return line.getLength(); /* The needed factory. */ final GeometryFactory factory = new GeometryFactory(line.getPrecisionModel(), line.getSRID()); /* Get all coordinates. */ final Coordinate[] coordinates = line.getCoordinates(); /* Only loop until the one before the last one. */ for (int i = 0; i < coordinates.length - 2; i++) { /* Get the coordinates to the current one + 1. */ final Coordinate[] coords = ArrayUtils.subarray(coordinates, 0, i + 2); /* Create a new line with the coordinates. */ final LineString ls = factory.createLineString(coords); if (point.distance(ls) >= TOLERANCE) continue; /* Point was intersecting the last segment, now take all coordinates but the last one ... */ final LinkedList<Coordinate> lineCoords = new LinkedList<>(); for (int j = 0; j < coords.length - 1; j++) lineCoords.add(coords[j]); /* ... and add the point as last one. */ lineCoords.add(point.getCoordinate()); /* Create the new geometry. */ final LineString tempLine = factory.createLineString(lineCoords.toArray(new Coordinate[] {})); return tempLine.getLength(); } throw new IllegalStateException(); }
From source file:org.rascalmpl.library.cobra.RandomValueTypeVisitor.java
@Override public IValue visitConstructor(Type type) { /*//from w w w . j a v a 2 s . c o m * Following the common definition of depth of tree, the depth of an * algebraic datatype with zero arguments is 0 and the depth of an * alternative with more than 0 arguments is defined as the maximum * depth of the list of arguments plus 1. */ if (type.getArity() == 0) { // Diepte 0 dus we mogen altijd opleveren. return vf.constructor(type); } else if (this.maxDepth <= 0) { return null; } RandomValueTypeVisitor visitor = descend(); LinkedList<IValue> values = new LinkedList<IValue>(); for (int i = 0; i < type.getArity(); i++) { Type fieldType = type.getFieldType(i); IValue argument = visitor.generate(fieldType); if (argument == null) { return null; /* * Het is onmogelijk om de constructor te bouwen als n * argument null is. */ } values.add(argument); } return vf.constructor(type, values.toArray(new IValue[values.size()])); }
From source file:org.richfaces.util.RenderPhaseComponentVisitorUtils.java
private static RenderPhaseComponentVisitor[] init() { LinkedList<RenderPhaseComponentVisitor> list = new LinkedList<RenderPhaseComponentVisitor>(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); String resource = "META-INF/services/org.richfaces.component.RenderPhaseComponentVisitor"; try {/* w ww . j av a2 s . co m*/ Enumeration<URL> resources = loader.getResources(resource); while (resources.hasMoreElements()) { InputStream stream = URLToStreamHelper.urlToStreamSafe(resources.nextElement()); BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); try { String handlerClassName = null; while ((handlerClassName = reader.readLine()) != null) { if (handlerClassName.length() > 0) { try { Class<?> handlerClass = ServicesUtils.loadClass(loader, handlerClassName); Object handler = handlerClass.newInstance(); list.add((RenderPhaseComponentVisitor) handler); } catch (Exception e) { throw new FacesException("Error create instance for class " + handlerClassName, e); } } } } finally { try { reader.close(); } catch (IOException e) { if (log.isDebugEnabled()) { log.debug(e.getLocalizedMessage(), e); } } } } } catch (IOException e) { throw new FacesException("Error load resource " + resource, e); } return list.toArray(new RenderPhaseComponentVisitor[list.size()]); }
From source file:de.vanita5.twittnuker.util.net.ssl.AbstractCheckSignatureVerifier.java
public static String[] getCNs(final X509Certificate cert) { final LinkedList<String> cnList = new LinkedList<String>(); /*//from w w w. ja v a 2s.com * Sebastian Hauer's original StrictSSLProtocolSocketFactory used * getName() and had the following comment: * * Parses a X.500 distinguished name for the value of the "Common Name" * field. This is done a bit sloppy right now and should probably be * done a bit more according to <code>RFC 2253</code>. * * I've noticed that toString() seems to do a better job than getName() * on these X500Principal objects, so I'm hoping that addresses * Sebastian's concern. * * For example, getName() gives me this: * 1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d * * whereas toString() gives me this: EMAILADDRESS=juliusdavies@cucbc.com * * Looks like toString() even works with non-ascii domain names! I * tested it with "花子.co.jp" and it worked fine. */ final String subjectPrincipal = cert.getSubjectX500Principal().toString(); final StringTokenizer st = new StringTokenizer(subjectPrincipal, ",+"); while (st.hasMoreTokens()) { final String tok = st.nextToken().trim(); if (tok.length() > 3) { if (tok.substring(0, 3).equalsIgnoreCase("CN=")) { cnList.add(tok.substring(3)); } } } if (!cnList.isEmpty()) { final String[] cns = new String[cnList.size()]; cnList.toArray(cns); return cns; } else return null; }
From source file:com.agimatec.validation.jsr303.ConstraintDefaults.java
private Map<String, Class[]> loadDefaultConstraints(String resource) { Properties constraintProperties = new Properties(); final ClassLoader classloader = getClassLoader(); InputStream stream = classloader.getResourceAsStream(resource); if (stream != null) { try {/*from ww w.j a va2 s . c o m*/ constraintProperties.load(stream); } catch (IOException e) { log.error("cannot load " + resource, e); } } else { log.warn("cannot find " + resource); } Map<String, Class[]> loadedConstraints = new HashMap(); for (Map.Entry entry : constraintProperties.entrySet()) { StringTokenizer tokens = new StringTokenizer((String) entry.getValue(), ", "); LinkedList classes = new LinkedList(); while (tokens.hasMoreTokens()) { final String eachClassName = tokens.nextToken(); Class constraintValidatorClass = SecureActions.run(new PrivilegedAction<Class>() { public Class run() { try { return Class.forName(eachClassName, true, classloader); } catch (ClassNotFoundException e) { log.error("Cannot find class " + eachClassName, e); return null; } } }); if (constraintValidatorClass != null) classes.add(constraintValidatorClass); } loadedConstraints.put((String) entry.getKey(), (Class[]) classes.toArray(new Class[classes.size()])); } return loadedConstraints; }
From source file:vn.chodientu.component.imboclient.ImboClient.java
/** * Parse server host URLs and prepare them for usage * * @param hosts URLs for the Imbo server * @return Array of URLs/*from ww w. j ava 2 s.c om*/ */ private String[] parseUrls(String[] hosts) { LinkedList<String> urls = new LinkedList<String>(); for (String host : hosts) { host = normalizeUrl(host); if (host != null && !urls.contains(host)) { urls.add(host); } } return urls.toArray(new String[urls.size()]); }
From source file:edu.umass.cs.msocket.gns.GnsSocketAddress.java
/** * Get all IP address/port number for the given service belonging to the guid. * //from w w w . j ava 2 s . com * @param guid guid to lookup * @param serviceName service to access * @return array of InetSocketAddres or null if no address was found * @throws Exception if a GNS error occurs */ public GnsSocketAddress[] getAllByGuid(String guid, String serviceName) throws Exception { JSONArray addresses = gnsClient.fieldRead(guid, serviceName, myGuid); if (addresses.length() == 0) return null; LinkedList<GnsSocketAddress> addrList = new LinkedList<GnsSocketAddress>(); for (int i = 0; i < addresses.length(); i++) { GnsSocketAddress sock = new GnsSocketAddress(gnsClient, myGuid); String ipPort = addresses.getString(i); if (ipPort.startsWith("P")) { sock.setProxy(true); ipPort = ipPort.substring(1); } else sock.setProxy(false); int colon = ipPort.indexOf(':'); if (colon == -1) throw new Exception("Invalid IP:Port value " + ipPort + " for service " + serviceName); sock.setIp(ipPort.substring(0, colon)); sock.setPort(Integer.valueOf(ipPort.substring(colon + 1))); addrList.add(sock); } return addrList.toArray(new GnsSocketAddress[addrList.size()]); }
From source file:com.epam.reportportal.apache.http.conn.ssl.AbstractVerifier.java
public static String[] getCNs(final X509Certificate cert) { final LinkedList<String> cnList = new LinkedList<String>(); /*/*from ww w . j a v a2 s .c o m*/ Sebastian Hauer's original StrictSSLProtocolSocketFactory used getName() and had the following comment: Parses a X.500 distinguished name for the value of the "Common Name" field. This is done a bit sloppy right now and should probably be done a bit more according to <code>RFC 2253</code>. I've noticed that toString() seems to do a better job than getName() on these X500Principal objects, so I'm hoping that addresses Sebastian's concern. For example, getName() gives me this: 1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d whereas toString() gives me this: EMAILADDRESS=juliusdavies@cucbc.com Looks like toString() even works with non-ascii domain names! I tested it with "花子.co.jp" and it worked fine. */ final String subjectPrincipal = cert.getSubjectX500Principal().toString(); final StringTokenizer st = new StringTokenizer(subjectPrincipal, ",+"); while (st.hasMoreTokens()) { final String tok = st.nextToken().trim(); if (tok.length() > 3) { if (tok.substring(0, 3).equalsIgnoreCase("CN=")) { cnList.add(tok.substring(3)); } } } if (!cnList.isEmpty()) { final String[] cns = new String[cnList.size()]; cnList.toArray(cns); return cns; } else { return null; } }
From source file:com.addthis.hydra.data.filter.value.ValueFilterHttpGet.java
@Override public void postDecode() { if (persist) { persistTo = LessFiles.initDirectory(persistDir); LinkedList<CacheObject> list = new LinkedList<>(); for (File file : persistTo.listFiles()) { if (file.isFile()) { try { CacheObject cached = codec.decode(CacheObject.class, LessFiles.read(file)); cached.hash = file.getName(); list.add(cached);/*from w w w . j a va2 s .com*/ if (log.isDebugEnabled()) { log.debug("restored " + cached.hash + " as " + cached.key); } } catch (Exception e) { e.printStackTrace(); } } } // sort so that hot map has the most recent inserted last CacheObject[] sort = new CacheObject[list.size()]; list.toArray(sort); Arrays.sort(sort); for (CacheObject cached : sort) { if (log.isDebugEnabled()) { log.debug("insert into hot " + cached.hash + " as " + cached.key); } cache.put(cached.key, cached); } } }