diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/jora/FieldMask.java b/projects/samskivert/src/java/com/samskivert/jdbc/jora/FieldMask.java index 10052894..7bd18754 100644 --- a/projects/samskivert/src/java/com/samskivert/jdbc/jora/FieldMask.java +++ b/projects/samskivert/src/java/com/samskivert/jdbc/jora/FieldMask.java @@ -1,9 +1,9 @@ // -// $Id: FieldMask.java,v 1.2 2002/05/11 20:29:27 mdb Exp $ +// $Id: FieldMask.java,v 1.3 2003/08/26 04:49:05 eric Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne -// +// // 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 @@ -22,6 +22,8 @@ package com.samskivert.jdbc.jora; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; /** * Provides support for doing partial updates to objects in a JORA table. @@ -81,6 +83,36 @@ public class FieldMask return _modified[index]; } + /** + * Returns true if the field with the specified name is modifed. + */ + public final boolean isModified (String fieldName) + { + Integer index = (Integer)_descripMap.get(fieldName); + if (index == null) { + String errmsg = "Passed in field not in mask."; + throw new IllegalArgumentException(errmsg); + } + return _modified[index.intValue()]; + } + + /** + * Takes a subset of the fields represented by this field mask. + * Returns true only if the modified fields intersect the subsetFields. + */ + public final boolean onlySubSetModified (HashSet subsetFields) + { + Iterator itr = _descripMap.keySet().iterator(); + while (itr.hasNext()) { + String field = (String)itr.next(); + if (isModified(field) && (!subsetFields.contains(field))) { + return false; + } + } + + return true; + } + /** * Marks the specified field as modified. */