All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xiaoleilu.hutool.lang.Tuple Maven / Gradle / Ivy

package com.xiaoleilu.hutool.lang;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Iterator;

import com.xiaoleilu.hutool.clone.CloneSupport;
import com.xiaoleilu.hutool.collection.ArrayIterator;

/**
 * 不可变数组类型,用于多值返回
* 多值可以支持每个元素值类型不同 * * @author Looly * */ public class Tuple extends CloneSupport implements Iterable, Serializable{ private static final long serialVersionUID = -7689304393482182157L; private Object[] members; /** * 构造 * @param members 成员数组 */ public Tuple(Object... members) { this.members = members; } /** * 获取指定位置元素 * @param 返回对象类型 * @param index 位置 * @return 元素 */ @SuppressWarnings("unchecked") public T get(int index){ return (T) members[index]; } /** * 获得所有元素 * @return 获得所有元素 */ public Object[] getMembers(){ return this.members; } @Override public String toString() { return Arrays.toString(members); } @Override public Iterator iterator() { return new ArrayIterator(members); } }