Hi Marianne,
I think you just need to do an Integer.parseInt(...) around each call to
p.getRegulationNumber(). I guess if the value is non parseable then it
should catch any exception and return a suitable value.
ie, replace:
p.getRegulationNumber()
with
parseInt(p.getRegulationNumber())
where
int parseInt(String str) {
try{ return Integer.parseInt(str); } catch(Exception ex) {
return -1; }
}
HTH
Dan
On 19 April 2016 at 19:37, Marianne Hagaseth <
[email protected]> wrote:
> Hi,
> Which function to use to be able to return "1","2","3","10","11", and not
> "1","10","11","2","3" (String values)?
>
> public static class RegulationsComparator implements
> Comparator<Regulation> {
> @Override
> public int compare(Regulation p, Regulation q) {
> Ordering<Regulation> byRegulationNumber = new
> Ordering<Regulation>() {
> public int compare(final Regulation p, final Regulation q) {
> return
> Ordering.natural().nullsFirst().compare(p.getRegulationNumber(),q.getRegulationNumber());
> }
> };
> return byRegulationNumber
> .compound(Ordering.<Regulation>natural())
> .compare(p, q);
> }
> }
>
>
>
> Med vennlig hilsen / Best regards,
> Marianne Hagaseth
> Forsker - Maritime transportsystemer
> Research Scientist - Maritime Transport Systems
>
> MARINTEK (Norsk Marinteknisk Forskningsinstitutt AS)
> Address: POB 4125 Valentinlyst, NO-7450 Trondheim, Norway
> Mobile: +47 90 95 64 69 - Phone: +47 464 15 000
> Web: www.marintek.sintef.no<http://www.marintek.sintef.no/>
>
>