com.shapesecurity.functional.data.NonEmptyImmutableList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shape-functional-java Show documentation
Show all versions of shape-functional-java Show documentation
Functional programming library
/*
* Copyright 2014 Shape Security, Inc.
*
* 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 com.shapesecurity.functional.data;
import com.shapesecurity.functional.F;
import com.shapesecurity.functional.F2;
import com.shapesecurity.functional.Pair;
import javax.annotation.Nonnull;
import java.util.ArrayList;
public final class NonEmptyImmutableList extends ImmutableList {
public static final int HASH_START = HashCodeBuilder.put(HashCodeBuilder.init(), "List");
@Nonnull
public final T head;
@Nonnull
public final ImmutableList tail;
protected NonEmptyImmutableList(@Nonnull T head, @Nonnull final ImmutableList tail) {
super(tail.length + 1);
this.head = head;
this.tail = tail;
}
@Nonnull
public ImmutableList tail() {
return this.tail;
}
@Nonnull
private T[] toObjectArray() {
int length = this.length;
Object[] target = new Object[length];
//noinspection unchecked
return (T[]) ((ImmutableList