Classes Files

mama/MamaRegexChannelFilter.java

Namespaces

Name
com::wombat::mama

Classes

  Name
class com::wombat::mama::MamaRegexChannelFilter

Source code

package com.wombat.mama;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

public class MamaRegexChannelFilter
{
    private int mDefaultChannelId = 0;

    private final Map<Pattern, Integer> mFilters = new HashMap<>();

    public MamaRegexChannelFilter ()
    {
    }

    public void setDefaultChannel(int channelId)
    {
        mDefaultChannelId = channelId;
    }

    public void addRegex (final String regexStr, final int channelId)
    {
        mFilters.put(Pattern.compile(regexStr), channelId);
    }

    public int getChannel (final String target)
    {
        for (Map.Entry<Pattern, Integer> entry : mFilters.entrySet()) {
            if (entry.getKey().matcher(target).find()) {
                return entry.getValue();
            }
        }
        return mDefaultChannelId;
    }
}

Updated on 2023-03-31 at 15:29:46 +0100