Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package org.monkeys.gui.matcher; import org.apache.commons.lang.NullArgumentException; import org.monkeys.category.Category; import org.monkeys.regex.RegexMatch; /** * matchable context * * @author bowen */ public class MatcherContext implements Comparable<MatcherContext> { private final RegexMatch match; private String text; public MatcherContext(final RegexMatch match) { this.match = match; this.reset(); } public RegexMatch getMatch() { return this.match; } public String getText() { return this.text; } public void setText(final String txt) { if (null == txt) { throw new NullArgumentException("text"); } this.text = txt; } public void reset() { final Category category = this.match.getCategory(); final String updated = category.process(this.match.getText()); this.text = updated != null ? updated.trim() : this.match.getText(); } @Override public int compareTo(MatcherContext context) { return this.match.compareTo(context.match); } }