当前位置: 首页>>代码示例>>Java>>正文


Java IteratorUtils.getIterator方法代码示例

本文整理汇总了Java中org.apache.commons.collections.IteratorUtils.getIterator方法的典型用法代码示例。如果您正苦于以下问题:Java IteratorUtils.getIterator方法的具体用法?Java IteratorUtils.getIterator怎么用?Java IteratorUtils.getIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.collections.IteratorUtils的用法示例。


在下文中一共展示了IteratorUtils.getIterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readAsString

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
@Override
public String readAsString(final Object object) {
    final StringBuilder sb = new StringBuilder();
    sb.append('[');
    final Converter<T> converter = resolveConverter();
    for (final Iterator<?> it = IteratorUtils.getIterator(object); it.hasNext();) {
        final Object value = it.next();
        final T baseValue = CoercionHelper.coerce(elementType, value);
        sb.append('"').append(converter.toString(baseValue)).append('"');
        if (it.hasNext()) {
            sb.append(',');
        }
    }
    sb.append(']');
    return sb.toString();
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:17,代码来源:SimpleCollectionBinder.java

示例2: writeAsString

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
@Override
public void writeAsString(final Object object, final Object value) {
    validateNestedBinders();
    final Map<String, String> values = new HashMap<String, String>();
    if (value instanceof Map<?, ?>) {
        for (final Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
            final String keyAsString = keyBinder.readAsString(Collections.singletonMap(keyBinder.getPath(), entry.getKey()));
            final String valueAsString = valueBinder.readAsString(Collections.singletonMap(valueBinder.getPath(), entry.getValue()));
            values.put(keyAsString, valueAsString);
        }
    } else {
        for (final Iterator<?> it = IteratorUtils.getIterator(value); it.hasNext();) {
            final Object current = it.next();
            values.put(keyBinder.readAsString(current), valueBinder.readAsString(current));
        }
    }
    doWrite(object, values);
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:19,代码来源:MapBinder.java

示例3: coerceCollection

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
/**
    * Converts an object to a collection of the given type, using the given element type
    * @return The resulting collection - it may be empty, but never null
    */
   @SuppressWarnings({ "unchecked", "rawtypes" })
   public static <T> Collection<T> coerceCollection(final Class<T> elementType, final Class<? extends Collection> collectionType, final Object value) {
final ArrayList<T> al = new ArrayList<T>();
       //final Collection<T> collection = ClassHelper.instantiate(collectionType == null ? al.getClass() : collectionType);
Collection<T> collection;
if(collectionType == null) {
	collection = ClassHelper.instantiate(al.getClass());
} else {
	collection = ClassHelper.instantiate(collectionType);
}

       final Iterator<?> iterator = IteratorUtils.getIterator(value);
       while (iterator.hasNext()) {
           collection.add(coerce(elementType, iterator.next()));
       }
       return collection;
   }
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:22,代码来源:CoercionHelper.java

示例4: getListFromObject

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
/**
 * create an iterator on a given object (Collection, Enumeration, array, single Object) and crop the resulting list
 * according to the startIndex and numberOfItems parameters.
 * @param iterableObject Collection, Enumeration or array to crop
 * @param startIndex int starting index
 * @param numberOfItems int number of items to keep in the list
 * @return List with values taken from the given object, cropped according the startIndex and numberOfItems
 * parameters
 */
public static List<Object> getListFromObject(Object iterableObject, int startIndex, int numberOfItems)
{
    if (iterableObject instanceof List)
    {
        // easier, use sublist
        List<Object> list = ((List<Object>) iterableObject);

        // check for partial lists
        int lastRecordExclusive = numberOfItems <= 0 ? list.size() : startIndex + numberOfItems;
        if (lastRecordExclusive > list.size())
        {
            lastRecordExclusive = list.size();
        }

        if (startIndex < list.size())
        {
            return list.subList(startIndex, lastRecordExclusive);
        }
    }

    // use an iterator
    Iterator< ? > iterator = IteratorUtils.getIterator(iterableObject);
    return getSubList(iterator, startIndex, numberOfItems);
}
 
开发者ID:webbfontaine,项目名称:displaytag,代码行数:34,代码来源:CollectionUtil.java

示例5: updateByChannels

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
/**
 * This method inserts/updates tasks by the channels in an errata. This method
 * corresponds to {@literal ChannelEditor.pm -> schedule_errata_cache_update}
 * method in the perl codebase.
 */
public void updateByChannels() {
    //Get the channels for this errata
    Set channels = errata.getChannels();

    //Loop through the channels and either insert or update a task
    Iterator itr = IteratorUtils.getIterator(channels);
    while (itr.hasNext()) {
        Channel channel = (Channel) itr.next();

        //Look to see if task already exists...
        Task task = TaskFactory.lookup(org, ErrataCacheWorker.BY_CHANNEL, channel
                .getId());
        if (task == null) { //if not, create a new task
            task = TaskFactory.createTask(org, ErrataCacheWorker.BY_CHANNEL, channel
                    .getId());
        }
        else { //if so, update the earliest column
            task.setEarliest(new Date(System.currentTimeMillis() + DELAY));
        }
        //save the task
        TaskFactory.save(task);
    }
}
 
开发者ID:spacewalkproject,项目名称:spacewalk,代码行数:29,代码来源:TaskScheduler.java

示例6: readAsString

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
@Override
public String readAsString(final Object object) {
    validateElementBinder();
    final StringBuilder sb = new StringBuilder();
    sb.append('[');
    for (final Iterator<?> it = IteratorUtils.getIterator(object); it.hasNext();) {
        final Object value = it.next();
        sb.append(elementBinder.readAsString(value));
        if (it.hasNext()) {
            sb.append(',');
        }
    }
    sb.append(']');
    return sb.toString();
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:16,代码来源:BeanCollectionBinder.java

示例7: writeAsString

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
@Override
public void writeAsString(final Object object, final Object value) {
    validateElementBinder();
    final Collection<String> values = instantiateCollection();
    for (final Iterator<?> it = IteratorUtils.getIterator(object); it.hasNext();) {
        final Object current = it.next();
        values.add(elementBinder.readAsString(current));
    }
    doWrite(object, values, true);
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:11,代码来源:BeanCollectionBinder.java

示例8: readAsString

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
@Override
public String readAsString(final Object object) {
    validateNestedBinders();
    final StringBuilder sb = new StringBuilder();
    sb.append('{');
    for (final Iterator<?> it = IteratorUtils.getIterator(object); it.hasNext();) {
        final Object value = it.next();
        sb.append(keyBinder.readAsString(value)).append('=').append(valueBinder.readAsString(value));
        if (it.hasNext()) {
            sb.append(',');
        }
    }
    sb.append('}');
    return sb.toString();
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:16,代码来源:MapBinder.java

示例9: setSelected

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void setSelected(final Object object) {
    if (object == null) {
        selectedValues = null;
    } else {
        final Iterator<Object> it = IteratorUtils.getIterator(object);
        selectedValues = new ArrayList<String>();
        while (it.hasNext()) {
            selectedValues.add(CoercionHelper.coerce(String.class, it.next()));
        }
    }
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:13,代码来源:MultiDropDownTag.java

示例10: apply

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
@Override
public String apply(T object, Object value) {
    StringBuffer sb = new StringBuffer();
    if (value != null && value instanceof Iterable) {
        Iterator<?> iterator = IteratorUtils.getIterator(value);
        while (iterator.hasNext()) {
            sb.append(getSubColumnFormatter().apply(object, iterator.next()));
        }
    }
    return sb.toString();
}
 
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:12,代码来源:IterableFormatter.java

示例11: getIterator

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
public Iterator<Object> getIterator(Object data)
{
    if (data instanceof List)
    {
        return getIterator((List<Object>) data);
    }

    return IteratorUtils.getIterator(data);
}
 
开发者ID:webbfontaine,项目名称:displaytag,代码行数:10,代码来源:PaginationHelper.java

示例12: clearChannels

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void clearChannels() {
    if (this.getChannels() != null) {
        this.getChannels().clear();
    }
    Iterator<ErrataFile> i = IteratorUtils.getIterator(this.getFiles());
    while (i.hasNext()) {
        PublishedErrataFile pf = (PublishedErrataFile) i.next();
        pf.getChannels().clear();
    }
}
 
开发者ID:spacewalkproject,项目名称:spacewalk,代码行数:14,代码来源:AbstractErrata.java

示例13: formatObject

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
/**
 * Format an object
 */
public static String formatObject(final Object object, final String defaultValue, final String emptyValue) {
    if (object == null) {
        return defaultValue;
    }
    try {
        if (object instanceof Number) {
            if ((object instanceof Float) || (object instanceof Double) || (object instanceof BigDecimal)) {
                return FLOAT_FORMAT.format(((Number) object).doubleValue());
            }
            return INTEGER_FORMAT.format(((Number) object).longValue());
        } else if ((object instanceof Calendar) || (object instanceof Date)) {
            final Date date = (object instanceof Calendar) ? ((Calendar) object).getTime() : (Date) object;
            final Date truncated = DateUtils.truncate(date, Calendar.DATE);
            if (date.equals(truncated)) {
                return DATE_FORMAT.format(date);
            } else {
                return DATE_TIME_FORMAT.format(date);
            }
        } else if (object instanceof Collection<?> || object instanceof Map<?, ?> || object.getClass().isArray()) {
            if (object instanceof Iterator<?>) {
                return "<iterator>";
            } else if (Persistence.getPersistenceUtil().isLoaded(object)) {
                Iterator<?> iterator;
                if (object instanceof Map<?, ?>) {
                    iterator = ((Map<?, ?>) object).entrySet().iterator();
                } else {
                    iterator = IteratorUtils.getIterator(object);
                }
                final StringBuilder sb = new StringBuilder();
                sb.append('[');
                while (iterator.hasNext()) {
                    sb.append(formatArgument(iterator.next()));
                    if (iterator.hasNext()) {
                        sb.append(", ");
                    }
                }
                sb.append(']');
                return sb.toString();
            } else {
                return "<uninitialized collection>";
            }
        } else if (object instanceof String) {
            return "".equals("object") ? emptyValue : (String) object;
        } else if (object instanceof Boolean) {
            return object.toString();
        } else if ((object instanceof Entity) && (object instanceof EntityReference) || !Persistence.getPersistenceUtil().isLoaded(object)) {
            return ClassHelper.getClassName(EntityHelper.getRealClass((Entity) object)) + '#' + ((Entity) object).getId();
        } else {
            return object.toString();
        }
    } catch (final Exception e) {
        return defaultValue;
    }
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:58,代码来源:FormatObject.java

示例14: describeEmptyTable

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
/**
 * If no columns are provided, automatically add them from bean properties. Get the first object in the list and get
 * all the properties (except the "class" property which is automatically skipped). Of course this isn't possible
 * for empty lists.
 */
private void describeEmptyTable()
{
    this.tableIterator = IteratorUtils.getIterator(this.list);

    if (this.tableIterator.hasNext())
    {
        Object iteratedObject = this.tableIterator.next();
        Map<String, String> objectProperties = new HashMap<String, String>();

        // if it's a String don't add the "Bytes" column
        if (iteratedObject instanceof String)
        {
            return;
        }
        // if it's a map already use key names for column headers
        if (iteratedObject instanceof Map)
        {
            objectProperties = (Map<String, String>) iteratedObject;
        }
        else
        {
            try
            {
                objectProperties = BeanUtils.describe(iteratedObject);
            }
            catch (Exception e)
            {
                log.warn("Unable to automatically add columns: " + e.getMessage(), e);
            }
        }

        // iterator on properties names
        Iterator<String> propertiesIterator = objectProperties.keySet().iterator();

        while (propertiesIterator.hasNext())
        {
            // get the property name
            String propertyName = propertiesIterator.next();

            // dont't want to add the standard "class" property
            if (!"class".equals(propertyName)) //$NON-NLS-1$
            {
                // creates a new header and add to the table model
                HeaderCell headerCell = new HeaderCell();
                headerCell.setBeanPropertyName(propertyName);

                // handle title i18n
                headerCell.setTitle(this.properties.geResourceProvider().getResource(
                    null,
                    propertyName,
                    this,
                    this.pageContext));

                this.tableModel.addColumnHeader(headerCell);
            }
        }
    }
}
 
开发者ID:webbfontaine,项目名称:displaytag,代码行数:64,代码来源:TableTag.java

示例15: copyDetails

import org.apache.commons.collections.IteratorUtils; //导入方法依赖的package包/类
/**
 * Helper method to copy the details for.
 * @param copy The object to copy into.
 * @param original The object to copy from.
 * @param clone  set to true if this is a cloned errata, and thus
 *      things like org or advisory name shouldn't be set
 */
private static void copyDetails(Errata copy, Errata original, boolean clone) {

    //Set the easy things first ;)

    if (!clone) {
        copy.setAdvisory(original.getAdvisory());
        copy.setAdvisoryName(original.getAdvisoryName());
        copy.setOrg(original.getOrg());
    }

    copy.setAdvisoryType(original.getAdvisoryType());
    copy.setProduct(original.getProduct());
    copy.setErrataFrom(original.getErrataFrom());
    copy.setDescription(original.getDescription());
    copy.setSynopsis(original.getSynopsis());
    copy.setTopic(original.getTopic());
    copy.setSolution(original.getSolution());
    copy.setIssueDate(original.getIssueDate());
    copy.setUpdateDate(original.getUpdateDate());
    copy.setNotes(original.getNotes());
    copy.setRefersTo(original.getRefersTo());
    copy.setAdvisoryRel(original.getAdvisoryRel());
    copy.setLocallyModified(original.getLocallyModified());
    copy.setLastModified(original.getLastModified());
    copy.setSeverity(original.getSeverity());


    /*
     * Copy the packages
     * packages aren't published or unpublished exactly... that is determined
     * by the status of the errata...
     */
    copy.setPackages(new HashSet(original.getPackages()));

    /*
     * Copy the keywords
     * if we use the string version of addKeyword, we don't have to worry about
     * whether or not the keyword is published.
     */
    Iterator keysItr = IteratorUtils.getIterator(original.getKeywords());
    while (keysItr.hasNext()) {
        Keyword k = (Keyword) keysItr.next();
        copy.addKeyword(k.getKeyword());
    }


    /*
     * Copy the bugs. If copy is published, then the bugs should be published as well.
     * If not, then we want unpublished bugs.
     */
    Iterator bugsItr = IteratorUtils.getIterator(original.getBugs());
    while (bugsItr.hasNext()) {
        Bug bugIn = (Bug) bugsItr.next();
        Bug cloneB;
        if (copy.isPublished()) { //we want published bugs
            cloneB = ErrataManager.createNewPublishedBug(bugIn.getId(),
                    bugIn.getSummary(),
                    bugIn.getUrl());
        }
        else { //we want unpublished bugs
            cloneB = ErrataManager.createNewUnpublishedBug(bugIn.getId(),
                    bugIn.getSummary(),
                    bugIn.getUrl());
        }
        copy.addBug(cloneB);
    }
}
 
开发者ID:spacewalkproject,项目名称:spacewalk,代码行数:75,代码来源:ErrataFactory.java


注:本文中的org.apache.commons.collections.IteratorUtils.getIterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。