> Larry wrote: "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."
> 
> I agree with Larry on this point. I believe it would be safe to
> develop a solution in which we assume each attribute is set only once
> during initialization, and not set and then reset during the
> initialization process. It may be true that this rule does not apply,
> but I think that would be an "edge case" and I can't think of any
> existing code in the core that would do this.
Sure enough this can be a good assumption. In fact if you look at the 
code I attached, this is exactly what I have done. There's an array used 
only during init time, where each attribute set is tracked separately. 
After all attributes have been set at least once, the init is considered 
ended, the array is discarded, and a single Boolean is used to track 
modification. All in all the overhead is a single Object reference, 
since init time is probably going to last for a very short time.

> 
> On the other hand, if we require client code to call some type of
> "setInitComplete" method we are going to break all sorts of stuff. I
> would think this would require that all code in plug-ins and the core
> that create BasicFeature objects would have to be modified if the
> system was going to work as desired. That is a major refactoring.
In fact the forementioned code gives this possibility as an add-on, so 
that non mod-aware code will use the "automatic" code described above, 
while mod-aware code can, if it whish to, set and reset the init status 
however it likes to.

Bye
Paolo


> 
> I think we should move forward with an internal mechanism to monitor
> modification of attribute values based on the assumption that
> attribute values are set once during initialization. This has a
> relatively low memory requirement, and if it doesn't work we will soon
> know about it.
> 
> I will start work on this solution on my lunch break today if there
> are no objections. Perhaps the best way to end debate is with some
> code we all can test.
> 
> The Sunburned Surveyor
> 
> On Thu, Apr 30, 2009 at 6:33 AM, Larry Becker <becker.la...@gmail.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.
>>
>> 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.
>>
>> regards,
>> Larry
>>
>>
>> On Thu, Apr 30, 2009 at 6:24 AM, Paolo Rizzi <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
>>> 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


------------------------------------------------------------------------------
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

Reply via email to