Coding in the small with Google Collections: AbstractIterator (5)
share
digg
by
swankjesse (0)
on
Public Object (0)
3 weeks, 1 day
ago
permalink
Part 17 in a Series.I really like the Java Collections API. So much so, that I use 'em when I'm doing work that isn't particularly collectioney. For example, I recently wrote a quick-n-dirty app that rewrote some files line-by-line. Instead of using a Reader as input, I used an Iterator<String>. The easiest way to create such an iterator is to load the entire file into memory first.Before: public Iterator<String> linesIterator(Reader reader) { BufferedReader buffered = ...
Coding in the small with Google Collections: Sets.union, intersection and difference (2)
share
digg
by
swankjesse (0)
on
Public Object (0)
3 weeks, 2 days
ago
permalink
Part 16 in a Series.The traditional approach to unions is to first create a new Set, and then to addAll using each component set. You can use a similar approach to do differences and intersections.Before: private static final ImmutableSet<String> LEGAL_PARAMETERS; static { Set<String> tmp = new HashSet<String>(); tmp.addAll(REQUIRED_PARAMETERS); tmp.addAll(OPTIONAL_PARAMETERS); LEGAL_PARAMETERS = ImmutableSet.copyOf(tmp); } public void login(Map<String, String> params) { if (!LEGAL_PARAMETERS.containsAll(params.keySet())) { Set<String> unrecognized = new HashSet<String>(params.keySet()); unrecognized.removeAll(LEGAL_PARAMETERS); throw new IllegalArgumentException("Unrecognized parameters: " + unrecognized); ...
Correctness and my wife (2)
share
digg
by
swankjesse (0)
on
Public Object (0)
1 month, 1 week
ago
permalink
I do this really annoying thing when I'm hanging out with my wife. I correct her when she uses the "wrong" words...We're walking around town when we see something out of the ordinary - like a humongous fat dog or a friendly hobo or a police chase.Her: "That was random"Me: "It was unexpected. Nothing really random about it."Her: "Ohhkayyy programmer boy. It was random. Get over it.Our apartment is in a bit of a ghetto. ...
-
ydant said:
This is all too familiar.
Don't create multiple annotations with the same simple name (1)
share
digg
by
swankjesse (0)
on
Public Object (0)
1 month, 2 weeks
ago
permalink
Nobody reads imports. Good IDEs do their best to pretend imports don't even exist - they'll hide 'em from you, and manage them for you. They'll even add imports on demand when you're writing new code.Suppose you create your own, say @Inject or @RequestScoped annotation. In the code, it's practically impossible to differentiate between this and a Guice-supplied annotation:package com.publicobject.pizza;import com.google.common.base.Preconditions;import com.google.common.collect.ImmutableSet;import com.google.inject.Injector;import com.google.inject.Provider;import com.publicobject.pizza.annotation.RequestScoped;import com.publicobject.pizza.annotation.Inject;import com.publicobject.pizza.geography.GeographyService;import com.publicobject.pizza.hr.EmployeeRoster;@RequestScopedpublic class PizzaStore { @Inject PizzaStore(GeographyService geography, EmployeeRoster ...
TypeResolver tells you what List.get() returns (1)
share
digg
by
swankjesse (0)
on
Public Object (0)
1 month, 2 weeks
ago
permalink
It's diminishingly rare that I get to write code that improves the internals of both Glazed Lists and Guice...Glazed Lists' BeanPropertyBeanProperty is a convenient utility class that can expose a JavaBeans getter/setter property as its own object. You give it a class (like Baz.class) and a property name (like "bar") and it gives you a full property object - you can use it to read and write the property. It even exposes the property's type:class ...
The reasons I'm not on iPhone (6)
share
digg
by
swankjesse (0)
on
Public Object (0)
1 month, 2 weeks
ago
permalink
It's really tempting. As far as devices go, iPhone 3G is the best there is. It's a generation ahead of its competitors, and the gap is growing. The app store is great for both developers and for its users. But I'm not gonna get one:Amazon MP3. Lots of good songs with no 'deregister this computer' nonsense. But Amazon MP3 cannot compete with iTunes on Apple's platform—third party apps can't download while I surf the web. ...
-
dafmetal said:
Good to see that some valid iPhone criticism is getting out as well.