Do you need to find interesting photos that would enhance your website and would perfectly match its color scheme? I found a perfect tool for that job.
Multicolr Search Lab by Idée Inc.
And these are the images that match colors of my blog:
Do you need to find interesting photos that would enhance your website and would perfectly match its color scheme? I found a perfect tool for that job.
And these are the images that match colors of my blog:
Posted by
Dushan Hanuska
at
Friday, December 05, 2008
0
comments
Labels: color, design, flickr, tools, web
Share this post: digg | del.icio.us | stumble spon | blogmarks | furl | linkroll | newsvine
Translate this post: French | German | Italian | Spanish | Japanese | Korean | Arabic | Chinese (Simplified)
Let's say we want to check the correct mimetype and file extension of the file being uploaded. In a typical Java way I would write something like this:
boolean isRightType = "image/jpeg".equals(contentType)
|| "image/png".equals(contentType)
|| "image/x-png".equals(contentType);
boolean isRightFileExt = filename.endsWith(".png")
|| filename.endsWith(".jpg")
|| filename.endsWith(".jpeg");
The Groovy way is much simpler and more elegant.
private static CONTENT_TYPES = ["image/jpeg", "image/png", "image/x-png"]
private static FILE_EXTENTIONS = [".png", ".jpg", ".jpeg"]
...
boolean isRightType = CONTENT_TYPES.any { it.equals(contentType) }
boolean isRightFileExt = FILE_EXTENTIONS.any { filename.endsWith(it) }
This was just a small example. What I really find useful are some of the following constructs that make my programming life really pleasant
Simple collection iteration
def fibList = [1, 1, 2, 3, 5, 8, 13]
fibList.each { println it } // prints all of the numbers in the list
If you need to find out if any element of the collection meets the condition.
def fibList = [1, 1, 2, 3, 5, 8, 13]
assert fibList.any { it == 3 }
assert fibList.any { it - 2 > 10 }
This is pretty much equivalent to a Java construct
boolean any(Listlist, Condition cond)
for (E e : list) {
if (cond.meets(e)) {
return true;
}
}
return false;
}
If you need to find out if any element of the collection meets the condition.
def fibList = [1, 1, 2, 3, 5, 8, 13]
assert fibList.every { it > 0 }
This is pretty much equivalent to a Java construct
boolean every(Listlist, Condition cond)
for (E e : list) {
if (!cond.meets(e)) {
return false;
}
}
return true;
}
If you need to create a new collection that contains each element of the original collection transformed in some way.
def fibList = [1, 1, 2, 3, 5, 8, 13]
assert fibList.collect { it - 1 } == [0, 0, 1, 2, 4, 7, 12]
This is pretty much equivalent to a Java construct
Listevery(List list, Command command)
Listresult = new ArrayList (list.size());
for (E e : list) {
result.add(command(e));
}
return result;
}
If you need to create a new collection that contains all elements that meet the condition.
def fibList = [1, 1, 2, 3, 5, 8, 13]
assert fibList.findAll { it > 1 && it < 5 } == [2, 3]
This is pretty much equivalent to a Java construct
ListfindAll(List list, Condition cond)
Listresult = new ArrayList (list.size());
for (E e : list) {
if (!cond.meets(e)) {
result.add(e);
}
}
return result;
}
If you need to find first element that matches the condition.
def fibList = [1, 1, 2, 3, 5, 8, 13]
assert fibList.find { it > 1 } == 2
This is pretty much equivalent to a Java construct
E findAll(Listlist, Condition cond)
for (E e : list) {
if (!cond.meets(e)) {
return e;
}
}
return null;
}
Posted by
Dushan Hanuska
at
Friday, December 05, 2008
3
comments
Labels: groovy, iteration, java, list
Share this post: digg | del.icio.us | stumble spon | blogmarks | furl | linkroll | newsvine
Translate this post: French | German | Italian | Spanish | Japanese | Korean | Arabic | Chinese (Simplified)
| Sun Certified |
| Java Programmer SCJP |
| Web Component Developer SCWCD |
| Business Component Developer SCBCD |
| Enterprise Architect SCEA |
| OMG UML Professional |
| OCUP - Fundamental |
| IBM Certified Solution Developer |
| WS Portal 5.1 |
| Java Black Belt |
- My Profile |