Java Code Examples for java.util.List#iterator()

The following examples show how to use java.util.List#iterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MergeExecutionCourses.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void copyShifts(final ExecutionCourse executionCourseFrom, final ExecutionCourse executionCourseTo) {
    final List<Shift> associatedShifts = new ArrayList<>(executionCourseFrom.getAssociatedShifts());
    for (final Shift shift : associatedShifts) {
        List<CourseLoad> courseLoadsFrom = new ArrayList<>(shift.getCourseLoadsSet());
        for (Iterator<CourseLoad> iter = courseLoadsFrom.iterator(); iter.hasNext();) {
            CourseLoad courseLoadFrom = iter.next();
            CourseLoad courseLoadTo = executionCourseTo.getCourseLoadByShiftType(courseLoadFrom.getType());
            if (courseLoadTo == null) {
                courseLoadTo =
                        new CourseLoad(executionCourseTo, courseLoadFrom.getType(), courseLoadFrom.getUnitQuantity(),
                                courseLoadFrom.getTotalQuantity());
            }
            iter.remove();
            shift.removeCourseLoads(courseLoadFrom);
            shift.addCourseLoads(courseLoadTo);
        }
    }
}
 
Example 2
Source File: CacheHelper.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Generates dummy functions from the given cache and function list.
 */
private static void generateDummyFunctions(Cache dummyCache, List functions,
                                                             String fn) {
  if (functions != null) {
    // create and configure the dummy functions
    log("Adding dummy functions: " + functions);
    FunctionServiceCreation fsc = new FunctionServiceCreation();
    for (Iterator i = functions.iterator(); i.hasNext();) {
      Function function = (Function)i.next();
      fsc.registerFunction(function);
    }
    //fsc.create(); // not needed, functions are registered during createCacheWithXml
    ((CacheCreation)dummyCache).setFunctionServiceCreation(fsc);
    log("Added dummy functions: " + fsc.getFunctions());

    // save the functions for future reference
    XmlFunctionConfigs.put(fn, classnamesFor(functions));
  }
}
 
Example 3
Source File: Chart_19_CategoryPlot_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns a list of the categories that should be displayed for the
 * specified axis.
 * 
 * @param axis  the axis (<code>null</code> not permitted)
 * 
 * @return The categories.
 * 
 * @since 1.0.3
 */
public List getCategoriesForAxis(CategoryAxis axis) {
    List result = new ArrayList();
    int axisIndex = this.domainAxes.indexOf(axis);
    List datasets = datasetsMappedToDomainAxis(axisIndex);
    Iterator iterator = datasets.iterator();
    while (iterator.hasNext()) {
        CategoryDataset dataset = (CategoryDataset) iterator.next();
        // add the unique categories from this dataset
        for (int i = 0; i < dataset.getColumnCount(); i++) {
            Comparable category = dataset.getColumnKey(i);
            if (!result.contains(category)) {
                result.add(category);
            }
        }
    }
    return result;
}
 
Example 4
Source File: URLStringCatFunction.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Checks the inputs of this function assuming no parameters are bags.
 * 
 * @param inputs a <code>List></code> of <code>Evaluatable</code>s
 * 
 * @throws IllegalArgumentException if the inputs won't work
 */
public void checkInputsNoBag(List inputs) throws IllegalArgumentException {
	// make sure it's long enough
	if (inputs.size() < 2)
		throw new IllegalArgumentException("not enough args to " + NAME_URI_STRING_CONCATENATE);

	// check that the parameters are of the correct types...
	Iterator it = inputs.iterator();

	// ...the first argument must be a URI...
	if (!((Expression) (it.next())).getType().toString().equals(AnyURIAttribute.identifier))
		throw new IllegalArgumentException("illegal parameter");

	// ...and all following arguments must be strings
	while (it.hasNext()) {
		if (!((Expression) (it.next())).getType().toString().equals(StringAttribute.identifier))
			throw new IllegalArgumentException("illegal parameter");
	}
}
 
Example 5
Source File: ConditionalLoop.java    From JDeodorant with MIT License 6 votes vote down vote up
private static List<ASTNode> getAllVariableModifiersInParentBlock(SimpleName variable, Block block)
{
	List<ASTNode> bodyVariableModifiers = new ArrayList<ASTNode>();
	ExpressionExtractor expressionExtractor = new ExpressionExtractor();
	bodyVariableModifiers.addAll(expressionExtractor.getAssignments(block));
	// remove all variable updaters that are not modifying the specified variable or are after the position of the variable in use
	Iterator<ASTNode> it = bodyVariableModifiers.iterator();
	while (it.hasNext())
	{
		ASTNode currentNode = it.next();
		if (currentNode instanceof Expression)
		{
			Expression currentExpression = (Expression) currentNode;
			if (!AbstractLoopUtilities.isUpdatingVariable(currentExpression, variable) || currentExpression.getStartPosition() >= variable.getStartPosition())
			{
				it.remove();
			}
		}
	}
	return bodyVariableModifiers;
}
 
Example 6
Source File: ResourceDAO.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public HashMap<String, Object> getAttributesWithUri(String uri,
		List<String> attrNames) throws OneM2MException {

	MongoCollection<Document> collection = context.getDatabaseManager()
			.getCollection(collectionName);
	Document doc = collection.find(new BasicDBObject(URI_KEY, uri)).first();

	if (doc == null) {
		throw new OneM2MException(RESPONSE_STATUS.NOT_FOUND,
				"resource not found");
	}

	HashMap<String, Object> results = new HashMap<String, Object>();
	Iterator<String> it = attrNames.iterator();
	while (it.hasNext()) {
		String attr = it.next();
		results.put(attr, doc.get(attr));
	}

	return results;

}
 
Example 7
Source File: ParameterList.java    From openid4java with Apache License 2.0 6 votes vote down vote up
/**
 * @return The key-value form encoding of for this ParameterList.
 */
public String toString()
{
    StringBuffer allParams = new StringBuffer("");

    List parameters = getParameters();
    Iterator iterator = parameters.iterator();
    while (iterator.hasNext())
    {
        Parameter parameter = (Parameter) iterator.next();
        allParams.append(parameter.getKey());
        allParams.append(':');
        allParams.append(parameter.getValue());
        allParams.append('\n');
    }

    return allParams.toString();
}
 
Example 8
Source File: ConcreteMethodImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public List<LocalVariable> arguments() throws AbsentInformationException {
    List<LocalVariable> variables = getVariables();

    List<LocalVariable> retList = new ArrayList<LocalVariable>(variables.size());
    Iterator<LocalVariable> iter = variables.iterator();
    while(iter.hasNext()) {
        LocalVariable variable = iter.next();
        if (variable.isArgument()) {
            retList.add(variable);
        }
    }
    return retList;
}
 
Example 9
Source File: CacheControlHeaderProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void handleFields(List<String> fields, StringBuilder sb) {
    if (fields.isEmpty()) {
        return;
    }
    sb.append('=');
    sb.append('\"');
    for (Iterator<String> it = fields.iterator(); it.hasNext();) {
        sb.append(it.next());
        if (it.hasNext()) {
            sb.append(',');
        }
    }
    sb.append('\"');
}
 
Example 10
Source File: EfficiencyStatementManager.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Get the passed value of a course node of a specific efficiency statment
 * 
 * @param nodeIdent
 * @param efficiencyStatement
 * @return true if passed, false if not, null if node not found
 */
public Boolean getPassed(final String nodeIdent, final EfficiencyStatement efficiencyStatement) {
    final List<Map<String, Object>> assessmentNodes = efficiencyStatement.getAssessmentNodes();
    if (assessmentNodes != null) {
        final Iterator<Map<String, Object>> iter = assessmentNodes.iterator();
        while (iter.hasNext()) {
            final Map<String, Object> nodeData = iter.next();
            if (nodeData.get(AssessmentHelper.KEY_IDENTIFYER).equals(nodeIdent)) {
                return (Boolean) nodeData.get(AssessmentHelper.KEY_PASSED);
            }
        }
    }
    return null;
}
 
Example 11
Source File: PeekingIterator.java    From LeetCode-Solution-in-Good-Style with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    List<Integer> list = new ArrayList<>();
    list.add(1);
    list.add(2);
    list.add(3);
    Iterator<Integer> iterator = list.iterator();
    PeekingIterator peekingIterator = new PeekingIterator(iterator);
    Integer peek1 = peekingIterator.peek();
    System.out.println(peek1);

    Integer peek2 = peekingIterator.peek();
    System.out.println(peek2);

    Integer peek3 = peekingIterator.peek();
    System.out.println(peek3);

    Integer peek4 = peekingIterator.peek();
    System.out.println(peek4);

    Integer next1 = peekingIterator.next();
    System.out.println(next1);

    Integer peek5 = peekingIterator.peek();
    System.out.println(peek5);

    Integer next2 = peekingIterator.next();
    System.out.println(next2);
    Integer next3 = peekingIterator.next();
    System.out.println(next3);
}
 
