BrightSide Workbench Full Report + Source Code
LineType.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.financials.entity;
19 
20 import java.util.HashSet;
21 import java.util.Set;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.FetchType;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.OneToMany;
30 import javax.persistence.Transient;
31 
36 @Entity
37 public class LineType implements java.io.Serializable {
38 
39  @Id
40  @GeneratedValue(strategy=GenerationType.IDENTITY)
41  @Column(name="IDENTIFIER")
42  private long id;
43 
44  @Column(name="LTYPE_NAME")
45  private String name;
46 
47  private double stockCoefficient;
48 
49  @OneToMany(mappedBy = "lineType", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
50  private Set<LineTypeAccount> lineTypeAccounts = new HashSet<LineTypeAccount>();
51 
52  @Transient
53  private ContractPreference contractPreference;
54 
55  @Transient
56  private String composedName;
57 
58  public long getId() {
59  return id;
60  }
61 
62  public void setId(long id) {
63  this.id = id;
64  }
65 
66  public String getComposedName() {
67  if(composedName == null) {
68  setContractPreference(contractPreference);
69  }
70  return composedName;
71  }
72 
73  public void setComposedName(String composedName) {
74  this.composedName = composedName;
75  }
76 
78  return contractPreference;
79  }
80 
81  public void setContractPreference(ContractPreference contractPreference) {
82  this.contractPreference = contractPreference;
83  if(contractPreference != null) {
84  if("#".equals(contractPreference.getName())) {
85  composedName = name.replaceAll("\\%n", "");
86  } else {
87  composedName = name.replaceAll("\\%n", contractPreference.getName());
88  }
89  }
90  }
91 
92  public Set<LineTypeAccount> getLineTypeAccounts() {
93  return lineTypeAccounts;
94  }
95 
96  public void setLineTypeAccounts(Set<LineTypeAccount> lineTypeAccounts) {
97  this.lineTypeAccounts = lineTypeAccounts;
98  }
99 
100  public String getName() {
101  return name;
102  }
103 
104  public void setName(String name) {
105  this.name = name;
106  }
107 
108  public double getStockCoefficient() {
109  return stockCoefficient;
110  }
111 
112  public void setStockCoefficient(double stockCoefficient) {
113  this.stockCoefficient = stockCoefficient;
114  }
115 
116  /* Helpers */
117 
118  public boolean isEmpty() {
119  return id > 0;
120  }
121 
122  @Override
123  public LineType clone() {
124  // soft clone: line type accounts are assigned
125  LineType lt = new LineType();
126  lt.setId(id);
127  lt.setName(name);
128  lt.setStockCoefficient(stockCoefficient);
129  lt.getLineTypeAccounts().addAll(lineTypeAccounts);
130  return lt;
131  }
132 }
ContractPreference getContractPreference()
Definition: LineType.java:77
void setStockCoefficient(double stockCoefficient)
Definition: LineType.java:112
void setLineTypeAccounts(Set< LineTypeAccount > lineTypeAccounts)
Definition: LineType.java:96
void setContractPreference(ContractPreference contractPreference)
Definition: LineType.java:81
Set< LineTypeAccount > getLineTypeAccounts()
Definition: LineType.java:92
void setComposedName(String composedName)
Definition: LineType.java:73