[Javamatch-cvs] javamatch/src/net/sourceforge/javamatch/query BooleanEquals.java,NONE,1.1 RegexMatch
Status: Pre-Alpha
Brought to you by:
iterson
From: Walter v. I. <it...@us...> - 2004-09-13 08:45:57
|
Update of /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv711/net/sourceforge/javamatch/query Modified Files: Contains.java GreaterThan.java LessThan.java Maximum.java Minimum.java NumberEquals.java Range.java StringEquals.java Added Files: BooleanEquals.java RegexMatches.java Log Message: Added regex, booleanEquals, test for null members --- NEW FILE: BooleanEquals.java --- /* JavaMatch: Matching engine for Java runtime data structures * Copyright (C) 2004 Walter van Iterson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package net.sourceforge.javamatch.query; import net.sourceforge.javamatch.engine.*; /** * Class BooleanEquals is a query that check if a boolean member returns true */ public class BooleanEquals extends MatchQuery { /** The name of the member of the object that is matched */ private String memberName; /** * Creates a new BooleanEquals-query, that checks if member with the given * member name returns true * @param memberName the name of the member that is matched */ public BooleanEquals(String memberName) { if (memberName == null) { throw new NullPointerException("Member name can't be null"); } this.memberName = memberName; } /** * Returns the match value of this match query, when executed on the given * object. * @param targetObject the object agains which the query is executed * @return A value between 0 and 1, both inclusive, that indicates how good * the object matches this query. 0 means a mismatch, 1 means a full * match * @throws MatchException when the value could not be retrieved */ public float getMatchValue(Object targetObject) throws MatchException { Boolean objectValue = (Boolean)getObjectValue(targetObject, memberName); if (objectValue.booleanValue()) { return 1f; } return 0f; } } Index: GreaterThan.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/GreaterThan.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GreaterThan.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- GreaterThan.java 13 Sep 2004 08:45:47 -0000 1.2 *************** *** 38,41 **** --- 38,44 ---- */ public GreaterThan(String memberName, double matchValue) { + if (memberName == null) { + throw new NullPointerException("Member name can't be null"); + } this.memberName = memberName; this.matchValue = matchValue; Index: Minimum.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/Minimum.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Minimum.java 6 Sep 2004 09:14:30 -0000 1.2 --- Minimum.java 13 Sep 2004 08:45:47 -0000 1.3 *************** *** 41,44 **** --- 41,47 ---- */ public Minimum(String memberName) { + if (memberName == null) { + throw new NullPointerException("Member name can't be null"); + } this.memberName = memberName; } Index: NumberEquals.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/NumberEquals.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** NumberEquals.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- NumberEquals.java 13 Sep 2004 08:45:48 -0000 1.2 *************** *** 38,41 **** --- 38,44 ---- */ public NumberEquals(String memberName, double matchValue) { + if (memberName == null) { + throw new NullPointerException("Member name can't be null"); + } this.memberName = memberName; this.matchValue = matchValue; Index: Range.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/Range.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Range.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- Range.java 13 Sep 2004 08:45:48 -0000 1.2 *************** *** 42,45 **** --- 42,48 ---- */ public Range(String memberName, double minimumValue, double maximumValue) { + if (memberName == null) { + throw new NullPointerException("Member name can't be null"); + } this.memberName = memberName; this.minimumValue = minimumValue; Index: Contains.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/Contains.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Contains.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- Contains.java 13 Sep 2004 08:45:47 -0000 1.2 *************** *** 38,41 **** --- 38,44 ---- */ public Contains(String memberName, String matchValue) { + if (memberName == null) { + throw new NullPointerException("Member name can't be null"); + } this.memberName = memberName; this.matchValue = matchValue; --- NEW FILE: RegexMatches.java --- /* JavaMatch: Matching engine for Java runtime data structures * Copyright (C) 2004 Walter van Iterson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package net.sourceforge.javamatch.query; import java.util.regex.*; import net.sourceforge.javamatch.engine.*; /** * Class RegexMatches is a query that check if a string matches a certain * regular expression */ public class RegexMatches extends StringQuery { /** The name of the member of the object that is matched */ private String memberName; /** The regular expression that describes the matching pattern */ private String expression; /** * Creates a new RegexMatches-query, that checks the given member name * againstthe given regular expression * @param memberName the name of the member that is matched * @param matchValue the value against which is matched * @throws PatternSyntaxException If the expression's syntax is invalid */ public RegexMatches(String memberName, String expression) throws PatternSyntaxException { if (memberName == null) { throw new NullPointerException("Member name can't be null"); } if (expression == null) { throw new NullPointerException("Expression can't be null"); } this.memberName = memberName; this.expression = expression; Pattern.compile(expression); } /** * Returns the match value of this match query, when executed on the given * object. * @param targetObject the object agains which the query is executed * @return A value between 0 and 1, both inclusive, that indicates how good * the object matches this query. 0 means a mismatch, 1 means a full * match * @throws MatchException when the value could not be retrieved */ public float getMatchValue(Object targetObject) throws MatchException { String objectValue = getValue(targetObject, memberName); float returnValue = 0.0f; if (objectValue != null) { if (Pattern.compile(expression).matcher(objectValue).matches()) { returnValue = 1.0f; } } return returnValue; } } Index: Maximum.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/Maximum.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Maximum.java 6 Sep 2004 09:14:30 -0000 1.2 --- Maximum.java 13 Sep 2004 08:45:47 -0000 1.3 *************** *** 41,44 **** --- 41,47 ---- */ public Maximum(String memberName) { + if (memberName == null) { + throw new NullPointerException("Member name can't be null"); + } this.memberName = memberName; } Index: LessThan.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/LessThan.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LessThan.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- LessThan.java 13 Sep 2004 08:45:47 -0000 1.2 *************** *** 38,41 **** --- 38,44 ---- */ public LessThan(String memberName, double matchValue) { + if (memberName == null) { + throw new NullPointerException("Member name can't be null"); + } this.memberName = memberName; this.matchValue = matchValue; Index: StringEquals.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/StringEquals.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** StringEquals.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- StringEquals.java 13 Sep 2004 08:45:48 -0000 1.2 *************** *** 38,41 **** --- 38,44 ---- */ public StringEquals(String memberName, String matchValue) { + if (memberName == null) { + throw new NullPointerException("Member name can't be null"); + } this.memberName = memberName; this.matchValue = matchValue; |