List of usage examples for java.util List listIterator
ListIterator<E> listIterator();
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupDaoJena.java
public int removeUnpopulatedGroups(List<VClassGroup> groups) { if (groups == null || groups.size() == 0) return 0; int removedGroupsCount = 0; ListIterator<VClassGroup> it = groups.listIterator(); while (it.hasNext()) { VClassGroup group = it.next();// w w w . ja va2 s .co m List<VClass> classes = group.getVitroClassList(); if (classes == null || classes.size() < 1) { removedGroupsCount++; it.remove(); } } return removedGroupsCount; }
From source file:com.bluelotussoftware.apache.commons.fileupload.example.MultiContentServlet.java
/** * Handles the HTTP// www. j a va2s . c om * <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter writer = null; InputStream is = null; FileOutputStream fos = null; try { writer = response.getWriter(); } catch (IOException ex) { log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } boolean isMultiPart = ServletFileUpload.isMultipartContent(request); if (isMultiPart) { log("Content-Type: " + request.getContentType()); // Create a factory for disk-based file items DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(); /* * Set the file size limit in bytes. This should be set as an * initialization parameter */ diskFileItemFactory.setSizeThreshold(1024 * 1024 * 10); //10MB. // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(diskFileItemFactory); List items = null; try { items = upload.parseRequest(request); } catch (FileUploadException ex) { log("Could not parse request", ex); } ListIterator li = items.listIterator(); while (li.hasNext()) { FileItem fileItem = (FileItem) li.next(); if (fileItem.isFormField()) { if (debug) { processFormField(fileItem); } } else { writer.print(processUploadedFile(fileItem)); } } } if ("application/octet-stream".equals(request.getContentType())) { log("Content-Type: " + request.getContentType()); String filename = request.getHeader("X-File-Name"); try { is = request.getInputStream(); fos = new FileOutputStream(new File(realPath + filename)); IOUtils.copy(is, fos); response.setStatus(HttpServletResponse.SC_OK); writer.print("{success: true}"); } catch (FileNotFoundException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); writer.print("{success: false}"); log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } catch (IOException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); writer.print("{success: false}"); log(MultiContentServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } finally { try { fos.close(); is.close(); } catch (IOException ignored) { } } writer.flush(); writer.close(); } }
From source file:gov.nih.nci.ncicb.cadsr.contexttree.CDEBrowserTree.java
public DefaultMutableTreeNode buildTree(Hashtable treeParams) throws Exception { DefaultMutableTreeNode tree = null; BaseTreeNode baseNode = null;/*from w ww . jav a 2s .c o m*/ //TimeUtils.recordStartTime("Tree"); try { log.info("Tree Start " + TimeUtils.getEasternTime()); baseNode = new BaseTreeNode(treeParams); CDEBrowserTreeCache cache = CDEBrowserTreeCache.getAnInstance(); cache.init(baseNode, treeParams); WebNode contexts = new WebNode(cache.getIdGen().getNewId(), "caDSR Contexts", "javascript:" + baseNode.getJsFunctionName() + "('P_PARAM_TYPE=P_PARAM_TYPE&P_IDSEQ=P_IDSEQ&" + baseNode.getExtraURLParameters() + "')"); tree = new DefaultMutableTreeNode(contexts); List allContexts = cache.getAllContextHolders(); if (allContexts == null) return tree; ListIterator contextIt = allContexts.listIterator(); while (contextIt.hasNext()) { ContextHolder currContextHolder = (ContextHolder) contextIt.next(); Context currContext = currContextHolder.getContext(); DefaultMutableTreeNode contextNode = currContextHolder.getNode(); //Adding data template nodes DefaultMutableTreeNode tmpLabelNode; DefaultMutableTreeNode otherTempNodes; if (Context.CTEP.equals(currContext.getName())) { cache.initCtepInfo(baseNode, currContext); tmpLabelNode = new DefaultMutableTreeNode( new WebNode(cache.getIdGen().getNewId(), "Protocol Form Templates")); List ctepNodes = cache.getAllTemplatesForCtep(); tmpLabelNode.add((DefaultMutableTreeNode) ctepNodes.get(0)); tmpLabelNode.add((DefaultMutableTreeNode) ctepNodes.get(1)); contextNode.add(tmpLabelNode); log.info("CTEP Templates End " + TimeUtils.getEasternTime()); } else { log.info("Other Templates Start " + TimeUtils.getEasternTime()); otherTempNodes = cache.getTemplateNodes(currContext.getConteIdseq()); if (otherTempNodes != null) { contextNode.add(otherTempNodes); } log.info("Other Templates End " + TimeUtils.getEasternTime()); } //Adding classification nodes long startingTime = System.currentTimeMillis(); log.info("Classification Start " + TimeUtils.getEasternTime()); DefaultMutableTreeNode csNode = cache.getClassificationNodes(currContext.getConteIdseq()); if (csNode != null) contextNode.add(csNode); long timeElsp = System.currentTimeMillis() - startingTime; log.info("Classification Took " + timeElsp); //End Adding Classification Node //Adding protocols nodes //Filtering CTEP context in data element search tree log.info("Proto forms Start " + TimeUtils.getEasternTime()); /** Remove to TT 1892 if ((!currContext.getName().equals(Context.CTEP) && treeType.equals(TreeConstants.DE_SEARCH_TREE)) //Publish Change order || (baseNode.isCTEPUser().equals("Yes") && treeType.equals(TreeConstants.DE_SEARCH_TREE)) || (treeType.equals(TreeConstants.FORM_SEARCH_TREE))) { if ((currContext.getName().equals( Context.CTEP) && baseNode.isCTEPUser().equals("Yes")) || (!currContext.getName().equals(Context.CTEP))) { **/ List protoNodes = cache.getProtocolNodes(currContext.getConteIdseq()); /** for release 3.0.1, forms without protocol is not displayed, uncomment this * code to display them DefaultMutableTreeNode noProtocolFormNode = cache.getProtocolFormNodeWithNoProtocol(currContext.getConteIdseq()); */ DefaultMutableTreeNode protocolFormsLabelNode = null; /** for release 3.0.1, forms without protocol is not displayed, uncomment this * code to display them if ((protoNodes != null && !protoNodes.isEmpty()) || noProtocolFormNode != null ) { */ if ((protoNodes != null && !protoNodes.isEmpty())) { protocolFormsLabelNode = new DefaultMutableTreeNode( new WebNode(cache.getIdGen().getNewId(), "Protocol Forms")); /** for release 3.0.1, forms without protocol is not displayed, uncomment this * code to display them // Add form with no protocol if (noProtocolFormNode != null ) { protocolFormsLabelNode.add(noProtocolFormNode); } */ // Add form with protocol if (protoNodes != null && !protoNodes.isEmpty()) { Iterator tmpIter = protoNodes.iterator(); while (tmpIter.hasNext()) { protocolFormsLabelNode.add((DefaultMutableTreeNode) tmpIter.next()); } } contextNode.add(protocolFormsLabelNode); } /** } TT 1892 }**/ log.info("Proto forms End " + TimeUtils.getEasternTime()); //End Add Protocol Nodes //Display Catalog //Get Publishing Node info log.info("Publish strat " + TimeUtils.getEasternTime()); DefaultMutableTreeNode publishNode = cache.getPublishNode(currContext); if (publishNode != null) contextNode.add(publishNode); log.info("Publish end " + TimeUtils.getEasternTime()); //End Catalog tree.add(contextNode); } log.info("Tree End " + TimeUtils.getEasternTime()); } catch (Exception ex) { ex.printStackTrace(); throw ex; } return tree; }
From source file:org.apache.hawq.pxf.plugins.json.parser.JsonLexerTest.java
public void runTest(File jsonFile, File stateFile) throws IOException { List<String> lexerStates = FileUtils.readLines(stateFile); InputStream jsonInputStream = new FileInputStream(jsonFile); try {/*from w w w . j ava 2 s . c o m*/ JsonLexer lexer = new JsonLexer(); int byteOffset = 0; int i; ListIterator<String> stateIterator = lexerStates.listIterator(); int recurrence = 0; JsonLexer.JsonLexerState expectedState = null; StringBuilder sb = new StringBuilder(); int stateFileLineNum = 0; while ((i = jsonInputStream.read()) != -1) { byteOffset++; char c = (char) i; sb.append(c); lexer.lex(c); if (lexer.getState() == JsonLexer.JsonLexerState.WHITESPACE) { // optimization to skip over multiple whitespaces continue; } if (!stateIterator.hasNext()) { assertFalse(formatStateInfo(jsonFile, sb.toString(), byteOffset, stateFileLineNum) + ": Input stream had character '" + c + "' but no matching state", true); } if (recurrence <= 0) { String state = stateIterator.next().trim(); stateFileLineNum++; while (state.equals("") || state.startsWith("#")) { if (!stateIterator.hasNext()) { assertFalse( formatStateInfo(jsonFile, sb.toString(), byteOffset, stateFileLineNum) + ": Input stream had character '" + c + "' but no matching state", true); } state = stateIterator.next().trim(); stateFileLineNum++; } Matcher m = STATE_RECURRENCE.matcher(state); recurrence = 1; if (m.matches()) { state = m.group(1); recurrence = Integer.valueOf(m.group(2)); } expectedState = JsonLexer.JsonLexerState.valueOf(state); } assertEquals(formatStateInfo(jsonFile, sb.toString(), byteOffset, stateFileLineNum) + ": Issue for char '" + c + "'", expectedState, lexer.getState()); recurrence--; } if (stateIterator.hasNext()) { assertFalse(formatStateInfo(jsonFile, sb.toString(), byteOffset, stateFileLineNum) + ": Input stream has ended but more states were expected: '" + stateIterator.next() + "...'", true); } } finally { IOUtils.closeQuietly(jsonInputStream); } LOG.info("File " + jsonFile.getName() + " passed"); }
From source file:com.asakusafw.runtime.directio.hadoop.HadoopDataSourceUtil.java
private static List<String> stringCrossJoin(List<Set<String>> candidates) { assert candidates != null; assert candidates.isEmpty() == false; List<String> results = new ArrayList<>(); Iterator<Set<String>> iter = candidates.iterator(); assert iter.hasNext(); results.addAll(iter.next());/*from w ww .j a v a2 s . c om*/ while (iter.hasNext()) { Set<String> next = iter.next(); if (next.size() == 1) { String suffix = next.iterator().next(); for (ListIterator<String> i = results.listIterator(); i.hasNext();) { String vaule = i.next(); i.set(vaule + suffix); } } else { List<String> nextResults = new ArrayList<>(); for (String value : results) { for (String suffix : next) { nextResults.add(value + suffix); } } results = nextResults; } } return results; }
From source file:org.apache.fop.layoutmgr.inline.ContentLayoutManager.java
/** * {@inheritDoc}// www . ja v a 2 s.c om */ public void addChildLMs(List newLMs) { if (newLMs == null || newLMs.size() == 0) { return; } ListIterator iter = newLMs.listIterator(); while (iter.hasNext()) { LayoutManager lm = (LayoutManager) iter.next(); addChildLM(lm); } }
From source file:org.drools.planner.examples.pas.solver.move.factory.BedDesignationPillarPartSwapMoveFactory.java
public List<Move> createMoveList(Solution solution) { PatientAdmissionSchedule patientAdmissionSchedule = (PatientAdmissionSchedule) solution; Map<Bed, List<BedDesignation>> bedToBedDesignationList = new HashMap<Bed, List<BedDesignation>>( patientAdmissionSchedule.getBedList().size()); for (BedDesignation bedDesignation : patientAdmissionSchedule.getBedDesignationList()) { List<BedDesignation> bedDesignationListPerBed = bedToBedDesignationList.get(bedDesignation.getBed()); if (bedDesignationListPerBed == null) { // Note: the initialCapacity is probably to high, // which is bad for memory, but the opposite is bad for performance (which is worse) bedDesignationListPerBed = new ArrayList<BedDesignation>( patientAdmissionSchedule.getNightList().size()); bedToBedDesignationList.put(bedDesignation.getBed(), bedDesignationListPerBed); }/*from w w w. ja v a2 s . c o m*/ bedDesignationListPerBed.add(bedDesignation); } for (List<BedDesignation> bedDesignationListPerBed : bedToBedDesignationList.values()) { Collections.sort(bedDesignationListPerBed, new Comparator<BedDesignation>() { public int compare(BedDesignation a, BedDesignation b) { // This comparison is sameBedInSameNight safe. return new CompareToBuilder() .append(a.getAdmissionPart().getFirstNight(), b.getAdmissionPart().getFirstNight()) .append(a.getAdmissionPart().getLastNight(), b.getAdmissionPart().getLastNight()) .append(a.getAdmissionPart(), b.getAdmissionPart()).toComparison(); } }); } List<Bed> bedList = patientAdmissionSchedule.getBedList(); List<Move> moveList = new ArrayList<Move>(); // For every 2 distinct beds for (ListIterator<Bed> leftBedIt = bedList.listIterator(); leftBedIt.hasNext();) { Bed leftBed = leftBedIt.next(); for (ListIterator<Bed> rightBedIt = bedList.listIterator(leftBedIt.nextIndex()); rightBedIt .hasNext();) { Bed rightBed = rightBedIt.next(); List<BedDesignation> leftBedDesignationList = bedToBedDesignationList.get(leftBed); if (leftBedDesignationList == null) { leftBedDesignationList = Collections.emptyList(); } List<BedDesignation> rightBedDesignationList = bedToBedDesignationList.get(rightBed); if (rightBedDesignationList == null) { rightBedDesignationList = Collections.emptyList(); } LowestFirstNightBedDesignationIterator lowestIt = new LowestFirstNightBedDesignationIterator( leftBedDesignationList, rightBedDesignationList); // For every pillar part duo while (lowestIt.hasNext()) { BedDesignation pillarPartBedDesignation = lowestIt.next(); // Note: the initialCapacity is probably to high, // which is bad for memory, but the opposite is bad for performance (which is worse) List<Move> moveListByPillarPartDuo = new ArrayList<Move>( leftBedDesignationList.size() + rightBedDesignationList.size()); int lastNightIndex = pillarPartBedDesignation.getAdmissionPart().getLastNight().getIndex(); Bed otherBed; int leftMinimumFirstNightIndex = Integer.MIN_VALUE; int rightMinimumFirstNightIndex = Integer.MIN_VALUE; if (lowestIt.isLastNextWasLeft()) { otherBed = rightBed; leftMinimumFirstNightIndex = lastNightIndex; } else { otherBed = leftBed; rightMinimumFirstNightIndex = lastNightIndex; } moveListByPillarPartDuo.add(new BedChangeMove(pillarPartBedDesignation, otherBed)); // For every BedDesignation in that pillar part duo while (lowestIt.hasNextWithMaximumFirstNightIndexes(leftMinimumFirstNightIndex, rightMinimumFirstNightIndex)) { pillarPartBedDesignation = lowestIt.next(); lastNightIndex = pillarPartBedDesignation.getAdmissionPart().getLastNight().getIndex(); if (lowestIt.isLastNextWasLeft()) { otherBed = rightBed; leftMinimumFirstNightIndex = Math.max(leftMinimumFirstNightIndex, lastNightIndex); } else { otherBed = leftBed; rightMinimumFirstNightIndex = Math.max(rightMinimumFirstNightIndex, lastNightIndex); } moveListByPillarPartDuo.add(new BedChangeMove(pillarPartBedDesignation, otherBed)); } moveList.add(new CompositeMove(moveListByPillarPartDuo)); } } } return moveList; }
From source file:gr.omadak.leviathan.asp.objects.JsUserDefinedMethod.java
public List getUsedGlobals() { List result = super.getUsedGlobals(); for (ListIterator li = result.listIterator(); li.hasNext();) { String varName = (String) li.next(); if (!usedVars.contains(varName) || hasVar(varName)) { li.remove();/*w ww. ja va 2 s.c o m*/ } } return result; }
From source file:cz.cas.lib.proarc.common.process.GenericExternalProcess.java
void interpolateParameters(List<String> cmdLine) { if (parameters.isEmpty()) { return;//from w ww . j a v a2 s .co m } for (ListIterator<String> it = cmdLine.listIterator(); it.hasNext();) { it.set(interpolateParameters(it.next(), parameters.getMap())); } }
From source file:com.google.gwt.emultest.java.util.ListTestBase.java
public void testListIteratorSetInSeveralPositions() { List l = makeEmptyList(); for (int n = 0; n < 5; n += 2) { l.add(new Integer(n)); }//www . j a v a 2s . co m l.listIterator(); for (int n = 0; n < 3; n++) { l.set(n, new Integer(n)); } for (int n = 0; n < 3; n++) { assertEquals(new Integer(n), l.get(n)); } }