/*
 * Copyright (c) 2002-2011 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 *  the terms of the license agreement you entered into with JSCAPE.
 */

package com.jscape.util.regex;

import com.jscape.util.Wildcard;

/**
 * @author Alex Usun
 */
public class WildcardMatcherFactory
        implements MatcherFactory {

    @Override
    public Matcher matcherFor(String pattern)
            throws OperationException {
        try {
            return new WildcardMatcher(new Wildcard(pattern));
        } catch (Exception e) {
            throw new OperationException(e);
        }
    }

    public static class WildcardMatcher
            implements Matcher {

        private final Wildcard wildcard;

        public WildcardMatcher(Wildcard wildcard) {
            this.wildcard = wildcard;
        }

        public WildcardMatcher(String wildcard) {
            this(new Wildcard(wildcard));
        }

        public boolean matches(String data) {
            return this.wildcard.matches(data);
        }

        @Override
        public String toString() {
            return "WildcardMatcher {"
                    + "wildcard=" + this.wildcard
                    + '}';
        }
    }
}
