It looks like there are several ways to skin a cat! I have no problem accepting Larry's presented solution, or modifying my solution to include the method needed to manually mark the completion of feature intialization.
I am willing to make these adjustments, offer another round of testing, and then commit if desired. I can have the test code ready by this afternoon (Pacific Time Zone). The Sunburned Surveyor On Fri, May 1, 2009 at 8:55 AM, Larry Becker <becker.la...@gmail.com> wrote: > I tried Sunburn's mod to BasicFeature and it seems to work. > > I looked again at Paolo's mod and it looks like it will work. > > I have tested my mod and it seems to work. > > Larry > > On Fri, May 1, 2009 at 10:17 AM, Paolo Rizzi <g...@oicom.com> wrote: >> >> > An example of the standard usage pattern for JDBC can be seen in: >> > com.vividsolutions.jump.datastore.jdbc.ValueConverterFactory. >> > Regardless of whether you use ResultSet's getObject() or something like >> > getInt(), eventually you are going to need an object representation of >> > the data in order to work with it. BasicFeature.SetAttribute requires >> > an Object. So if you did something like: new >> > Integer(rs.getInt(columnIndex)) on a null column , the JavaDoc for >> > ResultSet says you'll get a zero int wrapped in an Integer. >> Zero is not equal to NULL by any means!!! >> The assumption that a zero can be used in place of a NULL is quite bad, >> IMHO. Is exactly the kind of stuff that makes legacy formats like >> shapes, mapinfo, etc. vastly inferior in respect to RDBMSs. >> >> > >> > I appreciate all of the clever solutions, but I will remain convinced >> > that BasicFeature can detect modification without any need for explicit >> > client methods to set it, until someone shows me proof that it can not. >> If you spend a moment to look at the code I attached in my previous >> message you'll see that it works in both cases. Non mod-aware client >> will get the automatic assumption that each and every attributes has to >> be set at least once before init can be considered ended. While >> mod-aware clients can, if they want, set the init status explicitely. >> >> > >> > regards, >> > Larry >> Bye >> Paolo >> >> >> > >> > >> > On Thu, Apr 30, 2009 at 6:24 AM, Paolo Rizzi <g...@oicom.com >> > <mailto:g...@oicom.com>> wrote: >> > >> > The previous sample code I posted was foolish, I'm sorry!!! >> > >> > Find attached a better version that uses a single Object reference >> > to track both initialization and modify state. >> > >> > During initialization this Object references a byte[] where each >> > element tracks the init state of the corresponding attribute. >> > >> > Init ends when all attributes has been set at least once or when the >> > client code calls a provided method. >> > >> > After init has ended the byte[] is discarded and the Object >> > references the static instance of Boolean.FALSE (so there's no >> > memory wasted beyound the single Object reference itself). >> > >> > After at least one attributes is set, the Object references the >> > static instance Boolean.TRUE. >> > >> > Client code can decide to force init end with a non-modified state >> > or even an already-modified state, if it likes to. >> > >> > The code does not check if the new value set for an attribute is >> > equal or not to the value already present. This is because a == >> > check would not be good because two different Integer instances both >> > containing the same value are to be considered equal. >> > So the equals() method should be used, but that is not garanteed to >> > work with all class types, so I think it may be better to skip the >> > check altogether and consider an attribute modified in any case. >> > >> > Hope this is helpful!!! :-) >> > >> > Bye >> > Paolo >> > >> > >> > >> > public class BasicFeature { >> > private Object[] attributes; >> > private Object mods; >> > >> > public void forceInitEnded(boolean modified) { >> > //force init end and specified modify state >> > mods = modified ? Boolean.TRUE : Boolean.FALSE; >> > } >> > >> > public boolean isInitEnded() { >> > if( mods instanceof Boolean ) //init ended >> > return true; >> > >> > if( mods == null ) { //if >> > still null >> > mods = new byte[attributes.length]; //create it >> > Arrays.fill((byte[])mods,(byte)0); //fill with >> > zeros >> > >> > return false; //init not even started >> > } >> > >> > for(int i=0;i<((byte[])mods).length;i++) >> > if( ((byte[])mods)[i] == 0 ) //if any attribute never >> > flagged >> > return false; //init not ended >> > >> > forceInitEnded(false); //init ended, no mods done >> > >> > return true; //init ended >> > } >> > >> > public void setAttribute(Object[] newAttributes) { >> > //call setAttribute() for each element >> > } >> > >> > public void setAttribute(int attributeIndex, Object >> > newAttribute) { >> > if( isInitEnded() ) //if init ended >> > mods = Boolean.TRUE; //feature modified >> > else >> > >> > //if init not ended >> > ((byte[])mods)[attributeIndex] = 1; //flag the >> > attributes mod >> > >> > attributes[attributeIndex] = newAttribute; >> > } >> > >> > public boolean isModified() { >> > return isInitEnded() ? ((Boolean)mods).booleanValue() : >> > false; >> > } >> > } >> > >> > >> > ------------------------------------------------------------------------------ >> > Register Now & Save for Velocity, the Web Performance & Operations >> > Conference from O'Reilly Media. Velocity features a full day of >> > expert-led, hands-on workshops and two days of sessions from >> > industry >> > leaders in dedicated Performance & Operations tracks. Use code >> > vel09scf >> > and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf >> > _______________________________________________ >> > Jump-pilot-devel mailing list >> > Jump-pilot-devel@lists.sourceforge.net >> > <mailto:Jump-pilot-devel@lists.sourceforge.net> >> > https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel >> > >> > >> > >> > >> > -- >> > http://amusingprogrammer.blogspot.com/ >> > >> > >> > ------------------------------------------------------------------------ >> > >> > >> > ------------------------------------------------------------------------------ >> > Register Now & Save for Velocity, the Web Performance & Operations >> > Conference from O'Reilly Media. Velocity features a full day of >> > expert-led, hands-on workshops and two days of sessions from industry >> > leaders in dedicated Performance & Operations tracks. Use code vel09scf >> > and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf >> > >> > >> > ------------------------------------------------------------------------ >> > >> > _______________________________________________ >> > Jump-pilot-devel mailing list >> > Jump-pilot-devel@lists.sourceforge.net >> > https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel >> >> >> >> ------------------------------------------------------------------------------ >> Register Now & Save for Velocity, the Web Performance & Operations >> Conference from O'Reilly Media. Velocity features a full day of >> expert-led, hands-on workshops and two days of sessions from industry >> leaders in dedicated Performance & Operations tracks. Use code vel09scf >> and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf >> _______________________________________________ >> Jump-pilot-devel mailing list >> Jump-pilot-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel > > > > -- > http://amusingprogrammer.blogspot.com/ > > ------------------------------------------------------------------------------ > Register Now & Save for Velocity, the Web Performance & Operations > Conference from O'Reilly Media. Velocity features a full day of > expert-led, hands-on workshops and two days of sessions from industry > leaders in dedicated Performance & Operations tracks. Use code vel09scf > and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf > _______________________________________________ > Jump-pilot-devel mailing list > Jump-pilot-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel > > ------------------------------------------------------------------------------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel