List of usage examples for java.util ListIterator hasPrevious
boolean hasPrevious();
From source file:org.netflux.core.RecordMetadata.java
/** * Removes from this metadata all the field metadata with names included in the supplied collection. * //from w w w .j a v a 2s . c om * @param fieldNames the names of the field metadata to remove. * @throws NullPointerException if the specified collection is <code>null</code>. */ public void remove(Collection<String> fieldNames) { LinkedHashMap<String, Integer> fieldsToRemove = (LinkedHashMap<String, Integer>) this.fieldIndexes.clone(); fieldsToRemove.keySet().retainAll(fieldNames); List<FieldMetadata> newFieldMetadata = (List<FieldMetadata>) this.fieldMetadata.clone(); ListIterator<Integer> fieldIndexIterator = new ArrayList<Integer>(fieldsToRemove.values()) .listIterator(fieldsToRemove.size()); while (fieldIndexIterator.hasPrevious()) { newFieldMetadata.remove(fieldIndexIterator.previous()); } this.setFieldMetadata(newFieldMetadata); }
From source file:samples.com.axiomine.largecollections.util.TurboListSample.java
public static void workOnTurboList(TurboList<Integer> lst) { try {/*from w w w . j a v a 2s . com*/ ListIterator<Integer> it = lst.listIterator(); for (int i = 0; i < 10; i++) { boolean b = lst.add(i); Assert.assertEquals(true, true); } System.out.println("Size of map=" + lst.size()); System.out.println("Value for key 0=" + lst.get(0)); ; System.out.println("Now remove key 0"); try { int i = lst.remove(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } int i = lst.remove(9); System.out.println("Value for deleted key=" + i); ; System.out.println("Size of map=" + lst.size()); lst.close(); boolean b = false; try { lst.add(9); } catch (Exception ex) { System.out.println("Exception because acces after close"); b = true; } lst.open(); System.out.println("Open again"); b = lst.add(9); Assert.assertEquals(true, b); i = lst.set(9, 99); Assert.assertEquals(99, i); i = lst.set(5, 55); Assert.assertEquals(55, i); i = lst.set(0, 100); Assert.assertEquals(100, i); System.out.println(lst.get(0)); System.out.println(lst.get(5)); System.out.println(lst.get(9)); System.out.println("Now put worked. Size of map should be 10. Size of the map =" + lst.size()); Iterator<Integer> iter = lst.iterator(); try { while (iter.hasNext()) { i = iter.next(); System.out.println("From ITerator = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) iter).close(); } ListIterator<Integer> lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } lstIter = lst.listIterator(5); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("---"); lstIter = lst.listIterator(9); try { while (lstIter.hasPrevious()) { i = lstIter.previous(); System.out.println("From List Iterator Previous= " + i); System.out.println("From List Iterator Previous Index= " + lstIter.previousIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("----------------------------------"); lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = lstIter.next(); System.out.println("Iterating Forward = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("Now Serialize the List"); File serFile = new File(System.getProperty("java.io.tmpdir") + "/x.ser"); FileSerDeUtils.serializeToFile(lst, serFile); System.out.println("Now De-Serialize the List"); lst = (TurboList<Integer>) FileSerDeUtils.deserializeFromFile(serFile); System.out.println("After De-Serialization " + lst); System.out.println("After De-Serialization Size of map should be 10. Size of the map =" + lst.size()); printListCharacteristics(lst); System.out.println("Now calling lst.clear()"); lst.clear(); System.out.println("After clear list size should be 0 and =" + lst.size()); lst.add(0); System.out.println("Just added a record and lst size =" + lst.size()); System.out.println("Finally Destroying"); lst.destroy(); System.out.println("Cleanup serialized file"); FileUtils.deleteQuietly(serFile); } catch (Exception ex) { throw Throwables.propagate(ex); } }
From source file:Heuristics.TermLevelHeuristics.java
public boolean isQuestionMarkAtEndOfStatus(String status) { List<String> terms = new ArrayList(); Collections.addAll(terms, status.split(" ")); StringBuilder sb = new StringBuilder(); boolean cleanEnd = false; ListIterator<String> termsIterator = terms.listIterator(terms.size()); while (termsIterator.hasPrevious() & !cleanEnd) { String string = termsIterator.previous(); if (!cleanEnd && (string.contains("/") || string.startsWith("#") || string.startsWith("@") || string.equals("\\|") || string.equals("") || string.contains("via") || string.equals("..."))) { continue; } else {/*from w ww. j a v a 2s. com*/ cleanEnd = true; } sb.insert(0, string); } status = sb.toString().trim(); if (status.length() == 0) { return false; } else { return ("?".equals(String.valueOf(status.charAt(status.length() - 1)))) ? true : false; } }
From source file:com.neatresults.mgnltweaks.ui.field.ComponentTemplateSelectFieldFactory.java
private Map<String, TemplateDefinition> getAreaHierarchy(Node parentArea) throws RepositoryException, RegistrationException { Map<String, TemplateDefinition> areaHierarchy = new LinkedHashMap<String, TemplateDefinition>(); List<String> areaNamesHierarchy = new ArrayList<String>(); Node parentParentArea = parentArea; while (parentParentArea != null) { String areaName = parentParentArea.getName(); areaNamesHierarchy.add(areaName); parentParentArea = NodeUtil.getNearestAncestorOfType(parentParentArea, NodeTypes.Area.NAME); }/*from ww w.j av a 2 s . com*/ Node parentPage = NodeUtil.getNearestAncestorOfType(parentArea, NodeTypes.Page.NAME); templateId = parentPage.getProperty(NodeTypes.Renderable.TEMPLATE).getString(); TemplateDefinition templateDef = registry.getTemplateDefinition(templateId); templateDef = mergeDefinition(templateDef); ListIterator<String> iter = areaNamesHierarchy.listIterator(areaNamesHierarchy.size()); Node componentOrArea = parentPage; while (iter.hasPrevious()) { String name = iter.previous(); // subnode component is typically indication of having area type single if (!componentOrArea.hasNode(name) && (componentOrArea.hasNode("component") || (templateDef instanceof AreaDefinition && "single".equals(((AreaDefinition) templateDef).getType())))) { componentOrArea = componentOrArea.getNode("component/" + name); // so we know component is single, and we neeed to look if it has any sub areas String id = componentOrArea.getParent().getProperty(NodeTypes.Renderable.TEMPLATE).getString(); TemplateDefinition componentDef = registry.getTemplateDefinition(id); if (componentDef != null) { templateDef = componentDef; } } else { componentOrArea = componentOrArea.getNode(name); } // do we really need to merge here already? AreaDefinition area = templateDef.getAreas().get(name); if (area != null) { AreaDefinition areaDef = (AreaDefinition) mergeDefinition(area); templateDef = areaDef; } else { AreaDefinition maybeHit = templateDef.getAreas().get(name); if (maybeHit != null) { areaHierarchy.put(name, maybeHit); templateDef = maybeHit; } else { // get subareas of the area? what the hack was i thinking when writing this? How does it work anyway? for (Entry<String, AreaDefinition> tempAreaEntry : templateDef.getAreas().entrySet()) { AreaDefinition tempArea = tempAreaEntry.getValue(); maybeHit = tempArea.getAreas().get(name); if (maybeHit != null) { areaHierarchy.put(tempAreaEntry.getKey(), tempAreaEntry.getValue()); templateDef = maybeHit; } } } // noComponent area ... how do i read those? } areaHierarchy.put(name, templateDef); } return areaHierarchy; }
From source file:org.apache.cayenne.unit.di.server.SchemaBuilder.java
private void dropSchema(DataNode node, DataMap map) throws Exception { List<DbEntity> list = dbEntitiesInInsertOrder(node, map); try (Connection conn = dataSourceFactory.getSharedDataSource().getConnection();) { DatabaseMetaData md = conn.getMetaData(); List<String> allTables = new ArrayList<String>(); try (ResultSet tables = md.getTables(null, null, "%", null)) { while (tables.next()) { // 'toUpperCase' is needed since most databases // are case insensitive, and some will convert names to // lower // case // (PostgreSQL) String name = tables.getString("TABLE_NAME"); if (name != null) allTables.add(name.toUpperCase()); }//from w w w.jav a 2 s. com } unitDbAdapter.willDropTables(conn, map, allTables); // drop all tables in the map try (Statement stmt = conn.createStatement();) { ListIterator<DbEntity> it = list.listIterator(list.size()); while (it.hasPrevious()) { DbEntity ent = it.previous(); if (!allTables.contains(ent.getName().toUpperCase())) { continue; } for (String dropSql : node.getAdapter().dropTableStatements(ent)) { try { logger.info(dropSql); stmt.execute(dropSql); } catch (SQLException sqe) { logger.warn("Can't drop table " + ent.getName() + ", ignoring...", sqe); } } } } unitDbAdapter.droppedTables(conn, map); } }
From source file:org.cipango.callflow.JmxMessageLog.java
public void setMaxMessages(int maxMessages) { if (maxMessages <= 0) throw new IllegalArgumentException("Max message must be greater than 0"); synchronized (this) { if (isRunning() && maxMessages != _maxMessages) { MessageInfo[] messages = new MessageInfo[maxMessages]; ListIterator<MessageInfo> it = iterate(false); int index = maxMessages; while (it.hasPrevious()) { messages[--index] = it.previous(); if (index == 0) break; }//w ww. j ava 2 s. c o m _cursor = 0; _messages = messages; } _maxMessages = maxMessages; } }
From source file:samples.com.axiomine.largecollections.util.WritableListSample.java
public static void workOnWritableList(WritableList<IntWritable> lst) { try {/*from w w w . ja va 2 s. com*/ ListIterator<Writable> it = lst.listIterator(); for (int i = 0; i < 10; i++) { boolean b = lst.add(new IntWritable(i)); Assert.assertEquals(true, true); } System.out.println("Size of map=" + lst.size()); System.out.println("Value for key 0=" + lst.get(0)); ; System.out.println("Now remove key 0"); try { //int i = lst.remove(0); Writable w = lst.remove(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } int i = ((IntWritable) lst.remove(9)).get(); System.out.println("Value for deleted key=" + i); ; System.out.println("Size of map=" + lst.size()); lst.close(); boolean b = false; try { lst.add(new IntWritable(9)); } catch (Exception ex) { System.out.println("Exception because acces after close"); b = true; } lst.open(); System.out.println("Open again"); b = lst.add(new IntWritable(9)); Assert.assertEquals(true, b); i = ((IntWritable) lst.set(9, new IntWritable(99))).get(); Assert.assertEquals(99, i); i = ((IntWritable) lst.set(5, new IntWritable(55))).get(); Assert.assertEquals(55, i); i = ((IntWritable) lst.set(0, new IntWritable(100))).get(); Assert.assertEquals(100, i); System.out.println(lst.get(0)); System.out.println(lst.get(5)); System.out.println(lst.get(9)); System.out.println("Now put worked. Size of map should be 10. Size of the map =" + lst.size()); Iterator<Writable> iter = lst.iterator(); try { while (iter.hasNext()) { i = ((IntWritable) iter.next()).get(); System.out.println("From ITerator = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) iter).close(); } ListIterator<Writable> lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = ((IntWritable) lstIter.next()).get(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } lstIter = lst.listIterator(5); try { while (lstIter.hasNext()) { i = ((IntWritable) lstIter.next()).get(); System.out.println("From List Iterator = " + i); System.out.println("From List Iterator Next Index= " + lstIter.nextIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("---"); lstIter = lst.listIterator(9); try { while (lstIter.hasPrevious()) { i = ((IntWritable) lstIter.next()).get(); System.out.println("From List Iterator Previous= " + i); System.out.println("From List Iterator Previous Index= " + lstIter.previousIndex()); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("----------------------------------"); lstIter = lst.listIterator(); try { while (lstIter.hasNext()) { i = ((IntWritable) lstIter.next()).get(); System.out.println("Iterating Forward = " + i); } } finally { //Always close and iterator after use. Otherwise you will not be able to call the clear function ((Closeable) lstIter).close(); } System.out.println("Now Serialize the List"); File serFile = new File(System.getProperty("java.io.tmpdir") + "/x.ser"); FileSerDeUtils.serializeToFile(lst, serFile); System.out.println("Now De-Serialize the List"); lst = (WritableList<IntWritable>) FileSerDeUtils.deserializeFromFile(serFile); System.out.println("After De-Serialization " + lst); System.out.println("After De-Serialization Size of map should be 10. Size of the map =" + lst.size()); printListCharacteristics(lst); System.out.println("Now calling lst.clear()"); lst.clear(); System.out.println("After clear list size should be 0 and =" + lst.size()); lst.add(new IntWritable(0)); System.out.println("Just added a record and lst size =" + lst.size()); System.out.println("Finally Destroying"); lst.destroy(); System.out.println("Cleanup serialized file"); FileUtils.deleteQuietly(serFile); } catch (Exception ex) { throw Throwables.propagate(ex); } }
From source file:org.apache.stratos.autoscaler.service.util.IaasContext.java
/** * This will return the node id of the node which is belong to the * requesting domain, sub domain and which is the most recently created. If it cannot find a * matching node id, this will return <code>null</code>. * @param domain service domain.//from ww w. j a va 2 s . c o m * @param subDomain service sub domain. * @return the node Id of the node */ public String getLastMatchingNode(String domain, String subDomain) { InstanceContext ctx = getInstanceContext(domain, subDomain); if (ctx == null) { return null; } // iterate in reverse order ListIterator<String> iter = new ArrayList<String>(ctx.getNodeIdToIpMap().keySet()) .listIterator(ctx.getNodeIdToIpMap().size()); if (iter.hasPrevious()) { return iter.previous(); } return null; }
From source file:com.numenta.taurus.instance.InstanceDetailPageFragment.java
void updateServerHeader() { if (_chartData == null) { return;// w ww . j a v a 2s . c o m } if (_instanceChartFrag == null) { return; } // Update server header _instanceChartFrag.setChartData(_chartData); // Update time slider Date endDate = _chartData.getEndDate(); long endTime; if (endDate == null) { endTime = System.currentTimeMillis(); } else { endTime = endDate.getTime(); } _timeView.setAggregation(_chartData.getAggregation()); _timeView.setEndDate(endTime); // Check if need to collapse to market hours if (_collapseAfterHours) { EnumSet<MetricType> anomalousMetrics = _chartData.getAnomalousMetrics(); if (anomalousMetrics.contains(MetricType.TwitterVolume)) { // Collapse to market hours if twitter anomalies occurred during market hours MarketCalendar marketCalendar = TaurusApplication.getMarketCalendar(); boolean collapsed = true; // Check if is there any twitter anomaly on the last visible bars List<Pair<Long, Float>> data = _chartData.getData(); ListIterator<Pair<Long, Float>> iterator = data.listIterator(data.size()); for (int i = 0; i < TaurusApplication.getTotalBarsOnChart() && iterator.hasPrevious(); i++) { Pair<Long, Float> value = iterator.previous(); if (value != null && value.second != null && !Float.isNaN(value.second)) { double scaled = DataUtils.logScale(value.second); if (scaled >= TaurusApplication.getYellowBarFloor() && !marketCalendar.isOpen(value.first)) { // Found anomaly, don't collapse collapsed = false; break; } } } _marketHoursCheckbox.setChecked(collapsed); } else { // Collapse to market hours if we only have stock anomalies _marketHoursCheckbox.setChecked(true); } // Prevent collapsing during scroll _collapseAfterHours = false; } }
From source file:org.flowable.cmmn.converter.ConversionHelper.java
public void addExitCriteriaToCurrentElement(Criterion exitCriterion) { addExitCriterion(exitCriterion);//w ww. j a v a 2s .c om ListIterator<CmmnElement> iterator = currentCmmnElements.listIterator(currentCmmnElements.size()); HasExitCriteria hasExitCriteria = null; while (hasExitCriteria == null && iterator.hasPrevious()) { CmmnElement cmmnElement = iterator.previous(); if (cmmnElement instanceof HasExitCriteria) { hasExitCriteria = (HasExitCriteria) cmmnElement; } } if (hasExitCriteria == null) { hasExitCriteria = getCurrentCase().getPlanModel(); } if (StringUtils.isEmpty(exitCriterion.getId())) { // An id is expected by the evaluation algorithm, so setting an internal one if there isn't one exitCriterion.setId("exitCriterion_" + (hasExitCriteria.getExitCriteria().size() + 1)); } exitCriterion.setAttachedToRefId(hasExitCriteria.getId()); hasExitCriteria.getExitCriteria().add(exitCriterion); }