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

ua.co.gravy.tuplets.Tuplet Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2017 Vitaliy Berdinskikh
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ua.co.gravy.tuplets;


import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;


/**
 * 

* Represents a tuple. *

*

* The fixed-length, immutable and type-safe container of elements. * The number and type of its elements are determined by the implementing classes. *

* * @author Vitaliy Berdinskikh, ur6lad * @since 1.0 */ public interface Tuplet extends Comparable, Iterable { /** *

* Returns true if this tuple contains the specified element. *

*

* Returns true if the value is null and this tuple contains at least one null. *

* * @param value the element to search for * @return true if this tuple contains value, false otherwise */ boolean contains(Object value); /** *

* Returns the element at the specified position in this tuple. *

* * @param index the index of the element to return * @return an element at the specified position in this * @throws IndexOutOfBoundsException if the index is out of range: index < 0 || index >= length() */ Object get(int index); /** *

* Returns true if all elements are null. *

* * @return true if all elements are null. */ default boolean isEmpty() { for (Object item : toArray()) { if (Objects.nonNull(item)) { return false; } } return true; } /** * Returns the length of this tuple. * * @return length of this tuple */ int length(); /** * Returns a sequential {@link Stream} of elements. * * @return a sequential stream of elements */ Stream stream(); /** * Returns an array of elements. * * @return an array of elements */ Object[] toArray(); /** * Returns a fixed-size {@link List} of elements. * * @return a list of elements */ List toList(); }