BrightSide Workbench Full Report + Source Code
AptitudeDegree.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.erp.entity;
19 
20 import java.util.Collection;
21 import javax.persistence.*;
22 import org.turro.string.Strings;
23 import org.turro.elephant.util.DecimalFormats;
24 import org.turro.util.CompareUtil;
25 
30 @Entity
31 public class AptitudeDegree implements java.io.Serializable {
32 
33  @Id
34  @GeneratedValue(strategy= GenerationType.IDENTITY)
35  @Column(name="IDENTIFIER")
36  private long id;
37 
38  @ManyToOne
39  private Aptitude aptitude;
40 
41  private String name;
42 
43  private int ordering;
44 
45  private double cost, price, marketPrice;
46 
47  public double getCost() {
48  return cost;
49  }
50 
51  public void setCost(double cost) {
52  this.cost = cost;
53  }
54 
55  public long getId() {
56  return id;
57  }
58 
59  public void setId(long id) {
60  this.id = id;
61  }
62 
63  public double getMarketPrice() {
64  return marketPrice;
65  }
66 
67  public void setMarketPrice(double marketPrice) {
68  this.marketPrice = marketPrice;
69  }
70 
71  public String getName() {
72  return name;
73  }
74 
75  public void setName(String name) {
76  this.name = name;
77  }
78 
79  public Aptitude getAptitude() {
80  return aptitude;
81  }
82 
83  public void setAptitude(Aptitude aptitude) {
84  this.aptitude = aptitude;
85  }
86 
87  public int getOrdering() {
88  return ordering;
89  }
90 
91  public void setOrdering(int ordering) {
92  this.ordering = ordering;
93  }
94 
95  public double getPrice() {
96  return price;
97  }
98 
99  public void setPrice(double price) {
100  this.price = price;
101  }
102 
103  /* Helpers */
104 
105  public boolean isEmpty() {
106  return Strings.isBlank(name) || (ordering == 0 && (cost == 0.0 || price == 0.0));
107  }
108 
109  public boolean isIn(Collection<AptitudeDegree> aptitudeDegrees) {
110  for(AptitudeDegree o : aptitudeDegrees) {
111  if(CompareUtil.compare(name, o.getName()) == 0 &&
112  ordering <= o.ordering) {
113  return true;
114  }
115  }
116  return false;
117  }
118 
119  public String getFullName() {
120  return aptitude.getName() +
121  (!Strings.isEmpty(name) ? " " + name : "");
122  }
123 
124  public String getFullDescription() {
125  return getFullName() + " (" + DecimalFormats.format(cost) + "/" +
126  DecimalFormats.format(price) + ")";
127  }
128 
129 }
static String format(Number value, String pattern)
void setMarketPrice(double marketPrice)
boolean isIn(Collection< AptitudeDegree > aptitudeDegrees)
void setAptitude(Aptitude aptitude)