Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import static com.ociweb.jnb.april2008.Round2.Model.*; import static com.ociweb.jnb.april2008.Round2.Make.*; public class Round2 { enum Make { Ford, Chevrolet, Dodge } enum Model { Taurus, Focus, Mustang, Malibu, Impala, Corvette, Charger, Avenger, Viper } public static void main(String[] args) { Multimap<Make, Model> makeToModel = Multimaps.newHashMultimap(); makeToModel.put(Ford, Taurus); makeToModel.put(Ford, Focus); makeToModel.put(Ford, Mustang); makeToModel.put(Chevrolet, Malibu); makeToModel.put(Chevrolet, Impala); makeToModel.put(Chevrolet, Corvette); makeToModel.put(Dodge, Charger); makeToModel.put(Dodge, Avenger); makeToModel.put(Dodge, Viper); // forward search Make searchMake = Dodge; System.out.printf("%s makes ", searchMake); for (Model model : makeToModel.get(searchMake)) { System.out.printf("%s,", model); } System.out.printf("\n"); // invert the map Multimap<Model, Make> modelToMake = Multimaps.inverseHashMultimap(makeToModel); // reverse search Model searchModel = Impala; System.out.printf("model %s is made by %s\n", searchModel, modelToMake.get(searchModel)); } }
This paste will be private.
From the Design Piracy series on my blog: