List of usage examples for java.util Vector add
public synchronized boolean add(E e)
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 /* w w w . ja va 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:Main.java
private static Vector getDataTypes(Connection con) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;//from www . j a v a 2 s .c om else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } return dataTypes; }
From source file:edu.umn.cs.spatialHadoop.nasa.SpatioTemporalAggregateQuery.java
/** * Performs a spatio-temporal aggregate query on an indexed directory * @param inFile//from www . j a v a 2 s . c om * @param params * @throws ParseException * @throws IOException */ public static AggregateQuadTree.Node aggregateQuery(Path inFile, OperationsParams params) throws ParseException, IOException { // 1- Run a temporal filter step to find all matching temporal partitions Vector<Path> matchingPartitions = new Vector<Path>(); // List of time ranges to check. Initially it contains one range as // specified by the user. Eventually, it can be split into at most two // partitions if partially matched by a partition. Vector<TimeRange> temporalRanges = new Vector<TimeRange>(); temporalRanges.add(new TimeRange(params.get("time"))); Path[] temporalIndexes = new Path[] { new Path(inFile, "yearly"), new Path(inFile, "monthly"), new Path(inFile, "daily") }; int index = 0; final FileSystem fs = inFile.getFileSystem(params); while (index < temporalIndexes.length && !temporalRanges.isEmpty()) { Path indexDir = temporalIndexes[index]; LOG.info("Checking index dir " + indexDir); TemporalIndex temporalIndex = new TemporalIndex(fs, indexDir); for (int iRange = 0; iRange < temporalRanges.size(); iRange++) { TimeRange range = temporalRanges.get(iRange); TemporalPartition[] matches = temporalIndex.selectContained(range.start, range.end); if (matches != null) { LOG.info("Matched " + matches.length + " partitions in " + indexDir); for (TemporalPartition match : matches) { LOG.info("Matched temporal partition: " + match.dirName); matchingPartitions.add(new Path(indexDir, match.dirName)); } // Update range to remove matching part TemporalPartition firstMatch = matches[0]; TemporalPartition lastMatch = matches[matches.length - 1]; if (range.start < firstMatch.start && range.end > lastMatch.end) { // Need to split the range into two temporalRanges.setElementAt(new TimeRange(range.start, firstMatch.start), iRange); temporalRanges.insertElementAt(new TimeRange(lastMatch.end, range.end), iRange); } else if (range.start < firstMatch.start) { // Update range in-place range.end = firstMatch.start; } else if (range.end > lastMatch.end) { // Update range in-place range.start = lastMatch.end; } else { // Current range was completely covered. Remove it temporalRanges.remove(iRange); } } } index++; } numOfTemporalPartitionsInLastQuery = matchingPartitions.size(); // 2- Find all matching files (AggregateQuadTrees) in matching partitions final Rectangle spatialRange = params.getShape("rect", new Rectangle()).getMBR(); // Convert spatialRange from lat/lng space to Sinusoidal space double cosPhiRad = Math.cos(spatialRange.y1 * Math.PI / 180); double southWest = spatialRange.x1 * cosPhiRad; double southEast = spatialRange.x2 * cosPhiRad; cosPhiRad = Math.cos(spatialRange.y2 * Math.PI / 180); double northWest = spatialRange.x1 * cosPhiRad; double northEast = spatialRange.x2 * cosPhiRad; spatialRange.x1 = Math.min(northWest, southWest); spatialRange.x2 = Math.max(northEast, southEast); // Convert to the h v space used by MODIS spatialRange.x1 = (spatialRange.x1 + 180.0) / 10.0; spatialRange.x2 = (spatialRange.x2 + 180.0) / 10.0; spatialRange.y2 = (90.0 - spatialRange.y2) / 10.0; spatialRange.y1 = (90.0 - spatialRange.y1) / 10.0; // Vertically flip because the Sinusoidal space increases to the south double tmp = spatialRange.y2; spatialRange.y2 = spatialRange.y1; spatialRange.y1 = tmp; // Find the range of cells in MODIS Sinusoidal grid overlapping the range final int h1 = (int) Math.floor(spatialRange.x1); final int h2 = (int) Math.ceil(spatialRange.x2); final int v1 = (int) Math.floor(spatialRange.y1); final int v2 = (int) Math.ceil(spatialRange.y2); PathFilter rangeFilter = new PathFilter() { @Override public boolean accept(Path p) { Matcher matcher = MODISTileID.matcher(p.getName()); if (!matcher.matches()) return false; int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); return h >= h1 && h < h2 && v >= v1 && v < v2; } }; final Vector<Path> allMatchingFiles = new Vector<Path>(); for (Path matchingPartition : matchingPartitions) { // Select all matching files FileStatus[] matchingFiles = fs.listStatus(matchingPartition, rangeFilter); for (FileStatus matchingFile : matchingFiles) { allMatchingFiles.add(matchingFile.getPath()); } } // 3- Query all matching files in parallel Vector<Node> threadsResults = Parallel.forEach(allMatchingFiles.size(), new RunnableRange<AggregateQuadTree.Node>() { @Override public Node run(int i1, int i2) { Node threadResult = new AggregateQuadTree.Node(); for (int i_file = i1; i_file < i2; i_file++) { try { Path matchingFile = allMatchingFiles.get(i_file); Matcher matcher = MODISTileID.matcher(matchingFile.getName()); matcher.matches(); // It has to match int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); // Clip the query region and normalize in this tile Rectangle translated = spatialRange.translate(-h, -v); int x1 = (int) (Math.max(translated.x1, 0) * 1200); int y1 = (int) (Math.max(translated.y1, 0) * 1200); int x2 = (int) (Math.min(translated.x2, 1.0) * 1200); int y2 = (int) (Math.min(translated.y2, 1.0) * 1200); AggregateQuadTree.Node fileResult = AggregateQuadTree.aggregateQuery(fs, matchingFile, new java.awt.Rectangle(x1, y1, (x2 - x1), (y2 - y1))); threadResult.accumulate(fileResult); } catch (IOException e) { e.printStackTrace(); } } return threadResult; } }); AggregateQuadTree.Node finalResult = new AggregateQuadTree.Node(); for (Node threadResult : threadsResults) finalResult.accumulate(threadResult); numOfTreesTouchesInLastRequest = allMatchingFiles.size(); return finalResult; }
From source file:Main.java
public static NodeList getChildsByTagName(Element root, String name) { final Vector<Node> v = new Vector<Node>(); NodeList nl = root.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i);/* www . ja v a 2s .c o m*/ if (n.getNodeType() == Element.ELEMENT_NODE) { Element e = (Element) n; if (name.equals("*") || e.getNodeName().equalsIgnoreCase(name)) v.add(n); } } return new NodeList() { public Node item(int index) { if (index >= v.size() || index < 0) return null; else return v.get(index); } public int getLength() { return v.size(); } }; }
From source file:Main.java
/** * Get child elements by name, ignoring namespace declarations * * @param ele parent element//from w ww .ja v a 2 s .com * @param name name of elements to find */ public static List<Element> getElementsByName(Element ele, String name) { Vector<Element> list = new Vector(); NodeList nl = ele.getChildNodes(); for (int j = 0; j < nl.getLength(); j++) { if (nl.item(j).getNodeType() != Node.ELEMENT_NODE) continue; Element e = (Element) nl.item(j); String n = e.getNodeName(); if (matches(n, name)) list.add(e); } return (list); }
From source file:com.modeln.build.ctrl.charts.CMnPatchCountChart.java
/** * Create a chart representing the number patches grouped by time interval. * The data passed in the hashtable is a list of the time intervals and * the value is the number of patch requests for each interval. * * @param data Hashtable cnotaining the time intervals and corresponding counts * @param label Count label/*www . j ava 2s.c o m*/ * * @return Bar chart representing the interval and count information */ public static final JFreeChart getPatchesByIntervalChart(Hashtable<CMnTimeInterval, Integer> data, String label) { JFreeChart chart = null; String title = "Patches per " + label; String nameLabel = label; String valueLabel = "Patches"; // Sort the data by date Vector<CMnTimeInterval> intervals = new Vector<CMnTimeInterval>(); Enumeration intervalList = data.keys(); while (intervalList.hasMoreElements()) { intervals.add((CMnTimeInterval) intervalList.nextElement()); } Collections.sort(intervals); // Populate the dataset with data DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Iterator keyIter = intervals.iterator(); while (keyIter.hasNext()) { CMnTimeInterval interval = (CMnTimeInterval) keyIter.next(); Integer value = data.get(interval); dataset.addValue(value, valueLabel, interval.getName()); } // Create the chart chart = ChartFactory.createBarChart(title, /*title*/ nameLabel, /*categoryAxisLabel*/ valueLabel, /*valueAxisLabel*/ dataset, /*dataset*/ PlotOrientation.VERTICAL, /*orientation*/ false, /*legend*/ false, /*tooltips*/ false /*urls*/ ); // get a reference to the plot for further customization... CategoryPlot plot = (CategoryPlot) chart.getPlot(); //chartFormatter.formatMetricChart(plot, "min"); // Set the chart colors plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setShadowVisible(false); final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue); renderer.setSeriesPaint(0, gp); // Set the label orientation CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); return chart; }
From source file:jnode.net.NetworkInterface.java
/** * Return an Enumeration of all available network interfaces * //from ww w.j a va2s. co m * @exception SocketException * If an error occurs */ @SuppressWarnings("unchecked") public static Enumeration getNetworkInterfaces() throws SocketException { log.debug("getNetworkInterfaces"); final Vector list = new Vector(); for (Iterator i = VMNetUtils.getAPI().getNetDevices().iterator(); i.hasNext();) { final VMNetDevice dev = (VMNetDevice) i.next(); log.debug(dev.getId()); list.add(new NetworkInterface(dev)); } return list.elements(); }
From source file:Main.java
/** * Searches parent node for matching child nodes and collects and returns * their values.// ww w .j a v a 2s .c o m * * @param node The parent node * @param elemName The matching child node element name * @return List of node values */ public static Enumeration getChildrenNodeValues(Node node, String elemName) { Vector vect = new Vector(); NodeList nl = node.getChildNodes(); int n = nl.getLength(); for (int i = 0; i < n; i++) { Node nd = nl.item(i); if (nd.getNodeName().equals(elemName)) { Node child = nd.getFirstChild(); if (child == null) { vect.add(""); } else { vect.add(child.getNodeValue()); } } } return vect.elements(); }
From source file:com.fluidops.iwb.deepzoom.DZConvert.java
/** * Write image descriptor XML file//from ww w .ja v a 2 s.com * @param width image width * @param height image height * @param file the file to which it is saved */ private static void saveImageDescriptor(int width, int height, File file) throws IOException { Vector lines = new Vector(); lines.add(xmlHeader); lines.add("<Image TileSize=\"" + tileSize + "\" Overlap=\"" + tileOverlap + "\" Format=\"" + tileFormat + "\" ServerFormat=\"Default\" xmlns=\"" + schemaName + "\">"); lines.add("<Size Width=\"" + width + "\" Height=\"" + height + "\" />"); lines.add("</Image>"); saveText(lines, file); }
From source file:com.buaa.cfs.net.DNS.java
/** * Returns all the host names associated by the provided nameserver with the address bound to the specified network * interface/*from w w w .j a va 2s . c o m*/ * * @param strInterface The name of the network interface or subinterface to query (e.g. eth0 or eth0:0) * @param nameserver The DNS host name * * @return A string vector of all host names associated with the IPs tied to the specified interface * * @throws UnknownHostException if the given interface is invalid */ public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException { String[] ips = getIPs(strInterface); Vector<String> hosts = new Vector<String>(); for (int ctr = 0; ctr < ips.length; ctr++) { try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (UnknownHostException ignored) { } catch (NamingException ignored) { } } if (hosts.isEmpty()) { LOG.warn("Unable to determine hostname for interface " + strInterface); return new String[] { cachedHostname }; } else { return hosts.toArray(new String[hosts.size()]); } }