com.shapesecurity.functional.Tuple4 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;
import com.shapesecurity.functional.data.HashCodeBuilder;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
@CheckReturnValue
public final class Tuple4 {
@Nonnull
public final A a;
@Nonnull
public final B b;
@Nonnull
public final C c;
@Nonnull
public final D d;
public Tuple4(@Nonnull A a, @Nonnull B b, @Nonnull C c, @Nonnull D d) {
super();
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
@Nonnull
public Tuple4 mapA(@Nonnull F f) {
return new Tuple4<>(f.apply(this.a), this.b, this.c, this.d);
}
@Nonnull
public Tuple4 mapB(@Nonnull F f) {
return new Tuple4<>(this.a, f.apply(this.b), this.c, this.d);
}
@Nonnull
public Tuple4 mapC(@Nonnull F f) {
return new Tuple4<>(this.a, this.b, f.apply(this.c), this.d);
}
@Nonnull
public Tuple4 mapD(@Nonnull F f) {
return new Tuple4<>(this.a, this.b, this.c, f.apply(this.d));
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
return obj == this || obj instanceof Tuple4 &&
((Tuple4) obj).a.equals(this.a) &&
((Tuple4) obj).b.equals(this.b) &&
((Tuple4) obj).c.equals(this.c) &&
((Tuple4) obj).d.equals(this.d);
}
@Override
public int hashCode() {
int hash = HashCodeBuilder.put(HashCodeBuilder.init(), "Tuple4");
hash = HashCodeBuilder.put(hash, this.a);
hash = HashCodeBuilder.put(hash, this.b);
hash = HashCodeBuilder.put(hash, this.c);
return HashCodeBuilder.put(hash, this.d);
}
}