src/main/java/org/jamppa/component/utils/RSMUtils.java
public static List<Identifiable> filterRSMResponse(
            List<Identifiable> objects, RSM rsm)
            throws IllegalArgumentException {

        String after = rsm.getAfter();
        String before = rsm.getBefore();

        int initialIndex = rsm.getIndex();
        int lastIndex = objects.size();

        if (after != null || (before != null && !before.isEmpty())) {

            boolean afterItemFound = false;
            boolean beforeItemFound = false;

            int i = 0;
            for (Identifiable object : objects) {
                if (after != null && after.equals(object.getId())) {
                    initialIndex = i + 1;
                    afterItemFound = true;
                }
                if (before != null && before.equals(object.getId())) {
                    lastIndex = i;
                    beforeItemFound = true;
                }
                i++;
            }

            if (after != null && !afterItemFound) {
                throw new IllegalArgumentException();
            }

            if (before != null && !before.isEmpty() && !beforeItemFound) {
                throw new IllegalArgumentException();
            }
        }

        if (rsm.getMax() != null) {
            if (before != null) {
                initialIndex = lastIndex - rsm.getMax();
            } else {
                lastIndex = initialIndex + rsm.getMax();
            }
        }

        boolean outOfRange = initialIndex > lastIndex || initialIndex < 0
                || lastIndex > objects.size();

        List<Identifiable> filteredList = outOfRange ? new LinkedList<Identifiable>()
                : objects.subList(initialIndex, lastIndex);

        rsm.setCount(objects.size());
        rsm.setIndex(initialIndex);

        if (!filteredList.isEmpty()) {
            rsm.setFirst(filteredList.get(0).getId());
            rsm.setLast(filteredList.get(filteredList.size() - 1).getId());
        }

        return filteredList;
    }
public static List<Identifiable> filterRSMResponse(
            List<Identifiable> objects, RSM rsm)
            throws IllegalArgumentException {

        String after = rsm.getAfter();
        String before = rsm.getBefore();

        int initialIndex = rsm.getIndex();
        int lastIndex = objects.size();

        if (after != null || (before != null && !before.isEmpty())) {

            boolean afterItemFound = false;
            boolean beforeItemFound = false;

            int i = 0;
            for (Identifiable object : objects) {
                if (after != null && after.equals(object.getId())) {
                    initialIndex = i + 1;
                    afterItemFound = true;
                }
                if (before != null && before.equals(object.getId())) {
                    lastIndex = i;
                    beforeItemFound = true;
                }
                i++;
            }

            if (after != null && !afterItemFound) {
                throw new IllegalArgumentException();
            }

            if (before != null && !before.isEmpty() && !beforeItemFound) {
                throw new IllegalArgumentException();
            }
        }

        if (rsm.getMax() != null) {
            if (before != null) {
                initialIndex = lastIndex - rsm.getMax();
            } else {
                lastIndex = initialIndex + rsm.getMax();
            }
        }

        boolean outOfRange = initialIndex > lastIndex || initialIndex < 0
                || lastIndex > objects.size();

        List<Identifiable> filteredList = outOfRange ? new LinkedList<Identifiable>()
                : objects.subList(initialIndex, lastIndex);

        rsm.setCount(objects.size());
        rsm.setIndex(initialIndex);

        if (!filteredList.isEmpty()) {
            rsm.setFirst(filteredList.get(0).getId());
            rsm.setLast(filteredList.get(filteredList.size() - 1).getId());
        }

        return filteredList;
    }
Filters response objects based on the RSM parameters. Updates the RSM
object with item count, first and last jid

@param objects
@param rsm
@return
@throws IllegalArgumentException
If the item specified by the requesting entity via the UID in
the <after/> or <before/> element does not exist