{"id":4035,"date":"2011-07-31T17:58:31","date_gmt":"2011-07-31T12:28:31","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=4035"},"modified":"2016-12-19T15:06:23","modified_gmt":"2016-12-19T09:36:23","slug":"groovy-category-annotation","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/groovy-category-annotation\/","title":{"rendered":"Groovy Category Annotation"},"content":{"rendered":"<p>Annotations really provides a whole new view of programming things. Groovy also provides some of its own annotations one of them is Category. Lets take an example of using it. We create a IntegerUtil class and annotate it with Category.<\/p>\n<p>[java]<br \/>\n@Category(Integer)<br \/>\nclass IntegerUtil {<br \/>\n    List&amp;lt;Integer&amp;gt; multiples(Integer upto) {<br \/>\n        (1..upto).collect {this * it}<br \/>\n    }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>Now the above code made your class any other groovy category class for example Time Category. Now you can use these methods as follows -:<br \/>\n[java]<br \/>\nList&amp;lt;Integer&amp;gt; multiples<br \/>\nuse(IntegerUtil) {<br \/>\n    multiples = 2.multiples(10)<br \/>\n}<br \/>\nprintln multiples  \/\/ Output -: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]<br \/>\n[\/java]<\/p>\n<p>It really helps when you want some more helper methods on already existing classes.<br \/>\n<\/p>\n<p>Hope it helps<br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/author\/uday\/\">Uday Pratap Singh<\/a><br \/>\n<a href=\"mailto:uday@intelligrape.com\">uday@intelligrape.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Annotations really provides a whole new view of programming things. Groovy also provides some of its own annotations one of them is Category. Lets take an example of using it. We create a IntegerUtil class and annotate it with Category. [java] @Category(Integer) class IntegerUtil { List&amp;lt;Integer&amp;gt; multiples(Integer upto) { (1..upto).collect {this * it} } } [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[7],"tags":[612,613,614,611],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4035"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=4035"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4035\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=4035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=4035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=4035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}