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

commons.box.app.MetaBeanConfigBase Maven / Gradle / Ivy

The newest version!
package commons.box.app;

import commons.box.util.Maps;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.Map;

/**
 * 用于MetaBean基本类 对基本方法进行了封装
 */
public abstract class MetaBeanConfigBase extends MetaLabelValueBase implements HasKey, DataName, DataLabel, DataObject {
    protected String name;
    protected long version = 0;
    protected Map extprops;

    @Nonnull
    public String name() {
        return (this.name != null) ? this.name : "";
    }

    public long version() {
        return this.version;
    }

    public Map extprops() {
        return Maps.immmap(this.extprops);
    }

    public Serializable extprop(String key) {
        return (key != null && this.extprops != null) ? this.extprops.get(key) : null;
    }

    /**
     * 此方法用于内部机制 不允许直接调用
     *
     * @param name
     * @return
     */
    public R withName(@Nonnull String name) {
        this.name = name;
        return this.root();
    }


    /**
     * 此方法用于内部机制 不允许直接调用
     *
     * @param version
     * @return
     */
    public R withVersion(long version) {
        this.version = version;
        return this.root();
    }

    /**
     * 此方法用于内部机制 不允许直接调用
     *
     * @param name
     * @param val
     * @return
     */
    public R withExtprops(String name, Serializable val) {
        if (name == null || val == null) return this.root();
        Map map = new SafeMap<>();
        if (this.extprops != null) map.putAll(this.extprops);
        map.put(name, val);
        this.extprops = map;
        return this.root();
    }

    /**
     * 此方法用于内部机制 不允许直接调用
     *
     * @param extprops
     * @return
     */
    public R withExtprops(Map extprops) {
        return this.withExtprops(extprops, false);
    }

    /**
     * 此方法用于内部机制 不允许直接调用
     *
     * @param extprops
     * @param overwrite
     * @return
     */
    public R withExtprops(Map extprops, boolean overwrite) {
        Map map = new SafeMap<>();
        if (!overwrite && this.extprops != null) map.putAll(this.extprops);
        if (extprops != null) map.putAll(extprops);
        this.extprops = map;
        return this.root();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy