Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32467 > unrolled thread
| Started by | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| First post | 2015-09-02 17:14 -0400 |
| Last post | 2015-09-03 01:22 -0400 |
| Articles | 5 on this page of 25 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Self-updating relationship James Kuyper <jameskuyper@verizon.net> - 2015-09-02 17:14 -0400
Re: Self-updating relationship Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-09-02 17:46 -0400
Re: Self-updating relationship Arne Vajhøj <arne@vajhoej.dk> - 2015-09-03 21:06 -0400
Re: Self-updating relationship e.d.programmer@gmail.com - 2015-09-04 04:46 -0700
Re: Self-updating relationship Arne Vajhøj <arne@vajhoej.dk> - 2015-09-04 19:43 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-04 11:49 -0400
Re: Self-updating relationship Arne Vajhøj <arne@vajhoej.dk> - 2015-09-04 19:45 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-04 22:10 -0400
Re: Self-updating relationship Arne Vajhøj <arne@vajhoej.dk> - 2015-09-04 22:31 -0400
Re: Self-updating relationship Arne Vajhøj <arne@vajhoej.dk> - 2015-09-04 22:38 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-04 22:51 -0400
Re: Self-updating relationship James Kuyper <jameskuyper@verizon.net> - 2015-09-02 18:49 -0400
Re: Self-updating relationship James Kuyper <jameskuyper@verizon.net> - 2015-09-02 19:28 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-02 23:52 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-03 10:32 -0400
Re: Self-updating relationship James Kuyper <jameskuyper@verizon.net> - 2015-09-03 10:53 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-03 11:31 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-03 11:35 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-03 11:49 -0400
Re: Self-updating relationship James Kuyper <jameskuyper@verizon.net> - 2015-09-03 12:16 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-03 13:03 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-03 10:55 -0400
Re: Self-updating relationship James Kuyper <jameskuyper@verizon.net> - 2015-09-03 00:06 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-02 23:38 -0400
Re: Self-updating relationship Jeff Higgins <jeff@invalid.invalid> - 2015-09-03 01:22 -0400
Page 2 of 2 — ← Prev page 1 [2]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2015-09-03 13:03 -0400 |
| Message-ID | <ms9ugt$163$1@dont-email.me> |
| In reply to | #32497 |
On 09/03/2015 12:16 PM, James Kuyper wrote:
> OK - I thought I was beginning to understand what was going on, but now
> I'm thoroughly confused. You're saying that this behavior (Specifically,
> the behavior of re-calculating the subtraction each time
> spaces.getValue() is used) is a property of the
> javafx.beans.property.Property<T> interface, rather than a property of
> the javafx.beans.binding.Binding<T> interface, despite the fact that it
> happens when he uses javafx.beans.binding.NumberBinding, and doesn't
> happen when he uses javafx.beans.property.SimpleIntegerProperty?
>
> How does that work? Does javafx.beans.binding.NumberBinding use
> javafx.beans.property.Property<T> while
> javafx.beans.property.SimpleIntegerProperty uses
> javafx.beans.binding.Binding<T>? That's not at all what I would have
> expected, based solely upon the names.
>
>
Perhaps our discussion is going beside itself it the threads.
I would like to use the example code that I posted elsewhere
and neglect the javafx.beans.binding package, in particular
the NumberBinding interface if that is acceptable.
If so I will reproduce the example here.
You'll need access to the JavaFX documentation, located here:
With frames
<https://docs.oracle.com/javase/8/javafx/api/index.html?overview-summary.html>
No frames
<https://docs.oracle.com/javase/8/javafx/api/overview-summary.html>
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
public class Main
{ public static void main(String[] args)
{
final IntegerProperty height
= new SimpleIntegerProperty();
final IntegerProperty number
= new SimpleIntegerProperty();
final IntegerProperty spaces
= new SimpleIntegerProperty();
spaces.bind(height.subtract(number));
height.set(10);
number.set(2);
System.out.print(spaces.get()); // 8
spaces.unbind();
height.set(20);
System.out.print(spaces.get()); // 8
} }
Here spaces is a SimpleIntegerProperty, a subclass of
IntegerPropertyBase which is an implementation of the
Property<T> interface. IntegerPropertyBase is where the
Property.bind(ObservableValue<? extends T> observable) and
Property.unbind() are implemented.
The expression height.subtract(number) creates an
ObservableValue<Number>, through NumberExpression ( so much
for neglecting the javafx.beans.binding package) which
IntegerPropertyBase uses to bind height and number to spaces
as specified in his documentation.
As I stated elsewhere, the plethora of mixin interfaces
makes it difficult (for me) to discuss, but writing code
that uses it is simple.
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2015-09-03 10:55 -0400 |
| Message-ID | <ms9n0v$vd9$1@dont-email.me> |
| In reply to | #32489 |
On 09/03/2015 10:32 AM, Jeff Higgins wrote: > On 09/02/2015 11:52 PM, Jeff Higgins wrote: >> On 09/02/2015 07:28 PM, James Kuyper wrote: > >>> Your earlier version had: >>>> final javafx.beans.binding.NumberBinding spaces = >>>> height.subtract( number ); >>> >>> which causes spaces.getValue() to behave like the equivalent of a C++ >>> member function whose return value is calculated using the specified >>> formula freshly each time "spaces" is referred to. Is this a >>> characteristic of binding.NumberBinding, or some more general Java >>> feature? >> >> It's a characteristic of the >> javafx.beans.binding.Binding<T> interface. >> <https://docs.oracle.com/javase/8/javafx/api/javafx/beans/binding/Binding.html> >> >> > > Sorry, this is incorrect. > It's a characteristic of the > javafx.beans.property.Property<T> interface. > <https://docs.oracle.com/javase/8/javafx/api/javafx/beans/property/Property.html> > Actually, javafx.beans.property.IntegerPropertyBase provides the bind method and associated machinery in the given case. final javafx.beans.property.IntegerProperty height = new javafx.beans.property.SimpleIntegerProperty( 10 ); final javafx.beans.property.IntegerProperty number = new javafx.beans.property.SimpleIntegerProperty( 2 ); final javafx.beans.binding.NumberBinding spaces = height.subtract( number ); java.lang.System.out.println( spaces.getValue() ); height.set( 20 ); java.lang.System.out.println( spaces.getValue() ); /* prints: 8 18 */
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2015-09-03 00:06 -0400 |
| Message-ID | <ms8gs4$pv1$1@dont-email.me> |
| In reply to | #32475 |
On 09/02/2015 07:43 PM, Stefan Ram wrote:
> James Kuyper <jameskuyper@verizon.net> writes:
>> formula freshly each time "spaces" is referred to. Is this a
>> characteristic of binding.NumberBinding, or some more general Java feature?
>
> It is a characteristics of a certain standard Java library
> �JavaFX� that contains classes for "binding" properties to
> other properties. Binding can establish a spreadsheet-like
> relationship, so that one property can get updated when
> another property is updated. But this is a feature of the
> standard library, not of the language proper.
>
>> In C++, the equivalent of the first form above would be simpler than the
>> equivalent of the second form, so it feels odd that the second form is
>> simpler in Java. I'll try to keep that in mind should I ever need to
>> program in Java again. It sounds like I've got a lot to learn before I
>> even get started.
>
> I am not aware of a similar means of binding in the standard
> library of C++. But surely, one can implement it, if needed.
When I was talking about C++ equivalents, I was probably thinking of
something much simpler than what you're referring to as "binding". I
assumed that your original version worked something like the following:
struct Updating
{
int height;
int number;
Updating(int _height, int _number) : height(_height),
number(_number) {};
int spaces(void) const { return height - number; }
};
And what I was wondering about is which part of your code made it behave
that way, rather than the way this struct would:
struct OneTime
{
int height;
int number;
int spaces;
OneTime(int _height, int _number) : height(_height),
number(_number), spaces(_height - _number) {};
};
I'm not saying that OneTime is preferable to Updating, I was just
unclear about which features of your Java code caused it to behave more
like Updating than like OneTime. As I now understand it,
javafx.beans.binding.NumberBinding is that feature.
--
James Kuyper
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2015-09-02 23:38 -0400 |
| Message-ID | <ms8fbm$mbo$1@dont-email.me> |
| In reply to | #32472 |
On 09/02/2015 06:49 PM, James Kuyper wrote:
> On 09/02/2015 05:25 PM, Stefan Ram wrote:
>> James Kuyper <jameskuyper@verizon.net> writes:
>>>> final javafx.beans.property.IntegerProperty height
>>>> = new javafx.beans.property.SimpleIntegerProperty( 10 );
>>>> final javafx.beans.property.IntegerProperty number
>>>> = new javafx.beans.property.SimpleIntegerProperty( 2 );
>>>> final javafx.beans.binding.NumberBinding spaces =
>>>> height.subtract( number );
>>>> java.lang.System.out.println( spaces.getValue() );
>>>> height.set( 20 );
>>>> java.lang.System.out.println( spaces.getValue() ); }}
>>> What's the java feature that makes "spaces" above update automatically?
>>> To put it another way - if I didn't want such updates, what should I
>>> write differently?
>>
>> This depends on the details of the behavior you want instead.
>
> I read a bit about Java many years ago, and reached the conclusion that
> it had some syntactic similarities C++, but had a very different way of
> implementing objects. I played with it long enough to get something
> working, but concluded that it wasn't what I needed for any purpose I
> was trying to achieve at the time. I'm otherwise very unfamiliar with java.
>
> I get the impression from what you're saying, that the code you've shown
> results in each call to spaces.getValue() performing a fresh calculation
> of height-number, using the values of those things at the time
> getValue() is called. I'm asking about what you would have to do
> differently to have spaces set to the value of height - number at one
> particular time, and to have spaces.getValue() continue to report that
> same value, even if the values of height and number later change. It
> seems to me that this should be easier than arranging for automatic
> updates - in fact, I'd expect it to be trivial.
>
>> For one example, you can simply omit »height.set( 20 )«, and
>> »spaces« will not be updated. Or, you could just write:
>
> Well, I'm asking how to ensure that "spaces" will not be updated, even
> if "height" is, so that doesn't qualify.
>
>> public final class Main
>> { public static void main( final java.lang.String[] args )
>> { final javafx.beans.property.IntegerProperty spaces
>> = new javafx.beans.property.SimpleIntegerProperty( 8 );
>> java.lang.System.out.println( spaces.getValue() ); }}
>>
>> Which just will print »8« and not update spaces, or just
>>
>> public final class Main
>> { public static void main( final java.lang.String[] args )
>> { int const spaces = 8; java.lang.System.out.println( spaces ); }}
>
> Those both set spaces to 8, rather than height - number. If
> height-number is currently 8, that happens to be the right value, but
> isn't what I'm looking for.
>
>> or just,
>>
>> public final class Main
>> { public static void main( final java.lang.String[] args )
>> { java.lang.System.out.println( 8 ); }}
>>
>> to get the same behavior.
>
> That seems to print out 8 without even storing it anywhere, and without
> any connection to "height" or "number".
>
You may use the unbind method of the
javafx.beans.property.Property<T> interface.
<https://docs.oracle.com/javase/8/javafx/api/javafx/beans/property/Property.html>
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
public class Main
{ public static void main(String[] args)
{
final IntegerProperty height
= new SimpleIntegerProperty();
final IntegerProperty number
= new SimpleIntegerProperty();
final IntegerProperty spaces
= new SimpleIntegerProperty();
spaces.bind(height.subtract(number));
height.set(10);
number.set(2);
System.out.print(spaces.get()); // 8
spaces.unbind();
height.set(20);
System.out.print(spaces.get()); // 8
} }
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2015-09-03 01:22 -0400 |
| Message-ID | <ms8ldr$5ko$1@dont-email.me> |
| In reply to | #32481 |
On 09/02/2015 11:38 PM, Jeff Higgins wrote:
> import javafx.beans.property.IntegerProperty;
> import javafx.beans.property.SimpleIntegerProperty;
>
> public class Main
> { public static void main(String[] args)
> {
>
> final IntegerProperty height
> = new SimpleIntegerProperty();
>
> final IntegerProperty number
> = new SimpleIntegerProperty();
>
> final IntegerProperty spaces
> = new SimpleIntegerProperty();
>
> spaces.bind(height.subtract(number));
>
> height.set(10);
> number.set(2);
> System.out.print(spaces.get()); // 8
>
> spaces.unbind();
> height.set(20);
> System.out.print(spaces.get()); // 8
>
> } }
So, if I take spaces to be a spreadsheet cell with an Observable value
it's a pretty simple matter to bind it to any of my CellFormula(s) which
are also Observable values of a type compatible with the spaces cell.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.java.programmer
csiph-web