prompto.intrinsic.PromptoSet Maven / Gradle / Ivy
The newest version!
package prompto.intrinsic;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
@SuppressWarnings("serial")
public class PromptoSet extends HashSet implements Filterable, V>, IJsonNodeProducer {
public PromptoSet() {
}
public PromptoSet(Collection items) {
super(items);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append('<');
forEach((i)->{
sb.append(i.toString());
sb.append(", ");
});
if(sb.length()>1)
sb.setLength(sb.length()-2); // trim last ", "
sb.append('>');
return sb.toString();
}
public Long getCount() {
return (long)size();
}
public long getNativeCount() {
return size();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public PromptoList sort(boolean descending) {
Comparator cmp = descending ?
(o1, o2) -> ((Comparable)o2).compareTo(o1) :
(o1, o2) -> ((Comparable)o1).compareTo(o2);
TreeSet sorted = new TreeSet<>(cmp);
sorted.addAll(this);
return new PromptoList<>(sorted, false);
}
@SuppressWarnings("unchecked")
public PromptoList extends V> sortUsing(Comparator extends V> cmp) {
PromptoList sorted = new PromptoList<>(this, false);
sorted.sort((Comparator)cmp);
return sorted;
}
public boolean containsAny(Collection
© 2015 - 2024 Weber Informatics LLC | Privacy Policy