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

com.netflix.eureka2.interests.VipInterest Maven / Gradle / Ivy

There is a newer version: 2.0.0-DP4
Show newest version
package com.netflix.eureka2.interests;

import com.netflix.eureka2.registry.InstanceInfo;

import java.util.regex.Pattern;

/**
 * @author Nitesh Kant
 */
public class VipInterest extends Interest {

    private final String vip;
    private final Operator operator;

    private volatile Pattern pattern;

    protected VipInterest() {
        vip = null;
        operator = null;
    }

    public VipInterest(String vip) {
        this.vip = vip;
        this.operator = Operator.Equals;
    }

    public VipInterest(String vip, Operator operator) {
        this.vip = vip;
        this.operator = operator;
    }

    public String getVip() {
        return vip;
    }

    public Operator getOperator() {
        return operator;
    }

    @Override
    public boolean matches(InstanceInfo data) {
        if(data.getVipAddress() == null) {
            return false;
        }
        if (operator != Operator.Like) {
            return vip.equals(data.getVipAddress());
        }
        if (pattern == null) {
            pattern = Pattern.compile(vip);
        }
        return pattern.matcher(data.getVipAddress()).matches();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        VipInterest that = (VipInterest) o;

        if (operator != that.operator) {
            return false;
        }
        if (vip != null ? !vip.equals(that.vip) : that.vip != null) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = vip != null ? vip.hashCode() : 0;
        result = 31 * result + (operator != null ? operator.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "VipInterest{operator=" + operator + ", vip='" + vip + '\'' + '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy