Added code to check if a named field has been modified, added code to

check if all the modified fields are within a particular subset of fields.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1209 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
eric
2003-08-26 04:49:05 +00:00
parent d9731c97c2
commit 4e7004b847
@@ -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.
*/