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

cn.hutool.core.lang.mutable.MutableObj Maven / Gradle / Ivy

Go to download

Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。

There is a newer version: 5.8.34
Show newest version
package cn.hutool.core.lang.mutable;

import cn.hutool.core.util.ObjUtil;

import java.io.Serializable;

/**
 * 可变{@code Object}
 *
 * @param  可变的类型
 * @since 3.0.1
 */
public class MutableObj implements Mutable, Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 构建MutableObj
	 * @param value 被包装的值
	 * @param  值类型
	 * @return MutableObj
	 * @since 5.8.0
	 */
	public static  MutableObj of(T value){
		return new MutableObj<>(value);
	}

	private T value;

	/**
	 * 构造,空值
	 */
	public MutableObj() {
	}

	/**
	 * 构造
	 *
	 * @param value 值
	 */
	public MutableObj(final T value) {
		this.value = value;
	}

	// -----------------------------------------------------------------------
	@Override
	public T get() {
		return this.value;
	}

	@Override
	public void set(final T value) {
		this.value = value;
	}

	// -----------------------------------------------------------------------
	@Override
	public boolean equals(final Object obj) {
		if (obj == null) {
			return false;
		}
		if (this == obj) {
			return true;
		}
		if (this.getClass() == obj.getClass()) {
			final MutableObj that = (MutableObj) obj;
			return ObjUtil.equals(this.value, that.value);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return value == null ? 0 : value.hashCode();
	}

	// -----------------------------------------------------------------------
	@Override
	public String toString() {
		return value == null ? "null" : value.toString();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy