您的位置:首页 > 文旅 > 旅游 > 页面设计在线_web开发技术是什么意思_seo排名方案_百度店铺

页面设计在线_web开发技术是什么意思_seo排名方案_百度店铺

2025/3/18 9:13:21 来源:https://blog.csdn.net/qq_17589751/article/details/146316916  浏览:    关键词:页面设计在线_web开发技术是什么意思_seo排名方案_百度店铺
页面设计在线_web开发技术是什么意思_seo排名方案_百度店铺

背景

  • 在写代码的过程中,因有一些复杂的业务逻辑,需要返回多个结果。比如:需要增加一个true或者false,另外在加一个真正的结果值这样的类型。
  • 可能会有人用到数组以及Map等作为结果返回,当然这样确实是可以完成这样的功能,但是并不是很优雅。

解决方案1

  • 利用现有的轮子,或者自己造一个
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package reactor.util.function;import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import reactor.util.annotation.NonNull;
import reactor.util.annotation.Nullable;public class Tuple2<T1, T2> implements Iterable<Object>, Serializable {private static final long serialVersionUID = -3518082018884860684L;@NonNullfinal T1 t1;@NonNullfinal T2 t2;Tuple2(T1 t1, T2 t2) {this.t1 = Objects.requireNonNull(t1, "t1");this.t2 = Objects.requireNonNull(t2, "t2");}public T1 getT1() {return this.t1;}public T2 getT2() {return this.t2;}public <R> Tuple2<R, T2> mapT1(Function<T1, R> mapper) {return new Tuple2(mapper.apply(this.t1), this.t2);}public <R> Tuple2<T1, R> mapT2(Function<T2, R> mapper) {return new Tuple2(this.t1, mapper.apply(this.t2));}@Nullablepublic Object get(int index) {switch (index) {case 0:return this.t1;case 1:return this.t2;default:return null;}}public List<Object> toList() {return Arrays.asList(this.toArray());}public Object[] toArray() {return new Object[]{this.t1, this.t2};}public Iterator<Object> iterator() {return Collections.unmodifiableList(this.toList()).iterator();}public boolean equals(@Nullable Object o) {if (this == o) {return true;} else if (o != null && this.getClass() == o.getClass()) {Tuple2<?, ?> tuple2 = (Tuple2)o;return this.t1.equals(tuple2.t1) && this.t2.equals(tuple2.t2);} else {return false;}}public int hashCode() {int result = this.size();result = 31 * result + this.t1.hashCode();result = 31 * result + this.t2.hashCode();return result;}public int size() {return 2;}public final String toString() {return Tuples.tupleStringRepresentation(this.toArray()).insert(0, '[').append(']').toString();}
}
  • 如果是三个参数
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package reactor.util.function;import java.util.Objects;
import java.util.function.Function;
import reactor.util.annotation.NonNull;
import reactor.util.annotation.Nullable;public class Tuple3<T1, T2, T3> extends Tuple2<T1, T2> {private static final long serialVersionUID = -4430274211524723033L;@NonNullfinal T3 t3;Tuple3(T1 t1, T2 t2, T3 t3) {super(t1, t2);this.t3 = Objects.requireNonNull(t3, "t3");}public T3 getT3() {return this.t3;}public <R> Tuple3<R, T2, T3> mapT1(Function<T1, R> mapper) {return new Tuple3(mapper.apply(this.t1), this.t2, this.t3);}public <R> Tuple3<T1, R, T3> mapT2(Function<T2, R> mapper) {return new Tuple3(this.t1, mapper.apply(this.t2), this.t3);}public <R> Tuple3<T1, T2, R> mapT3(Function<T3, R> mapper) {return new Tuple3(this.t1, this.t2, mapper.apply(this.t3));}@Nullablepublic Object get(int index) {switch (index) {case 0:return this.t1;case 1:return this.t2;case 2:return this.t3;default:return null;}}public Object[] toArray() {return new Object[]{this.t1, this.t2, this.t3};}public boolean equals(@Nullable Object o) {if (this == o) {return true;} else if (!(o instanceof Tuple3)) {return false;} else if (!super.equals(o)) {return false;} else {Tuple3 tuple3 = (Tuple3)o;return this.t3.equals(tuple3.t3);}}public int size() {return 3;}public int hashCode() {int result = super.hashCode();result = 31 * result + this.t3.hashCode();return result;}
}
  • 以上都是来自这个包下面的,当然也可以自己去自定义

在这里插入图片描述

解决方案2

  • 同样的,推荐第二种方案,就是利用 Apache的commons包下面的 MutableTriple<L, M, R> ,废话不多说,直接上截图:
    在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com