mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
2554fbb896
commit
ea9349949b
@ -13,7 +13,7 @@
|
||||
package org.dromara.hutool.core.date.format;
|
||||
|
||||
import org.dromara.hutool.core.lang.Assert;
|
||||
import org.dromara.hutool.core.lang.Tuple;
|
||||
import org.dromara.hutool.core.lang.tuple.Tuple;
|
||||
import org.dromara.hutool.core.map.SafeConcurrentHashMap;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.core.lang.mutable;
|
||||
|
||||
import org.dromara.hutool.core.lang.tuple.Triple;
|
||||
|
||||
/**
|
||||
* 可变三元组对象
|
||||
*
|
||||
* @param <L> 左值类型
|
||||
* @param <M> 中值类型
|
||||
* @param <R> 右值类型
|
||||
* @author kirno7
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public class MutableTriple<L, M, R> extends Triple<L, M, R> implements Mutable<MutableTriple<L, M, R>>{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 构建MutableTriple对象
|
||||
*
|
||||
* @param <L> 左值类型
|
||||
* @param <M> 中值类型
|
||||
* @param <R> 右值类型
|
||||
* @param left 左值
|
||||
* @param middle 中值
|
||||
* @param right 右值
|
||||
* @return MutableTriple
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static <L, M, R> MutableTriple<L, M, R> of(final L left, final M middle, final R right) {
|
||||
return new MutableTriple<>(left, middle, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param left 左值
|
||||
* @param middle 中值
|
||||
* @param right 右值
|
||||
*/
|
||||
public MutableTriple(final L left, final M middle, final R right) {
|
||||
super(left, middle, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableTriple<L, M, R> get() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(final MutableTriple<L, M, R> value) {
|
||||
this.left = value.left;
|
||||
this.middle = value.middle;
|
||||
this.right = value.right;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置左值
|
||||
*
|
||||
* @param left 左值
|
||||
*/
|
||||
public void setLeft(final L left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置中值
|
||||
*
|
||||
* @param middle 中值
|
||||
*/
|
||||
public void setMiddle(final M middle) {
|
||||
this.middle = middle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置右值
|
||||
*
|
||||
* @param right 右值
|
||||
*/
|
||||
public void setRight(final R right) {
|
||||
this.right = right;
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.core.lang.tuple;
|
||||
|
||||
import org.dromara.hutool.core.exceptions.CloneRuntimeException;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 不可变三元组对象
|
||||
*
|
||||
* @param <L> 左值类型
|
||||
* @param <M> 中值类型
|
||||
* @param <R> 右值类型
|
||||
* @author kirno7
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public class Triple<L, M, R> implements Serializable, Cloneable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected L left;
|
||||
protected M middle;
|
||||
protected R right;
|
||||
|
||||
/**
|
||||
* 构建ImmutableTriple对象
|
||||
*
|
||||
* @param <L> 左值类型
|
||||
* @param <M> 中值类型
|
||||
* @param <R> 右值类型
|
||||
* @param left 左值
|
||||
* @param middle 中值
|
||||
* @param right 右值
|
||||
* @return ImmutableTriple
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static <L, M, R> Triple<L, M, R> of(final L left, final M middle, final R right) {
|
||||
return new Triple<>(left, middle, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param left 左值
|
||||
* @param middle 中值
|
||||
* @param right 右值
|
||||
*/
|
||||
public Triple(final L left, final M middle, final R right) {
|
||||
this.left = left;
|
||||
this.middle = middle;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
// region ----- getXXX
|
||||
/**
|
||||
* 获取左值
|
||||
*
|
||||
* @return 左值
|
||||
*/
|
||||
public L getLeft() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取中值
|
||||
*
|
||||
* @return 中值
|
||||
*/
|
||||
public M getMiddle() {
|
||||
return this.middle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取右值
|
||||
*
|
||||
* @return 右值
|
||||
*/
|
||||
public R getRight() {
|
||||
return this.right;
|
||||
}
|
||||
// endregion
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o instanceof Triple) {
|
||||
final Triple<?, ?, ?> triple = (Triple<?, ?, ?>) 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() + '}';
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Triple<L, M, R> clone() {
|
||||
try {
|
||||
return (Triple<L, M, R>) super.clone();
|
||||
} catch (final CloneNotSupportedException e) {
|
||||
throw new CloneRuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.core.lang;
|
||||
package org.dromara.hutool.core.lang.tuple;
|
||||
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.collection.iter.ArrayIter;
|
||||
@ -193,7 +193,7 @@ public class Tuple implements Iterable<Object>, Serializable, Cloneable {
|
||||
public Tuple clone() {
|
||||
try {
|
||||
return (Tuple) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
} catch (final CloneNotSupportedException e) {
|
||||
throw new CloneRuntimeException(e);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 元组相关封装,包括:
|
||||
* <ul>
|
||||
* <li>类似Python元组的{@link org.dromara.hutool.core.lang.tuple.Tuple}</li>
|
||||
* <li>三元组{@link org.dromara.hutool.core.lang.tuple.Triple}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Looly, kirno7
|
||||
*/
|
||||
package org.dromara.hutool.core.lang.tuple;
|
@ -1,77 +0,0 @@
|
||||
package org.dromara.hutool.core.tuple;
|
||||
|
||||
/**
|
||||
* 不可变三元组对象
|
||||
*
|
||||
* @param <L> 左值类型
|
||||
* @param <M> 中值类型
|
||||
* @param <R> 右值类型
|
||||
* @author kirno7
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected final L left;
|
||||
protected final M middle;
|
||||
protected final R right;
|
||||
|
||||
/**
|
||||
* 构建ImmutableTriple对象
|
||||
*
|
||||
* @param <L> 左值类型
|
||||
* @param <M> 中值类型
|
||||
* @param <R> 右值类型
|
||||
* @param left 左值
|
||||
* @param middle 中值
|
||||
* @param right 右值
|
||||
* @return ImmutableTriple
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static <L, M, R> ImmutableTriple<L, M, R> of(L left, M middle, R right) {
|
||||
return new ImmutableTriple<>(left, middle, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param left 左值
|
||||
* @param middle 中值
|
||||
* @param right 右值
|
||||
*/
|
||||
private ImmutableTriple(L left, M middle, R right) {
|
||||
this.left = left;
|
||||
this.middle = middle;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取左值
|
||||
*
|
||||
* @return 左值
|
||||
*/
|
||||
@Override
|
||||
public L getLeft() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取中值
|
||||
*
|
||||
* @return 中值
|
||||
*/
|
||||
@Override
|
||||
public M getMiddle() {
|
||||
return this.middle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取右值
|
||||
*
|
||||
* @return 右值
|
||||
*/
|
||||
@Override
|
||||
public R getRight() {
|
||||
return this.right;
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
package org.dromara.hutool.core.tuple;
|
||||
|
||||
/**
|
||||
* 可变三元组对象
|
||||
*
|
||||
* @param <L> 左值类型
|
||||
* @param <M> 中值类型
|
||||
* @param <R> 右值类型
|
||||
* @author kirno7
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public class MutableTriple<L, M, R> extends Triple<L, M, R> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected L left;
|
||||
protected M middle;
|
||||
protected R right;
|
||||
|
||||
/**
|
||||
* 构建MutableTriple对象
|
||||
*
|
||||
* @param <L> 左值类型
|
||||
* @param <M> 中值类型
|
||||
* @param <R> 右值类型
|
||||
* @param left 左值
|
||||
* @param middle 中值
|
||||
* @param right 右值
|
||||
* @return MutableTriple
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static <L, M, R> MutableTriple<L, M, R> of(L left, M middle, R right) {
|
||||
return new MutableTriple<>(left, middle, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param left 左值
|
||||
* @param middle 中值
|
||||
* @param right 右值
|
||||
*/
|
||||
private MutableTriple(L left, M middle, R right) {
|
||||
this.left = left;
|
||||
this.middle = middle;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取左值
|
||||
*
|
||||
* @return 左值
|
||||
*/
|
||||
@Override
|
||||
public L getLeft() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取中值
|
||||
*
|
||||
* @return 中值
|
||||
*/
|
||||
@Override
|
||||
public M getMiddle() {
|
||||
return this.middle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取右值
|
||||
*
|
||||
* @return 右值
|
||||
*/
|
||||
@Override
|
||||
public R getRight() {
|
||||
return this.right;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置左值
|
||||
*
|
||||
* @param left 左值
|
||||
*/
|
||||
public void setLeft(L left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置中值
|
||||
*
|
||||
* @param middle 中值
|
||||
*/
|
||||
public void setMiddle(M middle) {
|
||||
this.middle = middle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置右值
|
||||
*
|
||||
* @param right 右值
|
||||
*/
|
||||
public void setRight(R right) {
|
||||
this.right = right;
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
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() + '}';
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.dromara.hutool.core.lang;
|
||||
|
||||
import org.dromara.hutool.core.lang.tuple.Tuple;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.dromara.hutool.core.lang.func;
|
||||
|
||||
import org.dromara.hutool.core.func.*;
|
||||
import org.dromara.hutool.core.lang.Tuple;
|
||||
import org.dromara.hutool.core.lang.tuple.Tuple;
|
||||
import org.dromara.hutool.core.reflect.MethodUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.core.lang.tuple;
|
||||
|
||||
import org.dromara.hutool.core.lang.mutable.MutableTriple;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* {@link Triple} 三元组单元测试
|
||||
* {@link MutableTriple} 三元组单元测试
|
||||
*
|
||||
* @author kirno7
|
||||
*/
|
||||
public class TripleTest {
|
||||
|
||||
@Test
|
||||
public void mutableTripleTest() {
|
||||
final MutableTriple<String, String, String> mutableTriple = MutableTriple
|
||||
.of("1", "1", "1");
|
||||
Assertions.assertEquals("Triple {left=1, middle=1, right=1}", mutableTriple.toString());
|
||||
|
||||
mutableTriple.setLeft("2");
|
||||
mutableTriple.setMiddle("2");
|
||||
mutableTriple.setRight("2");
|
||||
Assertions.assertEquals("Triple {left=2, middle=2, right=2}", mutableTriple.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tripleTest() {
|
||||
final Triple<String, String, String> triple = Triple
|
||||
.of("3", "3", "3");
|
||||
Assertions.assertEquals("Triple {left=3, middle=3, right=3}", triple.toString());
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package org.dromara.hutool.core.tuple;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* {@link ImmutableTriple} 三元组单元测试
|
||||
* {@link MutableTriple} 三元组单元测试
|
||||
*
|
||||
* @author kirno7
|
||||
*/
|
||||
public class TripleTest {
|
||||
@Test
|
||||
public void tripleTest() {
|
||||
MutableTriple<String, String, String> mutableTriple = MutableTriple.of("1", "1", "1");
|
||||
System.out.println(mutableTriple);
|
||||
mutableTriple.setLeft("2");
|
||||
mutableTriple.setMiddle("2");
|
||||
mutableTriple.setRight("2");
|
||||
System.out.println(mutableTriple);
|
||||
ImmutableTriple<String, String, String> immutableTriple = ImmutableTriple.of("3", "3", "3");
|
||||
System.out.println(immutableTriple);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user