Example 12
Source File: DepartmentalInstructor.java    From unitime with Apache License 2.0 5 votes vote down vote up
public DepartmentalInstructor getNextDepartmentalInstructor(SessionContext context, Right right) throws Exception {
	List instructors = DepartmentalInstructor.findInstructorsForDepartment(getDepartment().getUniqueId());
	DepartmentalInstructor next = null;
	for (Iterator i=instructors.iterator();i.hasNext();) {
		DepartmentalInstructor di = (DepartmentalInstructor)i.next();
		if (right != null && !context.hasPermission(Department.class.equals(right.type()) ? di.getDepartment() : di, right)) continue;
		if (this.compareTo(di)>=0) continue;
		if (next==null || next.compareTo(di)>0)
			next = di;
	}
	return next;
}
 
Example 13
Source File: XDropTargetRegistry.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void registerProtocols(long embedder, boolean protocols,
                               List<XDropTargetProtocol> supportedProtocols) {
    Iterator dropTargetProtocols = null;

    /*
     * By default, we register a drop site that supports all dnd
     * protocols. This approach is not appropriate in plugin
     * scenario if the browser supports Motif DnD and doesn't support
     * XDnD. If we forcibly set XdndAware on the browser toplevel, any drag
     * source that supports both protocols and prefers XDnD will be unable
     * to drop anything on the browser.
     * The solution for this problem is not to register XDnD drop site
     * if the browser supports only Motif DnD.
     * In general, if the browser already supports some protocols, we
     * register the embedded drop site only for those protocols. Otherwise
     * we register the embedded drop site for all protocols.
     */
    if (!supportedProtocols.isEmpty()) {
        dropTargetProtocols = supportedProtocols.iterator();
    } else {
        dropTargetProtocols =
            XDragAndDropProtocols.getDropTargetProtocols();
    }

    /* Grab server, since we are working with the window that belongs to
       another client. */
    XlibWrapper.XGrabServer(XToolkit.getDisplay());
    try {
        while (dropTargetProtocols.hasNext()) {
            XDropTargetProtocol dropTargetProtocol =
                (XDropTargetProtocol)dropTargetProtocols.next();
            if ((protocols == XEMBED_PROTOCOLS) ==
                dropTargetProtocol.isXEmbedSupported()) {
                dropTargetProtocol.registerEmbedderDropSite(embedder);
            }
        }
    } finally {
        XlibWrapper.XUngrabServer(XToolkit.getDisplay());
    }
}
 
Example 14
Source File: PubmedArchiveCollectionReader2.java    From bluima with Apache License 2.0 5 votes vote down vote up
public boolean hasNext() throws IOException, CollectionException {
    if (articlesIt != null && articlesIt.hasNext()) {
        return true;
    } else {
        if (super.hasNext()) {
            // try to fetch
            File f = fileIterator.next();
            FileObject archive = fsManager.resolveFile("gz:file://"
                    + f.getAbsolutePath());
            FileObject fo = archive.getChildren()[0];
            LOG.debug("extracted file {} from archive {}", fo.getName(),
                    f.getName());
            if (fo.isReadable() && fo.getType() == FileType.FILE) {
                FileContent fc = fo.getContent();
                List<MedlineCitation> articles = xmlArticleParser
                        .parseAsArticles(fc.getInputStream());
                articlesIt = articles.iterator();
                if (articlesIt.hasNext()) {
                    return true;
                } else { // empty, try next file
                    return hasNext();
                }
            }
        }
    }
    return false;
}
 
Example 15
Source File: GatewayHubStatus.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected void initializeGatewayStatuses(GatewayHub hub) {
  List gateways = hub.getGateways();
  this._gatewayStatuses = new GatewayStatus[gateways.size()];
  int i = 0;
  for (Iterator gatewaysIterator = gateways.iterator(); gatewaysIterator.hasNext(); i++) {
    Gateway gateway = (Gateway) gatewaysIterator.next();
    this._gatewayStatuses[i] = new GatewayStatus(gateway);
  }
}
 
