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

shz.core.structure.config.Config Maven / Gradle / Ivy

There is a newer version: 2024.0.2
Show newest version
package shz.core.structure.config;

import shz.core.structure.FilterContainer;

import java.io.Serializable;

/**
 * 0-63 的配置类
 */
public final class Config implements FilterContainer, Serializable {
    private static final long serialVersionUID = -1631075296266326957L;
    private long config;

    public long getConfig() {
        return config;
    }

    public boolean has(int value) {
        return value <= 0 || (config & 1L << value) != 0;
    }

    public boolean nonHas(int value) {
        return !has(value);
    }

    public boolean hasAny(int... values) {
        for (int value : values) if (has(value)) return true;
        return false;
    }

    public boolean nonHasAny(int... values) {
        return !hasAny(values);
    }

    public boolean hasAll(int... values) {
        for (int value : values) if (nonHas(value)) return false;
        return true;
    }

    public boolean nonHasAll(int... values) {
        return !hasAll(values);
    }

    public void add(int value) {
        if (value <= 0) return;
        config |= 1L << value;
    }

    public void add(int... values) {
        for (int value : values) add(value);
    }

    public void remove(int value) {
        if (value <= 0) return;
        config &= ~(1L << value);
    }

    public void remove(int... values) {
        for (int value : values) remove(value);
    }

    ////////////////////////////////////other
    public boolean contains(long other) {
        return other <= 0L || (other ^ (config & other)) == 0L;
    }

    public boolean nonContains(long other) {
        return !contains(other);
    }

    public boolean containsAny(long... others) {
        for (long other : others) if (contains(other)) return true;
        return false;
    }

    public boolean nonContainsAny(long... others) {
        return !containsAny(others);
    }

    public boolean containsAll(long... others) {
        for (long other : others) if (nonContains(other)) return false;
        return true;
    }

    public boolean nonContainsAll(long... others) {
        return !containsAll(others);
    }

    public void join(long other) {
        if (other <= 0L) return;
        config |= other;
    }

    public void join(long... others) {
        for (long other : others) join(other);
    }

    public void clear(long other) {
        if (other <= 0L) return;
        config ^= config & other;
    }

    public void clear(long... others) {
        for (long other : others) clear(other);
    }

    @Override
    public void push(Object key) {
        if (key instanceof Integer) add((int) key);
    }

    @Override
    public void push(Object... keys) {
        for (Object key : keys) push(key);
    }

    @Override
    public boolean contain(Object key) {
        return (key instanceof Integer) && has((int) key);
    }

    @Override
    public boolean contain(Object... keys) {
        for (Object key : keys) if (!contain(key)) return false;
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy