Skip to content

Instantly share code, notes, and snippets.

@john77eipe
Created April 16, 2017 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john77eipe/999a05e53b9d8d54930dced19198234e to your computer and use it in GitHub Desktop.
Save john77eipe/999a05e53b9d8d54930dced19198234e to your computer and use it in GitHub Desktop.
//client creates list of Ints
List<Integer> listOfInts = new ArrayList<Integer>();
listOfInts.add(2);
listOfInts.add(3);
listOfInts.add(4);
//client does the filtering based on his logic
//let's say he wants to filter out even numbers
Iterator<Integer> itr = listOfInts.iterator();
while (itr.hasNext()) {
Integer i = itr.next();
if(i%2==0)
itr.remove();
}
//Client calls Vendor provided function
int result = MathUtility.sum(listOfInts);
//In the provided Vendor's MathUtility class
class MathUtility {
public static int sum(List<Integer> list){
//ability to add is only here
int sum=0;
for(Integer i: list){
sum=sum+i;
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment