List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:com.ikon.module.jcr.stuff.JCRUtils.java
/** * Convert a Value array to String array and add a user id. *//*w ww . j av a 2s . c o m*/ public static String[] usrValue2String(Value[] values, String usrId) throws ValueFormatException, IllegalStateException, javax.jcr.RepositoryException { ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < values.length; i++) { // Admin and System user is not propagated across the child nodes if (!values[i].getString().equals(Config.SYSTEM_USER) && !values[i].getString().equals(Config.ADMIN_USER)) { list.add(values[i].getString()); } } if (Config.USER_ASSIGN_DOCUMENT_CREATION) { // No add an user twice if (!list.contains(usrId)) { list.add(usrId); } } return (String[]) list.toArray(new String[list.size()]); }
From source file:gdt.data.entity.facet.ExtensionHandler.java
public static void addExtensionLibraries(Entigrator entigrator, String extension$) { try {/*from ww w .ja va 2 s .c om*/ System.out.println("ExtensionHandler:addExtensionLibraries:extension=" + extension$); Object obj = null; Sack extension = entigrator.getEntityAtKey(extension$); String lib$ = extension.getElementItemAt("field", "lib"); String jar$ = "jar:file:" + entigrator.getEntihome() + "/" + extension$ + "/" + lib$ + "!/"; ArrayList<URL> urll = new ArrayList<URL>(); urll.add(new URL(jar$)); //URL[] urls = { new URL(jar$) }; String[] sa = extension.elementListNoSorted("classpath"); if (sa != null) { File file; for (String s : sa) { file = new File(entigrator.getEntihome() + "/" + extension$ + "/" + s); if (file.exists()) urll.add(new URL("jar:file:" + file.getPath() + "!/")); } } URL[] urls = urll.toArray(new URL[0]); URLClassLoader urlClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); ExtensionClassLoader extensionLoader = new ExtensionClassLoader(urlClassLoader); for (URL url : urls) extensionLoader.addURL(url); Thread.currentThread().setContextClassLoader(extensionLoader); //URLClassLoader cl = URLClassLoader.newInstance(urls); } catch (Exception e) { Logger.getLogger(ExtensionHandler.class.getName()).severe(e.toString()); } }
From source file:Main.java
/** * Get all device ip addresses/*from ww w.j av a2s . c o m*/ * @return {@link array} */ public static String[] getLocalIpAddress() { ArrayList<String> addresses = new ArrayList<String>(); try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { //IPAddresses.setText(inetAddress.getHostAddress().toString()); boolean isIPv4 = isIPv4Address(inetAddress.getHostAddress().toString()); if (isIPv4) { addresses.add(inetAddress.getHostAddress().toString()); } } } } } catch (SocketException ex) { String LOG_TAG = null; Log.e(LOG_TAG, ex.toString()); } return addresses.toArray(new String[0]); }
From source file:edu.jhu.cvrg.waveform.utility.WebServiceUtility.java
/** Parses a list node from the service's incoming XML and builds a Map of all its children for easy access. * Used for parameters list and also file handle list. * //w w w .j a v a 2s . com * @param param0 - OMElement representing XML with the incoming parameters. */ public static String[] buildChildArray(OMElement param0) { ArrayList<String> childList = new ArrayList<String>(); try { @SuppressWarnings("unchecked") Iterator<OMElement> iterator = param0.getChildren(); while (iterator.hasNext()) { OMElement param = iterator.next(); childList.add(param.getText()); } } catch (Exception e) { e.printStackTrace(); // errorMessage = "buildParamMap() failed."; return null; } String[] ret = new String[childList.size()]; ret = childList.toArray(ret); return ret; }
From source file:com.clust4j.algo.HierarchicalAgglomerative.java
static Integer[] hcGetDescendents(int node, double[][] children, int leaves) { if (node < leaves) return new Integer[] { node }; final SimpleHeap<Integer> ind = new SimpleHeap<>(node); final ArrayList<Integer> descendent = new ArrayList<>(); int i, n_indices = 1; while (n_indices > 0) { i = ind.popInPlace();//ww w . j a v a 2 s . co m if (i < leaves) { descendent.add(i); n_indices--; } else { final double[] chils = children[i - leaves]; for (double d : chils) ind.add((int) d); n_indices++; } } return descendent.toArray(new Integer[descendent.size()]); }
From source file:edu.umn.cs.spatialHadoop.core.SpatialSite.java
/** * Returns the global index (partitions) of a file that is indexed using * the index command. If the file is not indexed, it returns null. * The return value is of type {@link GlobalIndex} where the generic * parameter is specified as {@link Partition}. * @param fs//from w ww .j a v a2s . c o m * @param dir * @return */ public static GlobalIndex<Partition> getGlobalIndex(FileSystem fs, Path dir) { try { FileStatus[] allFiles; if (OperationsParams.isWildcard(dir)) { allFiles = fs.globStatus(dir); } else { allFiles = fs.listStatus(dir); } FileStatus masterFile = null; int nasaFiles = 0; for (FileStatus fileStatus : allFiles) { if (fileStatus.getPath().getName().startsWith("_master")) { if (masterFile != null) throw new RuntimeException("Found more than one master file in " + dir); masterFile = fileStatus; } else if (fileStatus.getPath().getName().toLowerCase() .matches(".*h\\d\\dv\\d\\d.*\\.(hdf|jpg|xml)")) { // Handle on-the-fly global indexes imposed from file naming of NASA data nasaFiles++; } } if (masterFile != null) { ShapeIterRecordReader reader = new ShapeIterRecordReader(fs.open(masterFile.getPath()), 0, masterFile.getLen()); Rectangle dummy = reader.createKey(); reader.setShape(new Partition()); ShapeIterator values = reader.createValue(); ArrayList<Partition> partitions = new ArrayList<Partition>(); while (reader.next(dummy, values)) { for (Shape value : values) { partitions.add((Partition) value.clone()); } } GlobalIndex<Partition> globalIndex = new GlobalIndex<Partition>(); globalIndex.bulkLoad(partitions.toArray(new Partition[partitions.size()])); String extension = masterFile.getPath().getName(); extension = extension.substring(extension.lastIndexOf('.') + 1); globalIndex.setCompact(GridRecordWriter.PackedIndexes.contains(extension)); globalIndex.setReplicated(GridRecordWriter.ReplicatedIndexes.contains(extension)); return globalIndex; } else if (nasaFiles > allFiles.length / 2) { // A folder that contains HDF files // Create a global index on the fly for these files based on their names Partition[] partitions = new Partition[allFiles.length]; for (int i = 0; i < allFiles.length; i++) { final Pattern cellRegex = Pattern.compile(".*(h\\d\\dv\\d\\d).*"); String filename = allFiles[i].getPath().getName(); Matcher matcher = cellRegex.matcher(filename); Partition partition = new Partition(); partition.filename = filename; if (matcher.matches()) { String cellname = matcher.group(1); int h = Integer.parseInt(cellname.substring(1, 3)); int v = Integer.parseInt(cellname.substring(4, 6)); partition.cellId = v * 36 + h; // Calculate coordinates on MODIS Sinusoidal grid partition.x1 = h * 10 - 180; partition.y2 = (18 - v) * 10 - 90; partition.x2 = partition.x1 + 10; partition.y1 = partition.y2 - 10; // Convert to Latitude Longitude double lon1 = partition.x1 / Math.cos(partition.y1 * Math.PI / 180); double lon2 = partition.x1 / Math.cos(partition.y2 * Math.PI / 180); partition.x1 = Math.min(lon1, lon2); lon1 = partition.x2 / Math.cos(partition.y1 * Math.PI / 180); lon2 = partition.x2 / Math.cos(partition.y2 * Math.PI / 180); partition.x2 = Math.max(lon1, lon2); } else { partition.set(-180, -90, 180, 90); partition.cellId = allFiles.length + i; } partitions[i] = partition; } GlobalIndex<Partition> gindex = new GlobalIndex<Partition>(); gindex.bulkLoad(partitions); return gindex; } else { return null; } } catch (IOException e) { LOG.info("Error retrieving global index of '" + dir + "'"); LOG.info(e); return null; } }
From source file:com.liveneo.plat.utils.StringUtil.java
/** * Splits template name to get identifier, field name and locale * //from w w w .j a v a 2 s .c o m * @param templateName * String in form <code>identifier_field_locale</code> * @return Array containing identifier, field and locale or empty array if * string format is incorrect */ public static String[] splitTemplateName(String templateName) { ArrayList result = new ArrayList(); int k = templateName.lastIndexOf("_"); if (k != -1) { String locale = templateName.substring(k + 1); templateName = templateName.substring(0, k); k = templateName.lastIndexOf("_"); if (k != -1) { String field = templateName.substring(k + 1); templateName = templateName.substring(0, k); result.add(templateName); result.add(field); result.add(locale); } } return (String[]) result.toArray(new String[0]); }
From source file:it.geosolutions.geobatch.figis.intersection.Utilities.java
/** * Reduce a GeometryCollection to a MultiPolygon. This method basically explores * the collection and assembles all the linear rings and polygons into a multipolygon. * The idea there is that contains() works on a multi polygon but not a collection. * If we throw out points and lines, etc, we should still be OK. This is not 100% * correct, but we should still be able to throw away some features which is the point * of all this./*from ww w . j a va 2s .c o m*/ * * @param geometry * @return */ static Geometry reduce(Geometry geometry) { if (geometry instanceof GeometryCollection) { if (geometry instanceof MultiPolygon) { return geometry; } // WKTWriter wktWriter = new WKTWriter(); // logger.warn("REDUCING COLLECTION: " + wktWriter.write(geometry)); final ArrayList<Polygon> polygons = new ArrayList<Polygon>(); final GeometryFactory factory = geometry.getFactory(); geometry.apply(new GeometryComponentFilter() { public void filter(Geometry geom) { if (geom instanceof LinearRing) { polygons.add(factory.createPolygon((LinearRing) geom, null)); } else if (geom instanceof LineString) { // what to do? } else if (geom instanceof Polygon) { polygons.add((Polygon) geom); } } }); MultiPolygon multiPolygon = factory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()])); multiPolygon.normalize(); return multiPolygon; } return geometry; }
From source file:lucee.runtime.tag.VideoPlayerJW.java
private static int[] calculateDimension(PageContext pc, List params, int width, String strWidth, int height, String strHeight) throws PageException { Iterator it = params.iterator(); ArrayList sources = new ArrayList(); //Resource[] sources=new Resource[params.size()]; VideoPlayerParamBean param;// w w w .j ava 2s . co m while (it.hasNext()) { param = (VideoPlayerParamBean) it.next(); if (param.getVideo() != null) sources.add(new VideoInputImpl(param.getVideo())); } return VideoUtilImpl.getInstance().calculateDimension(pc, (VideoInput[]) sources.toArray(new VideoInput[sources.size()]), width, strWidth, height, strHeight); }
From source file:gdt.data.entity.facet.ExtensionHandler.java
/** * Get an array of all facet handlers for all extensions in the database * @param entigrator entigrator instance * @return array of facet handlers.// ww w . j a va 2 s. co m */ public static FacetHandler[] listExtensionHandlers(Entigrator entigrator) { try { String[] sa = entigrator.indx_listEntities("entity", "extension"); if (sa == null) return null; ArrayList<FacetHandler> fl = new ArrayList<FacetHandler>(); FacetHandler[] fha; for (String aSa : sa) { try { fha = listExtensionHandlers(entigrator, aSa); if (fha != null) for (FacetHandler fh : fha) fl.add(fh); } catch (Exception ee) { System.out.println( "ExtesionHandler:listExtensionHandlers:extension=" + aSa + " error:" + ee.toString()); } } return fl.toArray(new FacetHandler[0]); } catch (Exception e) { Logger.getLogger(ExtensionHandler.class.getName()).severe(e.toString()); return null; } }