I have these two functions which are basically the same:
private Order getOrder( List<Order> orders, String gcsId )
{
Predicate<Order> predicate = c -> c.getGcsId().equals( gcsId );
Order obj = orders.stream().filter( predicate ).findFirst().get();
return obj;
}
private OrderLine getOrderLine( List<OrderLine> orderLines, String gcsId )
{
Predicate<OrderLine> predicate = c -> c.getGcsId().equals( gcsId );
OrderLine obj = orderLines.stream().filter( predicate ).findFirst().get();
return obj;
}
The only difference is the type of the first parameter. How can I create a single function with the first parameter having a variable type?
Edit: This is how I call those functions in another method of the same class:
Order order = getOrder( orders, orderId );
OrderLine orderLine = getOrderLine( order.getOrderLines(), orderLineId );
interfacethat both classes implent, then use the interface as the parameter type?OrderLineandOrdershare any common super class or interface?