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

cz.mmsparams.api.utils.MmscAcquireRouteUtil Maven / Gradle / Ivy

package cz.mmsparams.api.utils;

import java.util.List;

import cz.mmsparams.api.websocket.model.mmsc.MM7Address;
import cz.mmsparams.api.websocket.model.mmsc.MmscAcquireRouteModel;

public class MmscAcquireRouteUtil
{
    private MmscAcquireRouteUtil()
    {
    }

    public static boolean isMatch(final MmscAcquireRouteModel mmscAcquireRouteModel, final List recipients)
    {
        if (mmscAcquireRouteModel == null || recipients == null)
            return false;

        for (MM7Address adr : recipients)
        {
            final boolean match = isMatch(mmscAcquireRouteModel, adr);
            if (match)
                return true;
        }

        return false;
    }

    public static boolean isMatch(final MmscAcquireRouteModel mmscAcquireRouteModel, final MM7Address recipients)
    {
        String pattern = mmscAcquireRouteModel.getPattern();
        String address = recipients.getAddress();

        if (StringUtil.isEmptyOrNull(pattern) || StringUtil.isEmptyOrNull(address))
            return false;

        if (pattern.length() > address.length())
            return false;

        if (pattern.equals(address))
            return true;

        for (int i = 0; i < pattern.length(); i++)
        {
            if (pattern.charAt(i) == '*')
                return true;

            if (pattern.charAt(i) != address.charAt(i))
                return false;
        }

        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy