[lang]

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[lang]

garydgregory
Hi All:

Do you think this is general enough for [lang]?

/**
 * Implements {@code Comparator<Object>} using toString()s.
 *
 */
public final class ObjectToStringComparator implements Comparator<Object>,
Serializable {

    private static final long serialVersionUID = 1L;

    @Override
    public int compare(final Object o1, final Object o2) {
        if (o1 == null && o2 == null) {
            return 0;
        }
        if (o1 == null) {
            return 1;
        }
        if (o2 == null) {
            return -1;
        }
        return o1.toString().compareTo(o2.toString());
    }
}

--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Matt Benson-2
This is dead easy in Java 8:

Comparator.comparing(Object::toString)

Granted, you have to do a little more for null handling, but I'm not sure
it's worth writing out a class definition in this form. If we are intending
to cater to pre Java 8 clients, okay, but it seems a little late in the
game to me.

Matt


On May 1, 2017 2:46 PM, "Gary Gregory" <[hidden email]> wrote:

Hi All:

Do you think this is general enough for [lang]?

/**
 * Implements {@code Comparator<Object>} using toString()s.
 *
 */
public final class ObjectToStringComparator implements Comparator<Object>,
Serializable {

    private static final long serialVersionUID = 1L;

    @Override
    public int compare(final Object o1, final Object o2) {
        if (o1 == null && o2 == null) {
            return 0;
        }
        if (o1 == null) {
            return 1;
        }
        if (o2 == null) {
            return -1;
        }
        return o1.toString().compareTo(o2.toString());
    }
}

--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_
tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_
tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_
tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Reply | Threaded
Open this post in threaded view
|

Re: [lang]

garydgregory
True. I wonder if we need to make some kind of documented statement that we
will not provide utils for things easily done in Java 8?

Gary

On Mon, May 1, 2017 at 1:13 PM, Matt Benson <[hidden email]> wrote:

> This is dead easy in Java 8:
>
> Comparator.comparing(Object::toString)
>
> Granted, you have to do a little more for null handling, but I'm not sure
> it's worth writing out a class definition in this form. If we are intending
> to cater to pre Java 8 clients, okay, but it seems a little late in the
> game to me.
>
> Matt
>
>
> On May 1, 2017 2:46 PM, "Gary Gregory" <[hidden email]> wrote:
>
> Hi All:
>
> Do you think this is general enough for [lang]?
>
> /**
>  * Implements {@code Comparator<Object>} using toString()s.
>  *
>  */
> public final class ObjectToStringComparator implements Comparator<Object>,
> Serializable {
>
>     private static final long serialVersionUID = 1L;
>
>     @Override
>     public int compare(final Object o1, final Object o2) {
>         if (o1 == null && o2 == null) {
>             return 0;
>         }
>         if (o1 == null) {
>             return 1;
>         }
>         if (o2 == null) {
>             return -1;
>         }
>         return o1.toString().compareTo(o2.toString());
>     }
> }
>
> --
> E-Mail: [hidden email] | [hidden email]
> Java Persistence with Hibernate, Second Edition
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
> 18%22>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Rob Tompkins


> On May 1, 2017, at 4:33 PM, Gary Gregory <[hidden email]> wrote:
>
> True. I wonder if we need to make some kind of documented statement that we
> will not provide utils for things easily done in Java 8?
>

I wonder if we would want to wait until Java 9 general availability to make such a statement. But that also may be arbitrary.

-Rob

> Gary
>
>> On Mon, May 1, 2017 at 1:13 PM, Matt Benson <[hidden email]> wrote:
>>
>> This is dead easy in Java 8:
>>
>> Comparator.comparing(Object::toString)
>>
>> Granted, you have to do a little more for null handling, but I'm not sure
>> it's worth writing out a class definition in this form. If we are intending
>> to cater to pre Java 8 clients, okay, but it seems a little late in the
>> game to me.
>>
>> Matt
>>
>>
>> On May 1, 2017 2:46 PM, "Gary Gregory" <[hidden email]> wrote:
>>
>> Hi All:
>>
>> Do you think this is general enough for [lang]?
>>
>> /**
>> * Implements {@code Comparator<Object>} using toString()s.
>> *
>> */
>> public final class ObjectToStringComparator implements Comparator<Object>,
>> Serializable {
>>
>>    private static final long serialVersionUID = 1L;
>>
>>    @Override
>>    public int compare(final Object o1, final Object o2) {
>>        if (o1 == null && o2 == null) {
>>            return 0;
>>        }
>>        if (o1 == null) {
>>            return 1;
>>        }
>>        if (o2 == null) {
>>            return -1;
>>        }
>>        return o1.toString().compareTo(o2.toString());
>>    }
>> }
>>
>> --
>> E-Mail: [hidden email] | [hidden email]
>> Java Persistence with Hibernate, Second Edition
>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
>> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
>> 1617290459>
>> JUnit in Action, Second Edition
>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
>> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
>> 18%22>
>>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
>> 1935182021>
>> Spring Batch in Action
>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
>> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
>> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
>> 1935182951>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> E-Mail: [hidden email] | [hidden email]
> Java Persistence with Hibernate, Second Edition
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang]

garydgregory
In my mind, we target a given platform, in this case its Java 7. So the
proposal is valid IMO. Then when switch to Java 8, we can mark the class as
deprecated and remove it in 4.0. I'm not hard set on including this
specific class, it's just something I use.

Gary

On Mon, May 1, 2017 at 1:36 PM, Rob Tompkins <[hidden email]> wrote:

>
>
> > On May 1, 2017, at 4:33 PM, Gary Gregory <[hidden email]> wrote:
> >
> > True. I wonder if we need to make some kind of documented statement that
> we
> > will not provide utils for things easily done in Java 8?
> >
>
> I wonder if we would want to wait until Java 9 general availability to
> make such a statement. But that also may be arbitrary.
>
> -Rob
>
> > Gary
> >
> >> On Mon, May 1, 2017 at 1:13 PM, Matt Benson <[hidden email]>
> wrote:
> >>
> >> This is dead easy in Java 8:
> >>
> >> Comparator.comparing(Object::toString)
> >>
> >> Granted, you have to do a little more for null handling, but I'm not
> sure
> >> it's worth writing out a class definition in this form. If we are
> intending
> >> to cater to pre Java 8 clients, okay, but it seems a little late in the
> >> game to me.
> >>
> >> Matt
> >>
> >>
> >> On May 1, 2017 2:46 PM, "Gary Gregory" <[hidden email]> wrote:
> >>
> >> Hi All:
> >>
> >> Do you think this is general enough for [lang]?
> >>
> >> /**
> >> * Implements {@code Comparator<Object>} using toString()s.
> >> *
> >> */
> >> public final class ObjectToStringComparator implements
> Comparator<Object>,
> >> Serializable {
> >>
> >>    private static final long serialVersionUID = 1L;
> >>
> >>    @Override
> >>    public int compare(final Object o1, final Object o2) {
> >>        if (o1 == null && o2 == null) {
> >>            return 0;
> >>        }
> >>        if (o1 == null) {
> >>            return 1;
> >>        }
> >>        if (o2 == null) {
> >>            return -1;
> >>        }
> >>        return o1.toString().compareTo(o2.toString());
> >>    }
> >> }
> >>
> >> --
> >> E-Mail: [hidden email] | [hidden email]
> >> Java Persistence with Hibernate, Second Edition
> >> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> >> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> >> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2
> b8>
> >>
> >> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> >> 1617290459>
> >> JUnit in Action, Second Edition
> >> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> >> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> >> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
> >> 18%22>
> >>
> >> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> >> 1935182021>
> >> Spring Batch in Action
> >> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> >> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> >> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> >> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> >> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> >> 1935182951>
> >> Blog: http://garygregory.wordpress.com
> >> Home: http://garygregory.com/
> >> Tweet! http://twitter.com/GaryGregory
> >>
> >
> >
> >
> > --
> > E-Mail: [hidden email] | [hidden email]
> > Java Persistence with Hibernate, Second Edition
> > <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
> >
> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1617290459>
> > JUnit in Action, Second Edition
> > <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22
> >
> >
> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182021>
> > Spring Batch in Action
> > <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182951>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Stian Soiland-Reyes
Adding a class with a plan to @deprecate it, something doesn't sound right.
:)

We should not be putting much effort (and future maintainability) into
adding functionality in Lang that jdk8 already (easily) can do. The point
of Lang is to complement JDK's Lang classes and friends, not to backport
what the current JDK has already added.

(Obviously existing Lang functionality is or will be superseded by new JDK
additions, that just shows that the philosophy of Lang is right.)

If you are stuck in jdk7 you are often also stuck with older Commons Lang.
(Oversimplification, yes)

We have java7 as target (I'm positive to bump it to 8) - but primarily for
backwards compatibility as Lang is ubiquitous and it makes sense to stay
one behind. But we don't need to add *new* backwards compatibility :)

We could make excemptions and do backports, but then I think that should be
for more core JDK8 improvements like Optional.

That said, your implementation is straightforward​, useful, and unlikely to
cause trouble; I would not veto your commit if it goes forward ;)


On 1 May 2017 9:40 pm, "Gary Gregory" <[hidden email]> wrote:

In my mind, we target a given platform, in this case its Java 7. So the
proposal is valid IMO. Then when switch to Java 8, we can mark the class as
deprecated and remove it in 4.0. I'm not hard set on including this
specific class, it's just something I use.
Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Rob Tompkins


> On May 1, 2017, at 8:25 PM, Stian Soiland-Reyes <[hidden email]> wrote:
>
> Adding a class with a plan to @deprecate it, something doesn't sound right.
> :)
>
> We should not be putting much effort (and future maintainability) into
> adding functionality in Lang that jdk8 already (easily) can do. The point
> of Lang is to complement JDK's Lang classes and friends, not to backport
> what the current JDK has already added.
>
> (Obviously existing Lang functionality is or will be superseded by new JDK
> additions, that just shows that the philosophy of Lang is right.)
>
> If you are stuck in jdk7 you are often also stuck with older Commons Lang.
> (Oversimplification, yes)
>
> We have java7 as target (I'm positive to bump it to 8) - but primarily for
> backwards compatibility as Lang is ubiquitous and it makes sense to stay
> one behind. But we don't need to add *new* backwards compatibility :)

Curious. This sounds like an argument for major versioning Lang in step with java, which seems natural.

>
> We could make excemptions and do backports, but then I think that should be
> for more core JDK8 improvements like Optional.
>
> That said, your implementation is straightforward​, useful, and unlikely to
> cause trouble; I would not veto your commit if it goes forward ;)
>
>
> On 1 May 2017 9:40 pm, "Gary Gregory" <[hidden email]> wrote:
>
> In my mind, we target a given platform, in this case its Java 7. So the
> proposal is valid IMO. Then when switch to Java 8, we can mark the class as
> deprecated and remove it in 4.0. I'm not hard set on including this
> specific class, it's just something I use.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]