
ru.progrm_jarvis.javacommons.object.Pair Maven / Gradle / Ivy
package ru.progrm_jarvis.javacommons.object;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.jetbrains.annotations.NotNull;
/**
* A container holding two values.
*
* @param type of the first value
* @param type of the second value
*/
public interface Pair {
/**
* Gets the first value.
*
* @return the first value
*/
F getFirst();
/**
* Gets the second value.
*
* @return the second value
*/
S getSecond();
/**
* Creates a new pair of the given values.
*
* @param first first value of the pair
* @param second second value of the pair
* @param type of the first value of the pair
* @param type of the second value of the pair
* @return created pair of the given values
*/
static @NotNull Pair of(final F first, final S second) {
return new SimplePair<>(first, second);
}
/**
* Simple implementation of {@link Pair}.
*
* @param type of the first value
* @param type of the second value
*/
@Value
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class SimplePair implements Pair {
/**
* The first value of this pair.
*/
F first;
/**
* The second value of this pair.
*/
S second;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy