List of usage examples for java.util ArrayList addAll
public boolean addAll(Collection<? extends E> c)
From source file:ala.soils2sat.DrawingUtils.java
public static Rectangle drawString(Graphics g, Font font, String text, int x, int y, int width, int height, int align, boolean wrap) { g.setFont(font);//from www . j av a 2 s. c o m FontMetrics fm = g.getFontMetrics(font); setPreferredAliasingMode(g); Rectangle ret = new Rectangle(0, 0, 0, 0); if (text == null) { return ret; } String[] alines = text.split("\\n"); ArrayList<String> lines = new ArrayList<String>(); for (String s : alines) { if (wrap && fm.stringWidth(s) > width) { // need to split this up into multiple lines... List<String> splitLines = wrapString(s, fm, width); lines.addAll(splitLines); } else { lines.add(s); } } int numlines = lines.size(); while (fm.getHeight() * numlines > height) { numlines--; } if (numlines > 0) { int maxwidth = 0; int minxoffset = y + width; int totalheight = (numlines * fm.getHeight()); int linestart = ((height / 2) - (totalheight / 2)); if (!wrap) { ret.y = y + linestart; } else { ret.y = y; linestart = 0; } for (int idx = 0; idx < numlines; ++idx) { String line = lines.get(idx); int stringWidth = fm.stringWidth(line); // the width of the label depends on the font : // if the width of the label is larger than the item if (stringWidth > 0 && width < stringWidth) { // We have to truncate the label line = clipString(null, fm, line, width); stringWidth = fm.stringWidth(line); } int xoffset = 0; int yoffset = linestart + fm.getHeight() - fm.getDescent(); if (align == TEXT_ALIGN_RIGHT) { xoffset = (width - stringWidth); } else if (align == TEXT_ALIGN_CENTER) { xoffset = (int) Math.round((double) (width - stringWidth) / (double) 2); } if (xoffset < minxoffset) { minxoffset = xoffset; } g.drawString(line, x + xoffset, y + yoffset); if (stringWidth > maxwidth) { maxwidth = stringWidth; } linestart += fm.getHeight(); } ret.width = maxwidth; ret.height = totalheight; ret.x = x + minxoffset; // Debug only... if (DEBUG) { Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(1)); g.setColor(Color.blue); g.drawRect(ret.x, ret.y, ret.width, ret.height); g.setColor(Color.green); g.drawRect(x, y, width, height); } return ret; } return ret; }
From source file:com.verisignlabs.dnssec.cl.SignZone.java
/** * Load keysets (which contain delegation point security info). * //from www.j av a2 s . c om * @param inDirectory * the directory to look for the keyset files (may be null, in * which * case it defaults to looking in the current working directory). * @param zonename * the name of the zone we are signing, so we can ignore keysets * that * do not belong in the zone. * @return a list of {@link org.xbill.DNS.Record}s found in the keyset * files. */ private static List<Record> getKeysets(File inDirectory, Name zonename) throws IOException { if (inDirectory == null) { inDirectory = new File("."); } // get the list of "keyset-" files. FileFilter filter = new KeysetFileFilter(); File[] files = inDirectory.listFiles(filter); // read in all of the records ArrayList<Record> keysetRecords = new ArrayList<Record>(); for (int i = 0; i < files.length; i++) { List<Record> l = ZoneUtils.readZoneFile(files[i].getAbsolutePath(), zonename); keysetRecords.addAll(l); } // discard records that do not belong to the zone in question. for (Iterator<Record> i = keysetRecords.iterator(); i.hasNext();) { Record r = i.next(); if (!r.getName().subdomain(zonename)) { i.remove(); } } return keysetRecords; }
From source file:gov.vha.isaac.ochre.api.LookupService.java
/** * @return the {@link ServiceLocator} that is managing this ISAAC instance *//*from w w w. j a v a 2 s. c om*/ public static ServiceLocator get() { if (looker == null) { synchronized (lock) { if (looker == null) { if (GraphicsEnvironment.isHeadless()) { log.info("Installing headless toolkit"); HeadlessToolkit.installToolkit(); } PlatformImpl.startup(() -> { // No need to do anything here }); ArrayList<String> packagesToSearch = new ArrayList<>( Arrays.asList("gov.va", "gov.vha", "org.ihtsdo", "org.glassfish")); boolean readInhabitantFiles = Boolean .getBoolean(System.getProperty(Constants.READ_INHABITANT_FILES, "false")); if (System.getProperty(Constants.EXTRA_PACKAGES_TO_SEARCH) != null) { String[] extraPackagesToSearch = System.getProperty(Constants.EXTRA_PACKAGES_TO_SEARCH) .split(";"); packagesToSearch.addAll(Arrays.asList(extraPackagesToSearch)); } try { String[] packages = packagesToSearch.toArray(new String[] {}); log.info("Looking for HK2 annotations " + (readInhabitantFiles ? "from inhabitant files" : "skipping inhabitant files") + "; and scanning in the packages: " + Arrays.toString(packages)); looker = HK2RuntimeInitializer.init("ISAAC", readInhabitantFiles, packages); log.info("HK2 initialized. Identifed " + looker.getAllServiceHandles((criteria) -> { return true; }).size() + " services"); } catch (Exception e) { throw new RuntimeException(e); } } } } return looker; }
From source file:Main.java
public static List<String> getValuesFromDocumentByTagAndAttribute(Node parentNode, String tagName, String attributeName, String attributeValue) { ArrayList<String> values = new ArrayList<String>(); for (int i = 0; i < parentNode.getChildNodes().getLength(); i++) { Node childNode = parentNode.getChildNodes().item(i); if (childNode != null) { if (childNode.hasAttributes()) { for (int j = 0; j < childNode.getAttributes().getLength(); j++) { Node attribute = childNode.getAttributes().item(j); if (attribute.getNodeName().equals(attributeName) && attribute.getNodeValue().equals(attributeValue)) { values.add(childNode.getTextContent().trim()); }/* w w w . j a va 2s. c o m*/ } } if (childNode.hasChildNodes()) { values.addAll(getValuesFromDocumentByTagAndAttribute(childNode, tagName, attributeName, attributeValue)); } } } return values; }
From source file:graphene.util.fs.FileUtils.java
public static ArrayList<File> getFilesRecursively(final String path, final String ext) throws IOException { final File folder = new File(path); final File[] listOfFiles = folder.listFiles(); final ArrayList<File> theFiles = new ArrayList<File>(); for (final File currentFile : listOfFiles) { final String name = currentFile.getName(); if (currentFile.isDirectory()) { // logger.debug("Directory name is " + // currentFile.getAbsolutePath()); theFiles.addAll(getFilesRecursively(currentFile.getAbsolutePath(), ext)); } else { // logger.debug("File name is " + currentFile.getName()); if (ValidationUtils.isValid(ext)) { // it's a file and we care about the extension if (name.contains(".")) { if (name.startsWith(".")) { // ignore these temp files logger.debug("Ignoring file " + name); } else { final String currentExt = getFileExtension(name); logger.debug("current Ext is " + currentExt); if (("." + ext).equalsIgnoreCase(currentExt)) { logger.debug("Adding file " + name); theFiles.add(currentFile); }//from w ww . j a v a 2s .co m } } else { // what do do with files that have no period? logger.debug("Ignoring file " + name); } } else { // Just add the file logger.debug("Adding file " + name); theFiles.add(currentFile); } } } return theFiles; }
From source file:SageCollegeProject.guideBox.java
public static void ReadAllShowsFromWeb(ArrayList<guide_ShowObject> res) { int resultamount = 2; int pos = 1;// w w w . java2 s . c om while (pos < resultamount) { String out = GetURLReturn("shows/all/" + pos + "/250/all/all"); Gson gson = new GsonBuilder().create(); guide_results test = gson.fromJson(out, guide_results.class); // for(guide_ShowObject curShow:test.getResults()) // { // curShow.setPoster(GetShowPoster(curShow.getId())); // System.out.println("Poster found +"+curShow.getPoster()); // } System.out.println(test.getTotal_results() + "Current " + pos); resultamount = Integer.parseInt(test.getTotal_results()); res.addAll(test.getResults()); pos = pos + 250; System.out.println("SCP GuideBox_Reading all shows total of=" + resultamount); System.out.println("SCP GuideBox_Current position of shows =" + pos); } }
From source file:DataBase.DataBase.java
public static ArrayList<StayPoint> calcAllStaypoints() { if (!DataBase.gpsRead()) { DataBase.readGPS();//from www.j ava2 s. co m } ArrayList<StayPoint> stayPoints = new ArrayList<StayPoint>(); ArrayList<User> users = DataBase.getAllUsers(); if (users != null) { Collections.sort(users, new CustomComparator()); } for (User u : users) { // User user1 = DataBase.getUser("user56"); ArrayList<StayPoint> stPoints = u.calcStayPoints(50000000.0, 0.0, 500000.0, 0.0); stayPoints.addAll(stPoints); } return stayPoints; }
From source file:com.imag.nespros.gui.plugin.GraphEditor.java
private static void buildEPGraphs() { ArrayList<EPUnit> operators = new ArrayList<>(); operators.addAll(simu.getProducers()); operators.addAll(simu.getConsumers()); for (EventConsumer c : simu.getConsumers()) { operators.addAll(c.getEPUList()); }//from w w w. j av a 2 s .c om EPGraph.getInstance().AddEPGraphFromList(operators); }
From source file:Main.java
private static ArrayList<SimpleEntry<String, String>> traverseNode(Node n, String p) { ArrayList<SimpleEntry<String, String>> output = new ArrayList<>(); String nName;// www .ja va2s .c o m if (n.getNodeType() != Node.TEXT_NODE) { nName = n.getNodeName(); if (nName.startsWith("m:")) nName = nName.substring(2); if (nName.equals("mws:qvar")) return new ArrayList<>(); p += "/" + nName; } String nValue = n.getNodeValue(); if (nValue != null) { nValue = nValue.trim(); if (nValue.length() == 0) { return new ArrayList<>(); } } else { nValue = ""; } if (!n.hasChildNodes()) { output.add(new SimpleEntry<>(p, nValue)); } else { for (int i = 0; i < n.getChildNodes().getLength(); i++) { output.addAll(traverseNode(n.getChildNodes().item(i), p)); } } return output; }
From source file:org.opendatakit.survey.android.provider.SubmissionProvider.java
@SuppressWarnings("unchecked") private static final int generateXmlHelper(Document d, Element data, int idx, String key, Map<String, Object> values, WebLogger log) { Object o = values.get(key);//from w ww. j a v a2 s. c o m Element e = d.createElement(XML_DEFAULT_NAMESPACE, key); if (o == null) { log.e(t, "Unexpected null value"); } else if (o instanceof Integer) { e.addChild(0, Node.TEXT, ((Integer) o).toString()); } else if (o instanceof Double) { e.addChild(0, Node.TEXT, ((Double) o).toString()); } else if (o instanceof Boolean) { e.addChild(0, Node.TEXT, ((Boolean) o).toString()); } else if (o instanceof String) { e.addChild(0, Node.TEXT, ((String) o)); } else if (o instanceof List) { StringBuilder b = new StringBuilder(); List<Object> al = (List<Object>) o; for (Object ob : al) { if (ob instanceof Integer) { b.append(((Integer) ob).toString()); } else if (ob instanceof Double) { b.append(((Double) ob).toString()); } else if (ob instanceof Boolean) { b.append(((Boolean) ob).toString()); } else if (ob instanceof String) { b.append(((String) ob)); } else { throw new IllegalArgumentException("Unexpected type in XML submission serializer"); } b.append(" "); } e.addChild(0, Node.TEXT, b.toString().trim()); } else if (o instanceof Map) { // it is an object... Map<String, Object> m = (Map<String, Object>) o; int nidx = 0; ArrayList<String> entryNames = new ArrayList<String>(); entryNames.addAll(m.keySet()); Collections.sort(entryNames); for (String name : entryNames) { nidx = generateXmlHelper(d, e, nidx, name, m, log); } } else { throw new IllegalArgumentException("Unexpected object type in XML submission serializer"); } data.addChild(idx++, Node.ELEMENT, e); data.addChild(idx++, Node.IGNORABLE_WHITESPACE, NEW_LINE); return idx; }