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

The following examples show how to use java.util.Collection#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: Cardumen_0082_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws the domain markers (if any) for an axis and layer.  This method is
 * typically called from within the draw() method.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param index  the renderer index.
 * @param layer  the layer (foreground or background).
 */
protected void drawDomainMarkers(Graphics2D g2, Rectangle2D dataArea,
                                 int index, Layer layer) {

    XYItemRenderer r = getRenderer(index);
    if (r == null) {
        return;
    }
    // check that the renderer has a corresponding dataset (it doesn't
    // matter if the dataset is null)
    if (index >= getDatasetCount()) {
        return;
    }
    Collection markers = getDomainMarkers(index, layer);
    ValueAxis axis = getDomainAxisForDataset(index);
    if (markers != null && axis != null) {
        Iterator iterator = markers.iterator();
        while (iterator.hasNext()) {
            Marker marker = (Marker) iterator.next();
            r.drawDomainMarker(g2, this, axis, marker, dataArea);
        }
    }

}
 
Example 2
Source File: CameraConfigurationUtils.java    From SimplifyReader with Apache License 2.0 6 votes vote down vote up
private static String toString(Collection<int[]> arrays) {
    if (arrays == null || arrays.isEmpty()) {
        return "[]";
    }
    StringBuilder buffer = new StringBuilder();
    buffer.append('[');
    Iterator<int[]> it = arrays.iterator();
    while (it.hasNext()) {
        buffer.append(Arrays.toString(it.next()));
        if (it.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append(']');
    return buffer.toString();
}
 
Example 3
Source File: FieldInfos.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Assumes the field is not storing term vectors
 * @param names The names of the fields
 * @param isIndexed Whether the fields are indexed or not
 *
 * @see #add(String, boolean)
 */
public void add(Collection names, boolean isIndexed) {
  Iterator i = names.iterator();
  int j = 0;
  while (i.hasNext()) {
    add((String)i.next(), isIndexed);
  }
}
 
Example 4
Source File: PurchaseOrderVendorChoiceValuesFinder.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns code/description pairs of all Purchase Order Vendor Choices.
 * 
 * @see org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder#getKeyValues()
 */
public List getKeyValues() {
    KeyValuesService boService = SpringContext.getBean(KeyValuesService.class);
    Collection codes = boService.findAll(PurchaseOrderVendorChoice.class);
    List labels = new ArrayList();
    labels.add(new ConcreteKeyValue(KFSConstants.EMPTY_STRING, KFSConstants.EMPTY_STRING));
    for (Iterator iter = codes.iterator(); iter.hasNext();) {
        PurchaseOrderVendorChoice povc = (PurchaseOrderVendorChoice) iter.next();
        labels.add(new ConcreteKeyValue(povc.getPurchaseOrderVendorChoiceCode(), povc.getPurchaseOrderVendorChoiceDescription()));
    }
    return labels;
}
 
Example 5
Source File: EventQueryNode.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Verify the Subject for all of the patterns is the same.
 *
 * @param patterns - The patterns to check.
 * @throws IllegalStateException If all of the Subjects are not the same.
 */
private static void verifySameSubjects(final Collection<StatementPattern> patterns) throws IllegalStateException {
    requireNonNull(patterns);

    final Iterator<StatementPattern> it = patterns.iterator();
    final Var subject = it.next().getSubjectVar();

    while(it.hasNext()) {
        final StatementPattern pattern = it.next();
        if(!pattern.getSubjectVar().equals(subject)) {
            throw new IllegalStateException("At least one of the patterns has a different subject from the others. " +
                    "All subjects must be the same.");
        }
    }
}
 
Example 6
Source File: SourceView.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isSafeName(String identifier) {
Collection safes = XMLConfig.readSafes("safes.xml");
for(Iterator iter = safes.iterator(); iter.hasNext(); ){
	XMLConfig.SafeDescription safeDesc = (XMLConfig.SafeDescription) iter.next();
	if(safeDesc.getMethodName().equals(identifier)){
		return true;
	}
}
	
// none matched
return false;
  }
 
Example 7
Source File: SortedArrayList.java    From vjtools with Apache License 2.0 5 votes vote down vote up
/**
 * Add all of the elements in the given collection to this list.
 */
@Override
public boolean addAll(Collection<? extends E> c) {
	Iterator<? extends E> i = c.iterator();
	boolean changed = false;
	while (i.hasNext()) {
		boolean ret = add(i.next());
		if (!changed) {
			changed = ret;
		}
	}
	return changed;
}
 
Example 8
Source File: SuperclassesTag.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Override
public Collection process(Collection topics) throws JspTagException {
  // find all superclasses of all topics in collection
  if (topics == null || topics.isEmpty())
    return Collections.EMPTY_SET;
  else {
    HashSet superclasses = new HashSet();
    Iterator iter = topics.iterator();
    TopicIF topic = null;
    Object obj = null;

    while (iter.hasNext()) {
      obj = iter.next();
      try {
        topic = (TopicIF)obj;
      } catch (ClassCastException e) {
        String msg = "SubclassesTag expected to get a input collection of " +
          "topic instances, " +
          "but got instance of class " + obj.getClass().getName();
        throw new NavigatorRuntimeException(msg);
      }

      // ok, the topic cast succeeded, now continue
      if (levelNumber == null)
        // if no level is specified get all of them.
        superclasses.addAll(hierUtils.getSuperclasses(topic));
      else 
        superclasses.addAll(hierUtils.getSuperclasses(topic, levelNumber.intValue()));

    } // while
    return superclasses;
  }
}
 
Example 9
Source File: CoordinatesGenerationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPlaceBusinessRuleTask() {

  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .sequenceFlowId(SEQUENCE_FLOW_ID)
      .businessRuleTask(TASK_ID)
      .done();

  Bounds businessRuleTaskBounds = findBpmnShape(TASK_ID).getBounds();
  assertShapeCoordinates(businessRuleTaskBounds, 186, 78);

  Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge(SEQUENCE_FLOW_ID).getWaypoints();
  Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();

  Waypoint waypoint = iterator.next();
  assertWaypointCoordinates(waypoint, 136, 118);

  while(iterator.hasNext()){
    waypoint = iterator.next();
  }

  assertWaypointCoordinates(waypoint, 186, 118);

}
 
Example 10
Source File: DefaultTemplateFilesResolverTest.java    From spring-soy-view with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveDebugOff() throws Exception {
    defaultTemplateFilesResolver.setTemplatesLocation(new ClassPathResource("templates", getClass().getClassLoader()));
    defaultTemplateFilesResolver.setRecursive(false);
    final Collection<URL> urls = defaultTemplateFilesResolver.resolve();
    Assert.assertEquals("should resolve urls", 3, urls.size());
    final Iterator<URL> it = urls.iterator();
    final URL template1Url = it.next();
    final URL template2Url = it.next();
    final URL template3Url = it.next();
    Assert.assertTrue("template1Url file should end with template1.soy", template1Url.getFile().endsWith("template1.soy"));
    Assert.assertTrue("template2Url file should end with template2.soy", template2Url.getFile().endsWith("template2.soy"));
    Assert.assertTrue("template3Url file should end with template3.soy", template3Url.getFile().endsWith("template3.soy"));
}
 
Example 11
Source File: CustomerOpenItemReportServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This method populates CustomerOpenItemReportDetails for PaymentApplicationDocuments (Customer History Report).
 *
 * @param paymentApplicationIds <=> documentNumbers of PaymentApplicationDocuments
 * @param results <=> CustomerOpenItemReportDetails to display in the report
 * @param details <=> <key = documentNumber, value = customerOpenItemReportDetail>
 */
protected void populateReportDetailsForPaymentApplications(List paymentApplicationIds, List results, Hashtable details) throws WorkflowException {
    Collection paymentApplications = getDocuments(PaymentApplicationDocument.class, paymentApplicationIds);

    for (Iterator itr = paymentApplications.iterator(); itr.hasNext();) {
        PaymentApplicationDocument paymentApplication = (PaymentApplicationDocument) itr.next();
        String documentNumber = paymentApplication.getDocumentNumber();

        CustomerOpenItemReportDetail detail = (CustomerOpenItemReportDetail) details.get(documentNumber);

        // populate Document Description
        String documentDescription = paymentApplication.getDocumentHeader().getDocumentDescription();
        if (ObjectUtils.isNotNull(documentDescription)) {
            detail.setDocumentDescription(documentDescription);
        }
        else {
            detail.setDocumentDescription("");
        }

        // populate Document Payment Amount
        detail.setDocumentPaymentAmount(paymentApplication.getFinancialSystemDocumentHeader().getFinancialDocumentTotalAmount().negated());

        // populate Unpaid/Unapplied Amount if the customer number is the same
        if (ObjectUtils.isNotNull(paymentApplication.getNonAppliedHolding())) {
            if (paymentApplication.getNonAppliedHolding().getCustomerNumber().equals(paymentApplication.getAccountsReceivableDocumentHeader().getCustomerNumber())) {
                detail.setUnpaidUnappliedAmount(paymentApplication.getNonAppliedHolding().getAvailableUnappliedAmount().negated());
            } else {
                detail.setUnpaidUnappliedAmount(KualiDecimal.ZERO);
            }
        } else {
            detail.setUnpaidUnappliedAmount(KualiDecimal.ZERO);
        }

        results.add(detail);
    }
}
 
Example 12
Source File: Symbols.java    From crate with Apache License 2.0 5 votes vote down vote up
public static Streamer<?>[] streamerArray(Collection<? extends Symbol> symbols) {
    Streamer<?>[] streamers = new Streamer<?>[symbols.size()];
    Iterator<? extends Symbol> iter = symbols.iterator();
    for (int i = 0; i < symbols.size(); i++) {
        streamers[i] = iter.next().valueType().streamer();
    }
    return streamers;
}
 
Example 13
Source File: ScopeUtils.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if the ScopedIF's scope intersects with the user
 * context. Note that there is no intersection when either
 * collection is empty.<p>
 *
 * Note that the unconstrained scope is in this case considered an
 * empty set.<p>
 *
 * @param obj The ScopedIF object to compare with.
 * @param context The user context; a collection of TopicIFs.
 *
 * @return boolean; true if the scoped object's scope intersects
 * with the user context.
 */
public static boolean isIntersectionOfContext(ScopedIF obj,
                                              Collection<TopicIF> context) {
  // Get object scope
  Collection<TopicIF> objscope = obj.getScope();

  // Loop over context to see if there is an intersection with the object scope.
  Iterator<TopicIF> iter = context.iterator();
  while (iter.hasNext()) {
    // If object scope contains context theme then there is an intersection.
    if (objscope.contains(iter.next())) return true;
  }
  // There is no intersection with the object scope.
  return false;
}
 
Example 14
Source File: ArraySet.java    From springreplugin with Apache License 2.0 5 votes vote down vote up
/**
 * Determine if the array set contains all of the values in the given collection.
 *
 * @param collection The collection whose contents are to be checked against.
 * @return Returns true if this array set contains a value for every entry
 * in <var>collection</var>, else returns false.
 */
@Override
public boolean containsAll(Collection<?> collection) {
    Iterator<?> it = collection.iterator();
    while (it.hasNext()) {
        if (!contains(it.next())) {
            return false;
        }
    }
    return true;
}
 
Example 15
Source File: DefaultValueStyler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String style(Collection<?> value) {
	StringBuilder result = new StringBuilder(value.size() * 8 + 16);
	result.append(getCollectionTypeString(value)).append('[');
	for (Iterator<?> i = value.iterator(); i.hasNext();) {
		result.append(style(i.next()));
		if (i.hasNext()) {
			result.append(',').append(' ');
		}
	}
	if (value.isEmpty()) {
		result.append(EMPTY);
	}
	result.append("]");
	return result.toString();
}
 
Example 16
Source File: FileLatency.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static ArrayWritable makeWritable(Collection<?> writables, Class<? extends Writable> impl) {
    Writable[] array = new Writable[writables.size()];
    Iterator<?> writable = writables.iterator();
    for (int i = 0; i < array.length; ++i)
        array[i] = (Writable) writable.next();
    ArrayWritable arrayWritable = new ArrayWritable(impl);
    arrayWritable.set(array);
    return arrayWritable;
}
 
Example 17
Source File: UserInvitationPane.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
 * Removes oneself as an owner of the room.
 *
 * @param muc the <code>MultiUserChat</code> of the chat room.
 */
private void removeOwner(MultiUserChat muc) {
    if (muc.isJoined()) {
        // Try and remove myself as an owner if I am one.
        Collection<Affiliate> owners = null;
        try {
            owners = muc.getOwners();
        }
        catch (XMPPException | SmackException | InterruptedException e1) {
            return;
        }

        if (owners == null) {
            return;
        }

        Iterator<Affiliate> iter = owners.iterator();

        List<Jid> list = new ArrayList<>();
        while (iter.hasNext()) {
            Affiliate affilitate = iter.next();
            Jid jid = affilitate.getJid();
            if (!jid.equals(SparkManager.getSessionManager().getBareUserAddress())) {
                list.add(jid);
            }
        }
        if (list.size() > 0) {
            try {
                Form form = muc.getConfigurationForm().createAnswerForm();
                List<String> jidStrings = JidUtil.toStringList(list);
                form.setAnswer("muc#roomconfig_roomowners", jidStrings);

                // new DataFormDialog(groupChat, form);
                muc.sendConfigurationForm(form);
            }
            catch (XMPPException | SmackException | InterruptedException e) {
                Log.error(e);
            }
        }
    }
}
 
Example 18
Source File: CsvClassAssignmentExport.java    From unitime with Apache License 2.0 4 votes vote down vote up
public static CSVFile exportCsv(UserContext user, Collection classes, ClassAssignmentProxy proxy) {
	CSVFile file = new CSVFile();
	String instructorFormat = user.getProperty(UserProperty.NameFormat);
	file.setSeparator(",");
	file.setQuotationMark("\"");
	file.setHeader(new CSVField[] {
			new CSVField("COURSE"),
			new CSVField("ITYPE"),
			new CSVField("SECTION"),
			new CSVField("SUFFIX"),
			new CSVField("EXTERNAL_ID"),
			new CSVField("ENROLLMENT"),
			new CSVField("LIMIT"),
			new CSVField("DATE_PATTERN"),
			new CSVField("DAY"),
			new CSVField("START_TIME"),
			new CSVField("END_TIME"),
			new CSVField("ROOM"),
			new CSVField("INSTRUCTOR"),
			new CSVField("SCHEDULE_NOTE")
		});
	
	for (Iterator i=classes.iterator();i.hasNext();) {
		Object[] o = (Object[])i.next(); Class_ clazz = (Class_)o[0]; CourseOffering co = (CourseOffering)o[1];
		StringBuffer leadsSb = new StringBuffer();
		if (clazz.isDisplayInstructor()) 
		for (ClassInstructor ci: clazz.getClassInstructors()) {
			if (!leadsSb.toString().isEmpty())
				leadsSb.append("\n");
			DepartmentalInstructor instructor = ci.getInstructor();
			leadsSb.append(instructor.getName(instructorFormat));
		}
           String divSec = clazz.getClassSuffix(co);
		Assignment assignment = null;
		try {
			assignment = proxy.getAssignment(clazz);
		} catch (Exception e) {
			Debug.error(e);
		}
		if (assignment!=null) {
			Placement placement = assignment.getPlacement();
			file.addLine(new CSVField[] {
					new CSVField(co.getCourseName()),
					new CSVField(clazz.getItypeDesc()),
					new CSVField(clazz.getSectionNumber()),
					new CSVField(clazz.getSchedulingSubpart().getSchedulingSubpartSuffix()),
					new CSVField(divSec),
					new CSVField(clazz.getEnrollment()),
					new CSVField(clazz.getClassLimit(proxy)),
					new CSVField(assignment.getDatePattern().getName()),
					new CSVField(placement.getTimeLocation().getDayHeader()),
					new CSVField(placement.getTimeLocation().getStartTimeHeader(CONSTANTS.useAmPm())),
					new CSVField(placement.getTimeLocation().getEndTimeHeader(CONSTANTS.useAmPm())),
					new CSVField(placement.getRoomName(",")),
					new CSVField(leadsSb),
					new CSVField(clazz.getSchedulePrintNote()==null?"":clazz.getSchedulePrintNote())
			});
		} else {
			DurationModel dm = clazz.getSchedulingSubpart().getInstrOfferingConfig().getDurationModel();
               Integer arrHrs = dm.getArrangedHours(clazz.getSchedulingSubpart().getMinutesPerWk(), clazz.effectiveDatePattern());
			file.addLine(new CSVField[] {
					new CSVField(co.getCourseName()),
					new CSVField(clazz.getItypeDesc()),
					new CSVField(clazz.getSectionNumber()),
					new CSVField(clazz.getSchedulingSubpart().getSchedulingSubpartSuffix()),
					new CSVField(divSec),
					new CSVField(clazz.getEnrollment()),
					new CSVField(clazz.getClassLimit(proxy)),
					new CSVField(clazz.effectiveDatePattern().getName()),
					new CSVField("Arr "+(arrHrs==null?"":arrHrs+" ")+"Hrs"),
					new CSVField(""),
					new CSVField(""),
					new CSVField(""),
					new CSVField(leadsSb),
					new CSVField(clazz.getSchedulePrintNote()==null?"":clazz.getSchedulePrintNote())
			});
		}
	}
	return file;
}
 
Example 19
Source File: GenomePositionSelectorIteratorImpl.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
GenomePositionSelectorIteratorImpl(@NotNull Collection<P> positions) {
    this.positions = positions.iterator();
    next = this.positions.hasNext() ? this.positions.next() : null;
}
 
Example 20
Source File: Validate.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Validate an argument, throwing <code>IllegalArgumentException</code>
 * if the argument collection  is <code>null</code> or has elements that
 * are not of type <code>clazz</code> or a subclass.</p>
 *
 * <pre>
 * Validate.allElementsOfType(collection, String.class, "Collection has invalid elements");
 * </pre>
 *
 * @param collection  the collection to check, not null
 * @param clazz  the <code>Class</code> which the collection's elements are expected to be, not null
 * @param message  the exception message if the <code>Collection</code> has elements not of type <code>clazz</code>
 * @since 2.1
 */
public static void allElementsOfType(Collection collection, Class clazz, String message) {
    Validate.notNull(collection);
    Validate.notNull(clazz);
    for (Iterator it = collection.iterator(); it.hasNext(); ) {
        if (clazz.isInstance(it.next()) == false) {
            throw new IllegalArgumentException(message);
        }
    }
}