ruper2/src/java/core/org/krysalis/ruper2/util/regexp RegularExpression.java,NONE,1.1 RegularExpressionSelector.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/util/regexp
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/java/core/org/krysalis/ruper2/util/regexp

Added Files:
	RegularExpression.java RegularExpressionSelector.java 
Log Message:
Avoid clash with existing Ruper...

--- NEW FILE: RegularExpression.java ---
/*
 * Created on Aug 27, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.util.regexp;

import java.util.HashMap;

import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;

/**
 * @author arb_jack
 * 
 *	Wrapper in case we move to ORO  
 */
public class RegularExpression {
	private final String m_expression;
	private final RE m_regexp;

	private static HashMap m_cached = new HashMap();

	public RegularExpression(String expression) {
		try {
			m_expression = expression;
			if (m_cached.containsKey(expression)) {
				m_regexp = (RE) m_cached.get(expression);
			}
			else {
				m_regexp = new RE(expression);
				m_cached.put(expression, m_regexp);
			}
		}
		catch (RESyntaxException e) {
			System.err.println(e.toString());
			e.printStackTrace(System.err);

			throw new IllegalArgumentException(e.getLocalizedMessage());
		}
	}

	public RegularExpression(RE expression) {
		m_expression = expression.toString();
		m_regexp = expression;
	}

	public boolean match(String input) {
		return m_regexp.match(input);
	}

	public String toString() {
		return m_expression;
	}
}

--- NEW FILE: RegularExpressionSelector.java ---
/*
 * Created on Aug 27, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.util.regexp;

import org.krysalis.ruper2.util.select.Selectable;
import org.krysalis.ruper2.util.select.Selector;


/**
 * @author arb_jack
 */
public class RegularExpressionSelector implements Selector {
	private final RegularExpression m_regexp;

	public RegularExpressionSelector(String expression) {
		m_regexp = new RegularExpression(expression);
	}

	public RegularExpressionSelector(RegularExpression expression) {
		m_regexp = expression;
	}

	/* (non-Javadoc)
	 * @see org.krysalis.ruper2.util.Selector#select(java.lang.Object)
	 */
	public boolean select(Object o) {
		String data = null;

		if (o instanceof Selectable)
			data = ((Selectable) o).getSelectionObject().toString();
		else
			data = o.toString();

		return m_regexp.match(data);
	}
	
	public String toString() {
		return m_regexp.toString();
	}
}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.