
com.jnape.palatable.shoki.api.Sizable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shoki Show documentation
Show all versions of shoki Show documentation
Purely functional data structures in Java
The newest version!
package com.jnape.palatable.shoki.api;
import static com.jnape.palatable.shoki.api.EquivalenceRelation.equivalent;
import static com.jnape.palatable.shoki.api.EquivalenceRelation.objectEquals;
/**
* A generic interface representing a type that can provide information about its size.
*
* @see Collection
*/
public interface Sizable {
/**
* Returns a {@link SizeInfo} representing any information this type has about its size.
*
* @return the information about this type's size
*/
SizeInfo sizeInfo();
/**
* Common {@link EquivalenceRelation}s between {@link Sizable}s.
*/
final class EquivalenceRelations {
private EquivalenceRelations() {
}
/**
* An {@link EquivalenceRelation} between two {@link Sizable}s that holds if, and only if, both {@link Sizable}s
* have equivalent {@link SizeInfo}s. O(1)
.
*
* @param the {@link Sizable} subtype of the arguments
* @return the {@link EquivalenceRelation}
*/
public static EquivalenceRelation sizeInfos() {
return (xs, ys) -> equivalent(objectEquals(), xs.sizeInfo(), ys.sizeInfo());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy