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

com.taotao.boot.sms.common.loadbalancer.TargetWrapper Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.taotao.boot.sms.common.loadbalancer;

import java.util.Objects;

/**
 * target wrapper
 *
 * @author shuigedeng
 * @version 2022.04
 * @since 2022-04-27 17:53:12
 */
public class TargetWrapper {

    /** active status */
    private boolean active;

    /** target object */
    private T target;

    private TargetWrapper() {}

    /**
     * build target wrapper
     *
     * @param target target object
     * @param  target class
     * @return target wrapper
     */
    public static  TargetWrapper of(T target) {
        if (target == null) {
            throw new NullPointerException("entity is null");
        }

        TargetWrapper wrapper = new TargetWrapper();
        wrapper.target = target;

        return wrapper;
    }

    /**
     * get active status
     *
     * @return active status
     */
    public boolean isActive() {
        return active;
    }

    /**
     * set active status
     *
     * @param active active status
     */
    public void setActive(boolean active) {
        this.active = active;
    }

    /**
     * get target object
     *
     * @return target object
     */
    public T getTarget() {
        return target;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TargetWrapper that = (TargetWrapper) o;
        return Objects.equals(target, that.target);
    }

    @Override
    public int hashCode() {
        return target.hashCode();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy