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

com.iohao.game.common.kit.beans.property.LongProperty Maven / Gradle / Ivy

/*
 * ioGame
 * Copyright (C) 2021 - present  渔民小镇 ([email protected][email protected]) . All Rights Reserved.
 * # iohao.com . 渔民小镇
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */
package com.iohao.game.common.kit.beans.property;

import lombok.ToString;

/**
 * long - 属性具备监听特性。当值发生变更时,会触发监听事件。
 * 
{@code
 *         var property = new LongProperty();
 *         // add listener monitor property object
 *         property.addListener((observable, oldValue, newValue) -> {
 *             log.info("oldValue:{}, newValue:{}", oldValue, newValue);
 *         });
 *
 *         property.get(); // value is 0
 *         property.set(22); // When the value changes,listeners are triggered
 *         property.get(); // value is 22
 * }
 * 
* * @author 渔民小镇 * @date 2024-04-17 */ @ToString public final class LongProperty extends NumberPropertyValueObservable { long value; public LongProperty() { this(0); } public LongProperty(long value) { this.value = value; } @Override public Long getValue() { return get(); } @Override public void setValue(Number value) { if (value == null) { this.set(0); } else { this.set(value.longValue()); } } /** * get current value * * @return current value */ public long get() { this.valid = true; return this.value; } /** * set current value * * @param newValue current new value */ public void set(long newValue) { if (newValue != this.value) { this.value = newValue; markInvalid(); } } /** * current value + 1 */ public void increment() { this.set(this.value + 1); } /** * current value - 1 */ public void decrement() { this.set(this.value - 1); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy