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 org.jetbrains.annotations.NotNull;
public final class Tuple4 {
@NotNull
public final A a;
@NotNull
public final B b;
@NotNull
public final C c;
@NotNull
public final D d;
public Tuple4(@NotNull A a, @NotNull B b, @NotNull C c, @NotNull D d) {
super();
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
@NotNull
public Tuple4 mapA(@NotNull F f) {
return new Tuple4<>(f.apply(this.a), this.b, this.c, this.d);
}
@NotNull
public Tuple4 mapB(@NotNull F f) {
return new Tuple4<>(this.a, f.apply(this.b), this.c, this.d);
}
@NotNull
public Tuple4 mapC(@NotNull F f) {
return new Tuple4<>(this.a, this.b, f.apply(this.c), this.d);
}
@NotNull
public Tuple4 mapD(@NotNull 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);
}
}