001package com.avaje.ebean;
002
003import java.util.ArrayList;
004import java.util.List;
005
006/**
007 * Created by rob on 17/07/15.
008 */
009public class MethodCalls {
010
011
012
013  List<MethodCall> list = new ArrayList<MethodCall>();
014
015  public void add(MethodCall call) {
016    list.add(call);
017  }
018
019  public int size() {
020    return list.size();
021  }
022
023  public List<MethodCall> all() {
024    return list;
025  }
026
027  public List<MethodCall> save() {
028    return matches(DelegateMethodNames.SAVE);
029  }
030
031  public List<MethodCall> insert() {
032    return matches(DelegateMethodNames.INSERT);
033  }
034
035  public List<MethodCall> update() {
036    return matches(DelegateMethodNames.UPDATE);
037  }
038
039  public List<MethodCall> delete() {
040    return matches(DelegateMethodNames.DELETE);
041  }
042
043  protected List<MethodCall> matches(String methodName) {
044
045    List<MethodCall> matches = new ArrayList<MethodCall>();
046    for (MethodCall call : list) {
047      if (isMatch(call, methodName)) {
048        matches.add(call);
049      }
050    }
051    return matches;
052  }
053
054  protected boolean isMatch(MethodCall call, String methodName) {
055    return call.name.equals(methodName);
056  }
057}