All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebean.WhenFind Maven / Gradle / Ivy

package io.ebean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by rob on 16/07/15.
 */
public class WhenFind {

  List> byId = new ArrayList();

  Map,WhenBeanReturn> byUnique = new HashMap,WhenBeanReturn>();

  public  WhenBeanReturn byId(Class beanType) {

    return byId(beanType, null);
  }

  public  WhenBeanReturn byId(Class beanType, Object id) {

    WhenBeanReturn ret = new WhenBeanReturn(beanType, id);
    byId.add(ret);
    return ret;
  }

  public  WhenBeanReturn byUnique(Class beanType) {

    WhenBeanReturn ret = new WhenBeanReturn(beanType);
    byUnique.put(beanType, ret);
    return ret;
  }

  protected WhenBeanReturn findMatchByUnique(Class beanType) {
    return byUnique.get(beanType);
  }

  protected WhenBeanReturn findMatchById(Class beanType, Object id) {

    for (WhenBeanReturn byIdReturn : byId) {
      if (byIdReturn.isMatch(beanType, id)){
        return byIdReturn;
      }
    }

    for (WhenBeanReturn byIdReturn : byId) {
      if (byIdReturn.isMatch(beanType)){
        return byIdReturn;
      }
    }

    // no match
    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy