Use Advanced Search to search the entire archive.
Re: Add five methods in Quantity interface[Proposal]
- From: Otávio Gonçalves de Santana <
>
- To:
- Subject: Re: Add five methods in Quantity interface[Proposal]
- Date: Sat, 1 Nov 2014 08:33:34 -0200
I remembered you had this discussion about the comparable and the
conclusion was we shouldn't put in the interface and each implementation
could or not have it.
In Java SE implementation already exist in Functions some kinds of sort.
https://github.com/unitsofmeasurement/unit-impl-se/blob/master/src/main/java/tec/uom/se/function/QuantityFunctions.java
In this classes in the constructor we can put the Comparator, too.
But don't want return this discussion again, just to remember.
On Sat, Nov 1, 2014 at 7:44 AM, Martin Desruisseaux <
>
wrote:
>
Implementing Comparable still necessary if one want to use the Quantity
>
in an ordered collection like TreeSet, or in Range structure, etc. Indeed,
>
the LocalTime and LocalDate examples that you gave implement Comparable,
>
and I presume that their "isBefore" ans "isAfter" methods are only
>
convenience methods delegating to "compareTo". Note also that they do not
>
provide methods for all possible combination ("isGreaterThanOrEquals",
>
etc.). For those cases, users can invoke "compareTo".
>
>
I have no objection against Comparable quantities. About methods like
>
"isGreater", they are convenience methods, not new functionalities. Some
>
convenience methods are sometime good - but I think we need to be careful
>
to not put too many of them.
>
>
Martin
>
>
>
>
>
Le 01/11/14 18:23, Otávio Gonçalves de Santana a écrit :
>
>
Martin, using the compareto method is really simple to make this.
>
About why create this method, is because we are in DSL age, to make our
>
code more expressive.
>
For example if you look new API how the JSR 310, it is not using
>
getInstance how the old API, but .now to create a instance in the exact
>
moment.
>
>
I believe is more expressive use:
>
>
Calendar calendar = Calendar.getInstance();
>
LocalTime time = LocalTime.now();
>
>
Talking about this JSR, it has comparative method, so the JSR 354 has
>
too.
>
>
http://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html
>
http://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html
>
http://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html
>
>
>
>
On Sat, Nov 1, 2014 at 12:56 AM, Martin Desruisseaux <
>
>
>
wrote:
>
>
> Le 01/11/14 04:36, Otávio Gonçalves de Santana a écrit :
>
>
>
> I would like to propose to add four new comparatives methods in
>
> Quantity interface:
>
>
>
> - boolean isGreaterThan(Quantity<T> quantity);
>
> - boolean isGreaterThanOrEqualTo(Quantity<T> quantity);
>
> - boolean isLessThan(Quantity<T> quantity);
>
> - boolean isLessThanOrEqualTo(Quantity<T> quantity);
>
> - boolean isEquivalentTo(Quantity<T> quantity);
>
>
>
> Why not just implement the int compareTo(Quantity<Q>) method that we
>
> could inherit from the Comparable interface instead? But I agree with
>
> Werner, we need to sort out the Measurement - Quantity relationship
>
> first.
>
>
>
> Martin
>
>
>
>
--
Otávio Gonçalves de Santana
blog:
http://otaviosantana.blogspot.com.br/
twitter:
http://twitter.com/otaviojava
site: *
http://about.me/otaviojava <
http://about.me/otaviojava>*
55 (11) 98255-3513