List of usage examples for java.util List iterator
Iterator<E> iterator();
From source file:daylightchart.daylightchart.calculation.RiseSetUtility.java
/** * Debug calculations./* w ww .j av a 2 s . co m*/ * * @param writer * Writer to write to * @param location * Location to debug * @param daylightBandType * Types of band type to write to */ @SuppressWarnings("boxing") private static void writeCalculations(final Writer writer, final Location location, final TwilightType twilight, final DaylightBandType... daylightBandType) { if (writer == null || location == null) { return; } final DecimalFormat format = new DecimalFormat("00.000"); format.setMaximumFractionDigits(3); final int year = Year.now().getValue(); final Options options = new Options(); options.setTwilightType(twilight); final RiseSetYearData riseSetYear = createRiseSetYear(location, year, options); final PrintWriter printWriter = new PrintWriter(writer, true); // Header printWriter.printf("Location\t%s%nDate\t%s%n%n", location, year); // Bands final List<DaylightBand> bands = riseSetYear.getBands(); for (final Iterator<DaylightBand> iterator = bands.iterator(); iterator.hasNext();) { final DaylightBand band = iterator.next(); if (!ArrayUtils.contains(daylightBandType, band.getDaylightBandType())) { iterator.remove(); } } printWriter.printf("\t\t\t"); if (ArrayUtils.contains(daylightBandType, DaylightBandType.twilight)) { printWriter.printf("\t\t"); } for (final DaylightBand band : bands) { printWriter.printf("Band\t%s\t", band.getName()); } printWriter.println(); // Data rows printWriter.print("Date\tSunrise\tSunset"); if (ArrayUtils.contains(daylightBandType, DaylightBandType.twilight)) { printWriter.println("\tTwilight Rise\tTwilight Set"); } else { printWriter.println(); } final List<RawRiseSet> rawRiseSets = riseSetYear.getRawRiseSets(); final List<RawRiseSet> rawTwilights = riseSetYear.getRawTwilights(); for (int i = 0; i < rawRiseSets.size(); i++) { final RawRiseSet rawRiseSet = rawRiseSets.get(i); printWriter.printf("%s\t%s\t%s", rawRiseSet.getDate(), format.format(rawRiseSet.getSunrise()), format.format(rawRiseSet.getSunset())); if (ArrayUtils.contains(daylightBandType, DaylightBandType.twilight)) { final RawRiseSet rawTwilight = rawTwilights.get(i); printWriter.printf("\t%s\t%s", format.format(rawTwilight.getSunrise()), format.format(rawTwilight.getSunset())); } for (final DaylightBand band : bands) { final RiseSet riseSet = band.get(rawRiseSet.getDate()); if (riseSet == null) { printWriter.print("\t\t"); } else { printWriter.printf("\t%s\t%s", riseSet.getSunrise().toLocalTime().format(DateTimeFormatter.ofPattern("HH:mm:ss")), riseSet.getSunset().toLocalTime().format(DateTimeFormatter.ofPattern("HH:mm:ss"))); } } printWriter.println(); } }
From source file:com.aurel.track.persist.TSystemStatePeer.java
private static List<TSystemStateBean> convertTorqueListToBeanList(List<TSystemState> torqueList) { List<TSystemStateBean> beanList = new LinkedList<TSystemStateBean>(); if (torqueList != null) { Iterator<TSystemState> itrTorqueList = torqueList.iterator(); while (itrTorqueList.hasNext()) { beanList.add(itrTorqueList.next().getBean()); }/*from w w w . j a v a 2s .com*/ } return beanList; }
From source file:ValidateLicenseHeaders.java
/** * Read the first comment upto the package ...; statement * /*from ww w .j a v a2 s . co m*/ * @param javaFile */ static void parseHeader(File javaFile) throws IOException { totalCount++; RandomAccessFile raf = new RandomAccessFile(javaFile, "rw"); String line = raf.readLine(); StringBuffer tmp = new StringBuffer(); long endOfHeader = 0; boolean packageOrImport = false; while (line != null) { long nextEOH = raf.getFilePointer(); line = line.trim(); // Ignore any single line comments if (line.startsWith("//")) { line = raf.readLine(); continue; } // If this is a package/import/class/interface statement break if (line.startsWith("package") || line.startsWith("import") || line.indexOf("class") >= 0 || line.indexOf("interface") >= 0) { packageOrImport = true; break; } // Update the current end of header marker endOfHeader = nextEOH; if (line.startsWith("/**")) tmp.append(line.substring(3)); else if (line.startsWith("/*")) tmp.append(line.substring(2)); else if (line.startsWith("*")) tmp.append(line.substring(1)); else tmp.append(line); tmp.append(' '); line = raf.readLine(); } raf.close(); if (tmp.length() == 0 || packageOrImport == false) { addDefaultHeader(javaFile); return; } String text = tmp.toString(); // Replace all duplicate whitespace with a single space text = text.replaceAll("[\\s*]+", " "); text = text.toLowerCase().trim(); // Replace any copyright date0-date1,date2 with copyright ... text = text.replaceAll(COPYRIGHT_REGEX, "..."); if (tmp.length() == 0) { addDefaultHeader(javaFile); return; } // Search for a matching header boolean matches = false; String matchID = null; Iterator iter = licenseHeaders.entrySet().iterator(); escape: while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); String key = (String) entry.getKey(); List list = (List) entry.getValue(); Iterator jiter = list.iterator(); while (jiter.hasNext()) { LicenseHeader lh = (LicenseHeader) jiter.next(); if (text.startsWith(lh.text)) { matches = true; matchID = lh.id; lh.count++; lh.usage.add(javaFile); if (log.isLoggable(Level.FINE)) log.fine(javaFile + " matches copyright key=" + key + ", id=" + lh.id); break escape; } } } text = null; tmp.setLength(0); if (matches == false) invalidheaders.add(javaFile); else if (matchID.startsWith("jboss") && matchID.endsWith("#0") == false) { // This is a legacy jboss head that needs to be updated to the default replaceHeader(javaFile, endOfHeader); jbossCount++; } }
From source file:Hib.ControllerInsertJSON.java
static void listUsers() { List<DB_jason_user> userList = Model.queryUsersInDB(); System.out.println();/*from www. jav a2 s . com*/ System.out.println("People in Database"); System.out.printf("%-5s%-16s%-16s%-20s\n", "ID", "Name", "Email Address", "Phone"); System.out.printf("%-5s%-16s%-16s%-20s\n", "---------------", "----------", "---------", "------"); Iterator<DB_jason_user> ownerIterator = userList.iterator(); while (ownerIterator.hasNext()) { DB_jason_user element = ownerIterator.next(); System.out.printf("%-5s%-16s%-16s%-20s\n", element.getUserID(), element.getName(), element.getEmail(), element.getPhone()); } }
From source file:grails.plugin.searchable.internal.compass.mapping.SearchableGrailsDomainClassCompassMappingUtils.java
/** * Merges the given property mappings, overriding parent mappings with child mappings * @param mappedProperties/*from w ww . j av a 2 s. c o m*/ * @param parentClassPropertyMappings */ public static void mergePropertyMappings(List mappedProperties, List parentClassPropertyMappings) { if (parentClassPropertyMappings == null) { return; } Assert.notNull(mappedProperties, "mappedProperties cannot be null"); List temp = new ArrayList(parentClassPropertyMappings); temp.addAll(mappedProperties); for (Iterator citer = mappedProperties.iterator(); citer.hasNext();) { CompassClassPropertyMapping cmapping = (CompassClassPropertyMapping) citer.next(); for (Iterator piter = parentClassPropertyMappings.iterator(); piter.hasNext();) { CompassClassPropertyMapping pmapping = (CompassClassPropertyMapping) piter.next(); if (cmapping.getPropertyName().equals(pmapping.getPropertyName())) { temp.remove(pmapping); } } } mappedProperties.clear(); mappedProperties.addAll(temp); }
From source file:forge.card.BoosterGenerator.java
/** * This method also modifies passed parameter *///from www .ja v a 2s. com private static Predicate<PaperCard> buildExtraPredicate(List<String> operators) { List<Predicate<PaperCard>> conditions = new ArrayList<>(); Iterator<String> itOp = operators.iterator(); while (itOp.hasNext()) { String operator = itOp.next(); if (StringUtils.isEmpty(operator)) { itOp.remove(); continue; } if (operator.endsWith("s")) { operator = operator.substring(0, operator.length() - 1); } boolean invert = operator.charAt(0) == '!'; if (invert) { operator = operator.substring(1); } Predicate<PaperCard> toAdd = null; if (operator.equalsIgnoreCase(BoosterSlots.DUAL_FACED_CARD)) { toAdd = Predicates.compose(CardRulesPredicates.splitType(CardSplitType.Transform), PaperCard.FN_GET_RULES); } else if (operator.equalsIgnoreCase(BoosterSlots.LAND)) { toAdd = Predicates.compose(CardRulesPredicates.Presets.IS_LAND, PaperCard.FN_GET_RULES); } else if (operator.equalsIgnoreCase(BoosterSlots.BASIC_LAND)) { toAdd = IPaperCard.Predicates.Presets.IS_BASIC_LAND; } else if (operator.equalsIgnoreCase(BoosterSlots.TIME_SHIFTED)) { toAdd = IPaperCard.Predicates.Presets.IS_SPECIAL; } else if (operator.equalsIgnoreCase(BoosterSlots.SPECIAL)) { toAdd = IPaperCard.Predicates.Presets.IS_SPECIAL; } else if (operator.equalsIgnoreCase(BoosterSlots.MYTHIC)) { toAdd = IPaperCard.Predicates.Presets.IS_MYTHIC_RARE; } else if (operator.equalsIgnoreCase(BoosterSlots.RARE)) { toAdd = IPaperCard.Predicates.Presets.IS_RARE; } else if (operator.equalsIgnoreCase(BoosterSlots.UNCOMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_UNCOMMON; } else if (operator.equalsIgnoreCase(BoosterSlots.COMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_COMMON; } else if (operator.startsWith("name(")) { operator = StringUtils.strip(operator.substring(4), "() "); String[] cardNames = TextUtil.splitWithParenthesis(operator, ',', '"', '"'); toAdd = IPaperCard.Predicates.names(Lists.newArrayList(cardNames)); } else if (operator.startsWith("color(")) { operator = StringUtils.strip(operator.substring("color(".length() + 1), "()\" "); switch (operator.toLowerCase()) { case "black": toAdd = Presets.IS_BLACK; break; case "blue": toAdd = Presets.IS_BLUE; break; case "green": toAdd = Presets.IS_GREEN; break; case "red": toAdd = Presets.IS_RED; break; case "white": toAdd = Presets.IS_WHITE; break; case "colorless": toAdd = Presets.IS_COLORLESS; break; } } else if (operator.startsWith("fromSets(")) { operator = StringUtils.strip(operator.substring("fromSets(".length() + 1), "()\" "); String[] sets = operator.split(","); toAdd = IPaperCard.Predicates.printedInSets(sets); } else if (operator.startsWith("fromSheet(") && invert) { String sheetName = StringUtils.strip(operator.substring(9), "()\" "); Iterable<PaperCard> src = StaticData.instance().getPrintSheets().get(sheetName).toFlatList(); List<String> cardNames = Lists.newArrayList(); for (PaperCard card : src) { cardNames.add(card.getName()); } toAdd = IPaperCard.Predicates.names(Lists.newArrayList(cardNames)); } if (toAdd == null) { continue; } else { itOp.remove(); } if (invert) { toAdd = Predicates.not(toAdd); } conditions.add(toAdd); } if (conditions.isEmpty()) { return Predicates.alwaysTrue(); } return Predicates.and(conditions); }
From source file:ch.ethz.epics.export.GoogleImageSitemap.java
protected static Element getSingleNode(Document doc, String strXPath) throws JDOMException { XPath xpath = XPath.newInstance(strXPath); xpath.addNamespace(XPort.nsEpics);/* w w w . j a v a 2s. co m*/ List elementList = xpath.selectNodes(doc); if (elementList.size() > 0) { return (Element) (elementList.iterator().next()); } else { return null; } }
From source file:com.aurel.track.exchange.excel.ExcelFieldMatchBL.java
/** * Get a label based map of all defined fields * @return/*w ww. jav a2 s. c om*/ */ private static Map<String, TFieldConfigBean> getFieldNameBasedFieldConfigsMap() { Map<String, TFieldConfigBean> fieldConfigBeansMap = new HashMap<String, TFieldConfigBean>(); Map<Integer, TFieldBean> fieldMap = GeneralUtils.createMapFromList(FieldBL.loadAll()); List<TFieldConfigBean> fieldConfigBeansList = FieldConfigBL.loadDefault(); Iterator<TFieldConfigBean> iterator = fieldConfigBeansList.iterator(); while (iterator.hasNext()) { TFieldConfigBean fieldConfigBean = iterator.next(); TFieldBean fieldBean = fieldMap.get(fieldConfigBean.getField()); if (fieldBean != null) { fieldConfigBeansMap.put(fieldBean.getName(), fieldConfigBean); } } return fieldConfigBeansMap; }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils.java
/** * Creates a set of vitro:ClassGroup resources for each root class in * an ontology. Also creates annotations to place each root class and all * of its children in the appropriate groups. In the case of multiple * inheritance, classgroup assignment will be arbitrary. * @param wadf/*from w w w. j a v a 2 s. co m*/ * @param tboxModel containing ontology classes * @return resultArray of OntModels, where resultArray[0] is the model containing * the triples about the classgroups, and resultArray[1] is the model containing * annotation triples assigning ontology classes to classgroups. */ public synchronized static OntModel[] makeClassGroupsFromRootClasses(WebappDaoFactory wadf, Model tboxModel) { OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, tboxModel); OntModel modelForClassgroups = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); OntModel modelForClassgroupAnnotations = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); SimpleOntModelSelector oms = new SimpleOntModelSelector(); oms.setTBoxModel(ontModel); oms.setApplicationMetadataModel(modelForClassgroups); WebappDaoFactoryConfig config = new WebappDaoFactoryConfig(); config.setDefaultNamespace(wadf.getDefaultNamespace()); WebappDaoFactory myWebappDaoFactory = new WebappDaoFactoryJena(new SimpleOntModelSelector(ontModel), config, null); Resource classGroupClass = ResourceFactory.createResource(VitroVocabulary.CLASSGROUP); Property inClassGroupProperty = ResourceFactory.createProperty(VitroVocabulary.IN_CLASSGROUP); ontModel.enterCriticalSection(Lock.READ); try { try { List<VClass> rootClasses = myWebappDaoFactory.getVClassDao().getRootClasses(); for (Iterator<VClass> rootClassIt = rootClasses.iterator(); rootClassIt.hasNext();) { VClass rootClass = rootClassIt.next(); Individual classGroup = modelForClassgroups.createIndividual( wadf.getDefaultNamespace() + "vitroClassGroup" + rootClass.getLocalName(), classGroupClass); classGroup.setLabel(rootClass.getName(), null); Resource rootClassRes = modelForClassgroupAnnotations.getResource(rootClass.getURI()); modelForClassgroupAnnotations.add(rootClassRes, inClassGroupProperty, classGroup); for (Iterator<String> childIt = myWebappDaoFactory.getVClassDao() .getAllSubClassURIs(rootClass.getURI()).iterator(); childIt.hasNext();) { String childURI = childIt.next(); Resource childClass = modelForClassgroupAnnotations.getResource(childURI); if (!modelForClassgroupAnnotations.contains(childClass, inClassGroupProperty, (RDFNode) null)) { childClass.addProperty(inClassGroupProperty, classGroup); } } } } catch (Exception e) { String errMsg = "Unable to create class groups automatically " + "based on class hierarchy"; log.error(errMsg, e); throw new RuntimeException(errMsg, e); } } finally { ontModel.leaveCriticalSection(); } OntModel[] resultArray = new OntModel[2]; resultArray[0] = modelForClassgroups; resultArray[1] = modelForClassgroupAnnotations; return resultArray; }
From source file:de.xwic.appkit.core.util.CollectionUtil.java
/** * @param collection//from www. ja va 2 s. c om * @param evaluator * @param emptyMessage * @return */ public static <O, X extends Exception> String join(final Collection<O> collection, final ExceptionalFunction<O, String, X> evaluator, final String separator, final String emptyMessage) throws X { final List<String> strings = createList(collection, evaluator); final Iterator<String> iterator = strings.iterator(); if (iterator.hasNext()) { return StringUtils.join(iterator, separator); } return emptyMessage; }