Example 16
Source File: StatisticsKeeperIterationHandlerCollection.java    From iaf with Apache License 2.0 5 votes vote down vote up
public void closeGroup(Object data) throws SenderException {
	if (trace && log.isDebugEnabled()) log.debug("closeGroup()");
	List sessionData=(List)data;
	Iterator sessionDataIterator=sessionData.iterator();
	for (Iterator it=iterationHandlerList.iterator();it.hasNext();) {
		StatisticsKeeperIterationHandler handler=(StatisticsKeeperIterationHandler)it.next();
		handler.closeGroup(sessionDataIterator.next());
	}
}
 
Example 17
Source File: MultipleDiagnosticSubjects.java    From FreeBuilder with Apache License 2.0 4 votes vote down vote up
private MultipleDiagnosticSubjects(List<Diagnostic<? extends JavaFileObject>> diagnostics) {
  this.diagnostics = diagnostics;
  this.nextCandidate = diagnostics.iterator();
  this.candidate = nextCandidate.next();
}
 
Example 18
Source File: SubscriberDaoITCaseNew.java    From olat with Apache License 2.0 4 votes vote down vote up
@Test
public void getSubscriberIDsByEventStatus_findsNone() {
    List<Long> subscriberIDs = subscriberDao.getSubscriberIDsByEventStatus(NotificationEvent.Status.WAITING);
    Iterator<Long> idsIterator = subscriberIDs.iterator();
    assertFalse(idsIterator.hasNext());
}
 
Example 19
Source File: CategoryAxis.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a temporary list of ticks that can be used when drawing the axis.
 *
 * @param g2  the graphics device (used to get font measurements).
 * @param state  the axis state.
 * @param dataArea  the area inside the axes.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
@Override
public List refreshTicks(Graphics2D g2, AxisState state, 
        Rectangle2D dataArea, RectangleEdge edge) {

    List ticks = new java.util.ArrayList();

    // sanity check for data area...
    if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
        return ticks;
    }

    CategoryPlot plot = (CategoryPlot) getPlot();
    List categories = plot.getCategoriesForAxis(this);
    double max = 0.0;

    if (categories != null) {
        CategoryLabelPosition position
                = this.categoryLabelPositions.getLabelPosition(edge);
        float r = this.maximumCategoryLabelWidthRatio;
        if (r <= 0.0) {
            r = position.getWidthRatio();
        }

        float l;
        if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
            l = (float) calculateCategorySize(categories.size(), dataArea,
                    edge);
        }
        else {
            if (RectangleEdge.isLeftOrRight(edge)) {
                l = (float) dataArea.getWidth();
            }
            else {
                l = (float) dataArea.getHeight();
            }
        }
        int categoryIndex = 0;
        Iterator iterator = categories.iterator();
        while (iterator.hasNext()) {
            Comparable category = (Comparable) iterator.next();
            g2.setFont(getTickLabelFont(category));
            TextBlock label = createLabel(category, l * r, edge, g2);
            if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                max = Math.max(max, calculateTextBlockHeight(label,
                        position, g2));
            }
            else if (edge == RectangleEdge.LEFT
                    || edge == RectangleEdge.RIGHT) {
                max = Math.max(max, calculateTextBlockWidth(label,
                        position, g2));
            }
            Tick tick = new CategoryTick(category, label,
                    position.getLabelAnchor(),
                    position.getRotationAnchor(), position.getAngle());
            ticks.add(tick);
            categoryIndex = categoryIndex + 1;
        }
    }
    state.setMax(max);
    return ticks;

}
 
Example 20
Source File: SegmentedTimeline.java    From ccu-historian with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Adds a list of dates as segment exceptions. Each exception segment is
 * defined as a segment to exclude from what would otherwise be considered
 * a valid segment of the timeline.  An exception segment can not be
 * contained inside an already excluded segment.  If so, no action will
 * occur (the proposed exception segment will be discarded).
 * <p>
 * The segment is identified by a Date into any part of the segment.
 *
 * @param exceptionList  List of Date objects that identify the segments to
 *                       exclude.
 */
public void addExceptions(List exceptionList) {
    for (Iterator iter = exceptionList.iterator(); iter.hasNext();) {
        addException((Date) iter.next());
    }
}