Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Utility for arrays?
Utility for arrays? [message #645445] Fri, 17 December 2010 09:43 Go to next message
Michael Schaufelberger is currently offline Michael Schaufelberger
Messages: 3
Registered: December 2010
Junior Member
Scout's utilities are very practical. E.g. if I want to know the length of a string variable "text", instead of writing
int length = text == null ? 0 : text.length();

I can use the StringUtility:
int length = StringUtility.length(text);


Is there a similar way for arrays (e.g. byte[])? I only found the CollectionUtility with which I'd have to convert my array to a List. Why is there no ArrayUtility?
Re: Utility for arrays? [message #645451 is a reply to message #645445] Fri, 17 December 2010 09:59 Go to previous messageGo to next message
Stephan Leicht Vogt is currently offline Stephan Leicht Vogt
Messages: 102
Registered: February 2010
Location: Baden Switzerland
Senior Member

To get the length of an array you could to following:
int size = ListUtility.toList(someByte[]).size();


This will work without exception even if someByte[] would be null.

But i filed a bug to make this even more easy: https://bugs.eclipse.org/bugs/show_bug.cgi?id=332831
Re: Utility for arrays? [message #645461 is a reply to message #645451] Fri, 17 December 2010 10:12 Go to previous messageGo to next message
Michael Schaufelberger is currently offline Michael Schaufelberger
Messages: 3
Registered: December 2010
Junior Member
Thanks for the fast reply and filing the bug!

Actually, I tried your workaround before already, but did not realize that printing the result seems changes it (?):
byte[] b = null;
System.out.println(ListUtility.toList(b).size());

prints "1" even though size() returns 0 (at least in debug mode)

weird..
Re: Utility for arrays? [message #645481 is a reply to message #645461] Fri, 17 December 2010 12:24 Go to previous message
Michael Schaufelberger is currently offline Michael Schaufelberger
Messages: 3
Registered: December 2010
Junior Member
It seems that eclipse's "inspect" in debug mode shows the wrong value, size() really returns 1:
byte[] b = null;
System.out.println(1 == ListUtility.toList(b).size());

outputs "true"

so I still have to write
output == null ? 0 : output.length

until there's an ArrayUtility

however, any other suggestions are still appreciated, of course
Previous Topic:Questions: Scout Source Code Repository / Roadmap
Next Topic:JavaMail and JAX-WS in Eclipse Scout
Goto Forum:
  


Current Time: Fri Oct 24 20:49:44 GMT 2014

Powered by FUDForum. Page generated in 0.01635 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software