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

ace.Utils Maven / Gradle / Ivy

The newest version!
package ace;

import ace.database.entities.content.DataContent;

import java.util.List;
import java.util.NoSuchElementException;

/**
 * Utils
 */
public class Utils {
    /**
     * @param list to be searched
     * @param nrElements of elements in a row to be found
     * @param  type of data for the elements
     * @return list of first sequence of nrElements with the given data type
     */
    public static > List listFindSequence(List list, int nrElements) {
        long lastId = -1;
        int sequence = 0;
        for (int i = 0; i < list.size(); i++) {
            if (++lastId != list.get(i).getId()) {
                sequence = 1;
                lastId = list.get(i).getId();
            } else {
                sequence++;
            }

            if (sequence == nrElements) {
                return list.subList(i - nrElements + 1, i + 1);
            }
        }
        throw new NoSuchElementException("Could not find a sequence of '" + nrElements + "' in the given list");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy