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

com.shapesecurity.functional.data.Nil Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
/*
 * 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;

public final class Nil extends ImmutableList {
    private final static int DEFAULT_HASH_CODE;

    static {
        int h = HashCodeBuilder.init();
        DEFAULT_HASH_CODE = HashCodeBuilder.put(h, "Nil");
    }

    Nil() {
        super(0);
    }

    @Override
    protected int calcHashCode() {
        return DEFAULT_HASH_CODE;
    }

    @Nonnull
    @Override
    public  A foldLeft(@Nonnull F2 f, @Nonnull A init) {
        return init;
    }

    @Nonnull
    @Override
    public  A foldRight(@Nonnull F2 f, @Nonnull A init) {
        return init;
    }

    @Nonnull
    @Override
    public Maybe maybeHead() {
        return Maybe.empty();
    }

    @Nonnull
    @Override
    public Maybe maybeLast() {
        return Maybe.empty();
    }

    @Nonnull
    @Override
    public Maybe> maybeTail() {
        return Maybe.empty();
    }

    @Nonnull
    @Override
    public Maybe> maybeInit() {
        return Maybe.empty();
    }

    @Nonnull
    @Override
    public ImmutableList filter(@Nonnull F f) {
        return this;
    }

    @Nonnull
    @Override
    public  ImmutableList map(@Nonnull F f) {
        return empty();
    }

    @Nonnull
    @Override
    public  ImmutableList mapWithIndex(@Nonnull F2 f) {
        return empty();
    }

    @Nonnull
    @Override
    public ImmutableList take(int n) {
        return this;
    }

    @Nonnull
    @Override
    public ImmutableList drop(int n) {
        return this;
    }

    @Nonnull
    @Override
    public Maybe> toNonEmptyList() {
        return Maybe.empty();
    }

    @Nonnull
    @Override
    public  Maybe decons(@Nonnull F2, B> f) {
        return Maybe.empty();
    }

    @SuppressWarnings("unchecked")
    @Nonnull
    @Override
    public  ImmutableList zipWith(@Nonnull F2 f, @Nonnull ImmutableList list) {
        return (ImmutableList) this;
    }

    @Override
    public boolean isEmpty() {
        return true;
    }

    @Nonnull
    @Override
    @SuppressWarnings("unchecked")
    public  ImmutableList append(@Nonnull ImmutableList defaultClause) {
        // This is safe due to erasure.
        return (ImmutableList) defaultClause;
    }

    @Override
    public boolean exists(@Nonnull F f) {
        return false;
    }

    @Override
    public boolean contains(@Nonnull T a) {
        return false;
    }

    @Nonnull
    @Override
    public Pair, ImmutableList> span(@Nonnull F f) {
        return new Pair<>(empty(), empty());
    }

    @Nonnull
    @Override
    @SuppressWarnings("unchecked")
    public  ImmutableList flatMap(@Nonnull F> f) {
        return (ImmutableList) this;
    }

    @Nonnull
    @Override
    public ImmutableList removeAll(@Nonnull F f) {
        return this;
    }

    @Nonnull
    @Override
    public ImmutableList reverse() {
        return this;
    }

    @Nonnull
    @SuppressWarnings("unchecked")
    @Override
    public  ImmutableList patch(int index, int patchLength, @Nonnull ImmutableList replacements) {
        return (ImmutableList) replacements;
    }

    @Nonnull
    @Override
    public  Pair> mapAccumL(@Nonnull F2> f, @Nonnull B acc) {
        return new Pair<>(acc, ImmutableList.empty());
    }

    @Nonnull
    @Override
    public ImmutableSet uniqByEquality() {
        return ImmutableSet.emptyUsingEquality();
    }

    @Nonnull
    @Override
    public ImmutableSet uniqByIdentity() {
        return ImmutableSet.emptyUsingIdentity();
    }

    @Nonnull
    @Override
    public  ImmutableSet uniqByEqualityOn(@Nonnull F f) {
        return ImmutableSet.emptyUsingEquality();
    }

    @SuppressWarnings("unchecked")
    @Override
    public boolean equals(Object o) {
        return this == o;
    }
}