Check whether a variable is an Array - grails

I want to find out whether a variable is an array or not
if (params.writtenLines == ???)
Much appreciated.

More importantly, why do you want to check whether it's an array? If you know the parameter might be a single string or a list, you can now use:
def lines = params.list("writtenLines")
That came with Grails 1.2.

This functionality is already available in pure Java and can therefore be used in Groovy, too:
if (params.writtenLines.class.isArray())

I realize this is a bit late, but what about this:
List.isCase(params.writtenLines)
Wouldn't it be a correct solution, too?

Related

How to implement Object.try! in Ruby on Rails?

I'd like to shorten code like the following:
content = content.join("\n") if content.respond_to? :join
into this:
content.try!(:join, "\n")
Is this a good idea, and can it be implemented in terms of the existing Object.try?
If I understand correctly, you want a version of try that modifies the object in-place, as in the difference between x = x.reverse and x.reverse!
To answer your questions...
Is this a good idea
No, it's not, it's actually impossible.
Can it be implemented in terms o the existing Object.try?
No, it can't, either with or without Object.try, it cannot be implemented at all. You cannot change an object's type in-place.
Using .join on an array produces a string. You cannot change an array in-place to become a string. This is why there is no join! method in the first place. Many of the methods on Array and Enumerable have versions with and without !. Many other methods do not have a ! version. This is because the ! version cannot be implemented.
In general, if you have a method like reverse and it's in-place equivalent reverse! you can already use try just fine:
content.try(:reverse!)
If the ! method doesn't already exist, such as join and the non-existent join!, it's because it cannot work, and you cannot make it work with a hypothetical try!.
Note that you can make something like this work with a proxy object, but this is a horrible overwrought solution to a nonexistent problem.
Just use content = content.join("\n") if content and be done with it.

Is there in grails something like domainClass.addToAll? for one to many or many to many

do we have in gorm something like addAll method in groovy?, i mean something like
someDomainClass.addToAll***
No we do not. But it is easy to work around:
[child1, child2, child3].each { parent.addToChildren it }
This question has a good answer here Syntax for "addAll()" to list in grails?.
I don't know why a addAllToEntity wouldn't exist, but it wouldn't do much more then the loop mentioned in the answers (the one you got and the one I suggested), would it?

Is there anything called Execute Non Scalar

Is there anything called ExecuteNonScalar ? in any of the programming language.
No. But there is ExecuteNonQuery, and ExecuteScalar.
Well there is a method called "ExecuteScalar" in .NET. It basically returns the first column of first resultant row.
For more info and example you may check this: link

Is ImageFigure() Constructor present in graphiti.js like draw2d?

i found one method ImageFigure() in draw2d. So i want to know is it presnt in graphiti.js also. If it present in graphiti then it solves my problem on grouping object.
Thanks In advance.
ImageShape or ImageFigure is not part of the current graphiti version. Graphiti tries to implement almost all functions/object from Draw2D......but it requires some time.

inet_addr functionality in erlang

As the question says, is there any function or module that performs the functionality of inet_addr ?
Results from google isnt suggesting any direct way or am i missing something ?
Thanks.
You can use inet_parse:address, and then convert the resuting list to binary. e.g.
16> list_to_binary(tuple_to_list(element(2,inet_parse:address("192.168.42.2")))).
<<192,168,42,2>>

Resources