The Daily WTF
Let’s say your company wanted to offer special deals. When a customer calls about one of these deals, you want to play an automated customer support message using SignalWire, a tool for scripting phone voice trees.
This is a natural case for using a Map data structure. Which is what Ajay‘s predecessor did. They just… uh… weren’t sure how to use a Map.
public String convert(Deal deal) { List<Deal> single = Collections.singletonList(deal); Map<Deal, String> swml = client.getSWMLs(single, version); for(Map.Entry<Deal, String> entry : swml.entrySet()) { if (deal.equals(entry.getKey())) { return entry.getValue(); } } return “”; }
This Java code looks like a case of trying to fit some APIs together awkwardly.
Our function takes a Deal object. The client.getSWMLs function apparently requires a list as its input, because we start by converting the input into a singletonList- a list with one item in it.
client.getSWMLs then returns a map, presumably mapping
To read the full article click on the 'post' link at the top.