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

com.robrua.orianna.api.Utils Maven / Gradle / Ivy

There is a newer version: 2.4.5
Show newest version
package com.robrua.orianna.api;

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

public abstract class Utils {
    /**
     * Breaks a list of IDs into smaller lists under the limited size
     *
     * @param 
     *            the type of the IDs
     * @param IDs
     *            the IDs to split
     * @param limit
     *            the list size limit
     * @return the split lists
     */
    public static  List> breakUpList(final List IDs, final int limit) {
        final List> result = new ArrayList<>(IDs.size() / limit + 1);
        List list = new ArrayList<>();
        for(int i = 0; i < IDs.size(); i++) {
            if(i % limit == 0 && i != 0) {
                result.add(list);
                list = new ArrayList<>();
            }
            list.add(IDs.get(i));
        }
        result.add(list);

        return result;
    }

    /**
     * Converts an array of longs into a list
     *
     * @param vals
     *            the values to convert
     * @return the result list
     */
    public static List convert(final long... vals) {
        final List values = new ArrayList<>(vals.length);
        for(final long val : vals) {
            values.add(val);
        }

        return values;
    }

    /**
     * Stringifies a list of IDs
     *
     * @param 
     *            the type of the IDs
     * @param IDs
     *            the IDs
     * @return a string of the IDs
     */
    public static  String getIDString(final List IDs) {
        final StringBuilder sb = new StringBuilder();
        for(final T ID : IDs) {
            sb.append("," + ID.toString());
        }
        return sb.substring(1);
    }

    /**
     * Converts a list of Longs to Integers
     *
     * @param longs
     *            the longs
     * @return a list of Integers
     */
    public static List toIntegers(final List longs) {
        final List ints = new ArrayList<>();
        for(final Long lng : longs) {
            ints.add(lng.intValue());
        }

        return ints;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy