001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * https://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.lang3.mutable; 019 020import java.util.function.Supplier; 021 022/** 023 * Provides mutable access to a value. 024 * <p> 025 * {@link Mutable} is used as a generic interface to the implementations in this package. 026 * </p> 027 * <p> 028 * A typical use case would be to enable a primitive or string to be passed to a method and allow that method to effectively change the value of the 029 * primitive/object. Another use case is to store a frequently changing primitive in a collection (for example a total in a map) without needing to create new 030 * Integer/Long wrapper objects. 031 * </p> 032 * 033 * @param <T> the type to wrap. 034 * @since 2.1 035 */ 036public interface Mutable<T> extends Supplier<T> { 037 038 /** 039 * Gets the value of this mutable. 040 * 041 * @return the stored value. 042 * @since 3.18.0 043 */ 044 @Override 045 default T get() { 046 return getValue(); 047 } 048 049 /** 050 * Gets the value of this mutable. 051 * 052 * @return the stored value 053 * @deprecated Use {@link #get()}. 054 */ 055 @Deprecated 056 T getValue(); 057 058 /** 059 * Sets the value of this mutable. 060 * 061 * @param value the value to store 062 * @throws NullPointerException if the object is null and null is invalid. 063 * @throws ClassCastException if the type is invalid. 064 */ 065 void setValue(T value); 066}