mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
抽取抽象类/减少重复代码
This commit is contained in:
parent
126aa0211b
commit
b1c032b326
@ -1,8 +1,5 @@
|
|||||||
package org.dromara.hutool.core.tuple;
|
package org.dromara.hutool.core.tuple;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不可变三元组对象
|
* 不可变三元组对象
|
||||||
*
|
*
|
||||||
@ -12,7 +9,7 @@ import java.util.Objects;
|
|||||||
* @author kirno7
|
* @author kirno7
|
||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
public class ImmutableTriple<L, M, R> implements Serializable {
|
public class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected final L left;
|
protected final L left;
|
||||||
@ -53,6 +50,7 @@ public class ImmutableTriple<L, M, R> implements Serializable {
|
|||||||
*
|
*
|
||||||
* @return 左值
|
* @return 左值
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public L getLeft() {
|
public L getLeft() {
|
||||||
return this.left;
|
return this.left;
|
||||||
}
|
}
|
||||||
@ -62,6 +60,7 @@ public class ImmutableTriple<L, M, R> implements Serializable {
|
|||||||
*
|
*
|
||||||
* @return 中值
|
* @return 中值
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public M getMiddle() {
|
public M getMiddle() {
|
||||||
return this.middle;
|
return this.middle;
|
||||||
}
|
}
|
||||||
@ -71,31 +70,8 @@ public class ImmutableTriple<L, M, R> implements Serializable {
|
|||||||
*
|
*
|
||||||
* @return 右值
|
* @return 右值
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public R getRight() {
|
public R getRight() {
|
||||||
return this.right;
|
return this.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ImmutableTriple {" + "left=" + left + ", middle=" + middle + ", right=" + right + '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (o instanceof ImmutableTriple) {
|
|
||||||
ImmutableTriple<?, ?, ?> triple = (ImmutableTriple<?, ?, ?>) o;
|
|
||||||
return Objects.equals(left, triple.getLeft()) &&
|
|
||||||
Objects.equals(middle, triple.getMiddle()) &&
|
|
||||||
Objects.equals(right, triple.getRight());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(left) ^ Objects.hashCode(middle) ^ Objects.hashCode(right);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package org.dromara.hutool.core.tuple;
|
package org.dromara.hutool.core.tuple;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可变三元组对象
|
* 可变三元组对象
|
||||||
*
|
*
|
||||||
@ -12,7 +9,7 @@ import java.util.Objects;
|
|||||||
* @author kirno7
|
* @author kirno7
|
||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
public class MutableTriple<L, M, R> implements Serializable {
|
public class MutableTriple<L, M, R> extends Triple<L, M, R> {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
protected L left;
|
protected L left;
|
||||||
@ -53,6 +50,7 @@ public class MutableTriple<L, M, R> implements Serializable {
|
|||||||
*
|
*
|
||||||
* @return 左值
|
* @return 左值
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public L getLeft() {
|
public L getLeft() {
|
||||||
return this.left;
|
return this.left;
|
||||||
}
|
}
|
||||||
@ -62,6 +60,7 @@ public class MutableTriple<L, M, R> implements Serializable {
|
|||||||
*
|
*
|
||||||
* @return 中值
|
* @return 中值
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public M getMiddle() {
|
public M getMiddle() {
|
||||||
return this.middle;
|
return this.middle;
|
||||||
}
|
}
|
||||||
@ -71,6 +70,7 @@ public class MutableTriple<L, M, R> implements Serializable {
|
|||||||
*
|
*
|
||||||
* @return 右值
|
* @return 右值
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public R getRight() {
|
public R getRight() {
|
||||||
return this.right;
|
return this.right;
|
||||||
}
|
}
|
||||||
@ -101,28 +101,4 @@ public class MutableTriple<L, M, R> implements Serializable {
|
|||||||
public void setRight(R right) {
|
public void setRight(R right) {
|
||||||
this.right = right;
|
this.right = right;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "MutableTriple {" + "left=" + left + ", middle=" + middle + ", right=" + right + '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (o instanceof MutableTriple) {
|
|
||||||
MutableTriple<?, ?, ?> triple = (MutableTriple<?, ?, ?>) o;
|
|
||||||
return Objects.equals(left, triple.getLeft()) &&
|
|
||||||
Objects.equals(middle, triple.getMiddle()) &&
|
|
||||||
Objects.equals(right, triple.getRight());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(left) ^ Objects.hashCode(middle) ^ Objects.hashCode(right);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
package org.dromara.hutool.core.tuple;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 三元组抽象类
|
||||||
|
*
|
||||||
|
* @param <L> 左值类型
|
||||||
|
* @param <M> 中值类型
|
||||||
|
* @param <R> 右值类型
|
||||||
|
* @author kirno7
|
||||||
|
* @since 6.0.0
|
||||||
|
*/
|
||||||
|
public abstract class Triple<L, M, R> implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取左值
|
||||||
|
*
|
||||||
|
* @return 左值
|
||||||
|
*/
|
||||||
|
public abstract L getLeft();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取中值
|
||||||
|
*
|
||||||
|
* @return 中值
|
||||||
|
*/
|
||||||
|
public abstract M getMiddle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取右值
|
||||||
|
*
|
||||||
|
* @return 右值
|
||||||
|
*/
|
||||||
|
public abstract R getRight();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o instanceof ImmutableTriple) {
|
||||||
|
ImmutableTriple<?, ?, ?> triple = (ImmutableTriple<?, ?, ?>) o;
|
||||||
|
return Objects.equals(getLeft(), triple.getLeft()) &&
|
||||||
|
Objects.equals(getMiddle(), triple.getMiddle()) &&
|
||||||
|
Objects.equals(getRight(), triple.getRight());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(getLeft()) ^ Objects.hashCode(getMiddle()) ^ Objects.hashCode(getRight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Triple {" + "left=" + getLeft() + ", middle=" + getMiddle() + ", right=" + getRight() + '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user