001/* 002 * PermissionsEx 003 * Copyright (C) zml and PermissionsEx contributors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://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 */ 017package ca.stellardrift.permissionsex.util; 018 019import org.immutables.value.Value; 020 021/** 022 * Represents a change in the value of some object. 023 * 024 * @param <T> the type of object being changed 025 * @since 2.0.0 026 */ 027@Value.Immutable(builder = false) 028public interface Change<T> { 029 030 static <T> Change<T> of(final T old, final T current) { 031 return new ChangeImpl<>(old, current); 032 } 033 034 /** 035 * The previous value before the operation. 036 * 037 * @return the previous value 038 * @since 2.0.0 039 */ 040 @Value.Parameter 041 T old(); 042 043 /** 044 * The current value. 045 * 046 * @return the current value 047 * @since 2.0.0 048 */ 049 @Value.Parameter 050 T current(); 051 052 /** 053 * Get whether any change actually occurred. 054 * 055 * @return if a change occurred 056 * @since 2.0.0 057 */ 058 default boolean changed() { 059 return old() != current(); 060 } 061}