22
33import java .io .PrintWriter ;
44import java .io .StringWriter ;
5- import java .math .BigDecimal ;
65import java .util .Arrays ;
76import java .util .HashSet ;
87
@@ -29,8 +28,7 @@ public MinMaxSample() {
2928 setExampleCode (loadExample ("/samples/Extensions.javatxt" ));
3029 }
3130
32- public final static class ExamplePane extends
33- AbstractSingleSamplePane {
31+ public final static class ExamplePane extends AbstractSingleSamplePane {
3432
3533 private HBox exPane = new HBox ();
3634 private AmountEntry amount1 = new AmountEntry ("Amount 1" );
@@ -43,78 +41,79 @@ public ExamplePane() {
4341 AnchorPane .setLeftAnchor (exPane , 10d );
4442 AnchorPane .setTopAnchor (exPane , 10d );
4543 Button minButton = new Button ("Calculate MIN" );
46- minButton
47- .setOnAction (new javafx .event .EventHandler <ActionEvent >() {
48- public void handle (ActionEvent action ) {
49- StringWriter sw = new StringWriter ();
50- PrintWriter pw = new PrintWriter (sw );
51- try {
52- MonetaryAmount min = MonetaryCalculations .minimum ().calculate (new HashSet (Arrays .asList (
53- amount1 .getAmount (), amount2 .getAmount (),
54- amount3 .getAmount ())));
55- pw .println ("MonetaryAmount (Min)" );
56- pw .println ("--------------------" );
57- pw .println ();
58- printSummary (min , pw );
59- } catch (Exception e ) {
60- e .printStackTrace (pw );
61- }
62- pw .flush ();
63- ExamplePane .this .outputArea .setText (sw
64- .toString ());
65- }
44+ minButton .setOnAction (new javafx .event .EventHandler <ActionEvent >() {
45+ public void handle (ActionEvent action ) {
46+ StringWriter sw = new StringWriter ();
47+ PrintWriter pw = new PrintWriter (sw );
48+ try {
49+ MonetaryAmount min = MonetaryCalculations .minimum ()
50+ .calculate (
51+ new HashSet <MonetaryAmount >(Arrays
52+ .asList (amount1 .getAmount (),
53+ amount2 .getAmount (),
54+ amount3 .getAmount ())));
55+ pw .println ("MonetaryAmount (Min)" );
56+ pw .println ("--------------------" );
57+ pw .println ();
58+ printSummary (min , pw );
59+ } catch (Exception e ) {
60+ e .printStackTrace (pw );
61+ }
62+ pw .flush ();
63+ ExamplePane .this .outputArea .setText (sw .toString ());
64+ }
6665
67- private void printSummary (MonetaryAmount amount ,
68- PrintWriter pw ) {
69- pw .println ("Class: " + amount .getClass ().getName ());
70- if (amount instanceof Money ) {
71- Money asMoney = (Money )amount ;
72- pw .println ("Value (BD): "
73- + asMoney .getNumber ());
74- pw .println ("Value (double): "
75- + asMoney .getNumber ().doubleValue ());
76- pw .println ("Precision: " + asMoney .getNumber ().getPrecision ());
77- pw .println ("Scale: " + asMoney .getNumber ().getScale ());
78- }
79- }
80- });
66+ private void printSummary (MonetaryAmount amount , PrintWriter pw ) {
67+ pw .println ("Class: " + amount .getClass ().getName ());
68+ if (amount instanceof Money ) {
69+ Money asMoney = (Money ) amount ;
70+ pw .println ("Value (BD): " + asMoney .getNumber ());
71+ pw .println ("Value (double): "
72+ + asMoney .getNumber ().doubleValue ());
73+ pw .println ("Precision: "
74+ + asMoney .getNumber ().getPrecision ());
75+ pw .println ("Scale: " + asMoney .getNumber ().getScale ());
76+ }
77+ }
78+ });
8179 Button maxButton = new Button ("Calculate MAX" );
82- maxButton
83- .setOnAction (new javafx .event .EventHandler <ActionEvent >() {
84- public void handle (ActionEvent action ) {
85- StringWriter sw = new StringWriter ();
86- PrintWriter pw = new PrintWriter (sw );
87- try {
88- MonetaryAmount max = MonetaryCalculations .maximum ().calculate (new HashSet (Arrays .asList (
89- amount1 .getAmount (), amount2 .getAmount (),
90- amount3 .getAmount ())));
91- pw .println ("MonetaryAmount (Max)" );
92- pw .println ("--------------------" );
93- pw .println ();
94- printSummary (max , pw );
95- } catch (Exception e ) {
96- e .printStackTrace (pw );
97- }
98- pw .flush ();
99- ExamplePane .this .outputArea .setText (sw
100- .toString ());
101- }
80+ maxButton .setOnAction (new javafx .event .EventHandler <ActionEvent >() {
81+ public void handle (ActionEvent action ) {
82+ StringWriter sw = new StringWriter ();
83+ PrintWriter pw = new PrintWriter (sw );
84+ try {
85+ MonetaryAmount max = MonetaryCalculations .maximum ()
86+ .calculate (
87+ new HashSet <MonetaryAmount >(Arrays
88+ .asList (amount1 .getAmount (),
89+ amount2 .getAmount (),
90+ amount3 .getAmount ())));
91+ pw .println ("MonetaryAmount (Max)" );
92+ pw .println ("--------------------" );
93+ pw .println ();
94+ printSummary (max , pw );
95+ } catch (Exception e ) {
96+ e .printStackTrace (pw );
97+ }
98+ pw .flush ();
99+ ExamplePane .this .outputArea .setText (sw .toString ());
100+ }
102101
103- private void printSummary (MonetaryAmount amount ,
104- PrintWriter pw ) {
105- pw . println ( "Class: " + amount . getClass (). getName ());
106- if ( amount instanceof Money ) {
107- Money asMoney = ( Money ) amount ;
108- pw .println ("Value (BD ): "
109- + asMoney .getNumber ());
110- pw .println ("Value (double) : "
111- + asMoney .getNumber ().doubleValue ());
112- pw .println ("Precision : " + asMoney .getNumber ().getPrecision ());
113- pw . println ( "Scale: " + asMoney . getNumber (). getScale ());
114- }
115- }
116- });
117- buttonPane . getChildren (). addAll ( minButton , new Label ( " " ), maxButton );
102+ private void printSummary (MonetaryAmount amount , PrintWriter pw ) {
103+ pw . println ( "Class: " + amount . getClass (). getName ());
104+ if ( amount instanceof Money ) {
105+ Money asMoney = ( Money ) amount ;
106+ pw . println ( "Value (BD): " + asMoney . getNumber ()) ;
107+ pw .println ("Value (double ): "
108+ + asMoney .getNumber (). doubleValue ());
109+ pw .println ("Precision : "
110+ + asMoney .getNumber ().getPrecision ());
111+ pw .println ("Scale : " + asMoney .getNumber ().getScale ());
112+ }
113+ }
114+ });
115+ buttonPane . getChildren (). addAll ( minButton , new Label ( " " ),
116+ maxButton );
118117 }
119118 }
120119}
0 commit comments