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

com.xlrit.gears.base.collection.CollectionRef Maven / Gradle / Ivy

There is a newer version: 1.17.5
Show newest version
package com.xlrit.gears.base.collection;

import java.util.Comparator;
import java.util.List;

import lombok.RequiredArgsConstructor;

public interface CollectionRef extends HasElementType {
    default CollectionRef sorted(Comparator comparator) {
        return new SortedCollectionRef<>(this, comparator);
    }

    List getElements();
    void updateElements(List newElements);
}

@RequiredArgsConstructor
class SortedCollectionRef implements CollectionRef {
    private final CollectionRef delegate;
    private final Comparator comparator;

    @Override
    public Class getElementType() {
        return delegate.getElementType();
    }

    @Override
    public List getElements() {
        return delegate.getElements().stream().sorted(comparator).toList();
    }

    @Override
    public void updateElements(List newElements) {
        delegate.updateElements(newElements);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy