package models; import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import com.avaje.ebean.Model; @Entity public class Color extends Model { @Id public Long id; public int r; public int g; public int b; public String hex; @OneToMany(mappedBy="color") @OrderBy("count DESC") public List imageColors; public static Finder Find = new Finder(Color.class); public static Color findOrCreate(Integer r, Integer g, Integer b) { Color c = Find.where().eq("r", r).eq("g", g).eq("b", b).findUnique(); if(c == null) { c = new Color(); c.r = r; c.g = g; c.b = b; c.hex = String.format("%02x%02x%02x", r, g, b); c.save(); } return c; } public String toString() { return this.hex; } }