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

com.mmnaseri.utils.tuples.facade.HasThird Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package com.mmnaseri.utils.tuples.facade;

import com.mmnaseri.utils.tuples.FixedTuple;
import com.mmnaseri.utils.tuples.Tuple;

import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * Defines methods that work with the third element of a {@link FixedTuple}.
 *
 * @param  the super-type of the tuple's main data type.
 * @param  the type of the object at the third position.
 * @param  the concrete type of the fixed-size tuple.
 * @author Milad Naseri ([email protected])
 */
public interface HasThird> extends FixedTuple {

  /** Returns the third element in the current tuple. */
  @SuppressWarnings("unchecked")
  default A third() {
    return (A) get(2);
  }

  /** Sets the third element of the tuple to the indicated value. */
   Tuple third(X value);

  /** Sets the third element of the tuple to the supplied value. */
   Tuple third(Supplier supplier);

  /** Sets the third element of the tuple to the value returned from the function. */
   Tuple third(Function function);

  /** Drops the third element of the tuple, to return a tuple of one size smaller. */
  Tuple dropThird();

  /** Checks to see if the third element of this tuple matches the given predicate. */
  default boolean checkThird(Predicate predicate) {
    return predicate.test(third());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy