All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mockrunner.util.common.CollectionUtil Maven / Gradle / Ivy

Go to download

Mockrunner is a lightweight framework for unit testing applications in the J2EE environment. It supports servlets, filters, tag classes and Struts actions. It includes a JDBC a JMS and a JCA test framework and can be used to test EJB based applications.

The newest version!
package com.mockrunner.util.common;

import java.util.ArrayList;
import java.util.List;

/**
 * Util class for collections
 */
public class CollectionUtil
{
    /**
     * Fills a List with null
     * by calling {@link #fillList(List, int, Object)}
     * with a null object.
     * @param list the List that should be filled
     * @param size the resulting size of the List
     */
    public static void fillList(List list, int size)
    {
        fillList(list, size, null);
    }
    
    /**
     * Fills a List with with the specified object
     * until it has the specified size. If the specified size is
     * equal or lower the List size, nothing happens.
     * @param list the List that should be filled
     * @param size the resulting size of the List
     */
    public static void fillList(List list, int size, Object object)
    {
        for(int ii = list.size(); ii <  size; ii++)
        {
            list.add(object);
        }
    }
    
    /**
     * Returns a truncated version of the specified List.
     * @param list the List
     * @param len the truncate length
     * @return the truncated List
     */
    public static List truncateList(List list, int len)
    {
        if(len >= list.size()) return list;
        ArrayList newList = new ArrayList(len);
        for(int ii = 0; ii < len; ii++)
        {
            newList.add(list.get(ii));
        }
        return newList;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy