Option A:
static <X, Y, Z> Map<X, Z> transform(Map<? extends X, ? extends Y> input, Function<Y, Z> function) { return input.keySet().stream() .collect(Collectors.toMap(Function.identity(), key -> function.apply(input.get(key)))); }
static <X, Y, Z> Map<X, Z> transform1(Map<? extends X, ? extends Y> input, Function<Y, Z> function) { Map<X, Z> result = new HashMap<>(); input.forEach((k, v) -> result.put(k, function.apply(v))); return result; }
protected boolean isCashBasis(CalendarDate effectiveDate) { return priorVatReturns.stream() .filter(r -> r.period.contains(effectiveDate)) .findFirst() .map(r -> r.basis == AccountingBasis.CASH_BASIS) .orElseGet(() -> super.isCashBasis(effectiveDate)); }
protected boolean isCashBasis(CalendarDate effectiveDate) { for (VatReturn r : priorVatReturns) { if (r.period.contains(effectiveDate)) { return r.basis == AccountingBasis.CASH_BASIS; } } return super.isCashBasis(effectiveDate); }
[0] https://stackoverflow.com/a/25905196/76295
Option A:
Option B: Personally I find Option B more readable. Another example:Option A:
Option B: Again I would choose Option B, although I suppose Option A isn't too bad.[0] https://stackoverflow.com/a/25905196/76295