/** * Obtains an instance from a list of cash flows. * * @param cashFlows the list of cash flows * @return the cash flows instance */ public static CashFlows of(List<CashFlow> cashFlows) { return new CashFlows(cashFlows); }
@Override public CashFlows build() { return new CashFlows( cashFlows); }
/** * Combines this cash flows instance with another cash flow. * <p> * This returns a new cash flows instance with a combined list of cash flow instances. * This instance is immutable and unaffected by this method. * The result may contain duplicate cash flows. * * @param cashFlow the additional single cash flow * @return the new instance of {@code CashFlows} based on this instance, with the additional single cash flow added */ public CashFlows combinedWith(CashFlow cashFlow) { return new CashFlows(ImmutableList.<CashFlow>builder() .addAll(cashFlows) .add(cashFlow) .build()); }
/** * Combines this cash flows instance with another one. * <p> * This returns a new cash flows instance with a combined list of cash flow instances. * This instance is immutable and unaffected by this method. * The result may contain duplicate cash flows. * * @param other the other cash flows * @return the new instance of {@code CashFlows} based on this instance, with the other instance added */ public CashFlows combinedWith(CashFlows other) { return new CashFlows(ImmutableList.<CashFlow>builder() .addAll(cashFlows) .addAll(other.cashFlows) .build()); }
/** * Returns an instance that is sorted. * <p> * The sort is by date, then value. * * @return the sorted instance */ public CashFlows sorted() { if (Ordering.natural().isOrdered(cashFlows)) { return this; } else { return new CashFlows(Ordering.natural().immutableSortedCopy(cashFlows)); } }