BrightSide Workbench Full Report + Source Code
m111/ModelEntry.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.treasury.m111;
19 
20 import java.util.HashMap;
21 import java.util.Map;
22 import org.turro.jpa.Dao;
23 import org.turro.math.Round;
24 import org.turro.util.CompareUtil;
25 
30 public class ModelEntry implements Comparable<ModelEntry> {
31 
32  private ModelSet set;
33  private ModelType type;
34  private double perCent = 0.0; //, taxable = 0.0;
35  private Map<Long, EntryContract> contracts = new HashMap<Long, EntryContract>();
36 
37  public ModelEntry(ModelSet set, ModelType type, double perCent) {
38  this.set = set;
39  this.type = type;
40  this.perCent = new Round(perCent).decimals(2).value();
41  }
42 
43  public double getPerCent() {
44  return perCent;
45  }
46 
47  public double getTaxable() {
48  double total = 0.0;
49  for(EntryContract ec : contracts.values()) {
50  total += ec.getTaxable();
51  }
52  return total;
53  //return taxable;
54  }
55 
56  public ModelType getType() {
57  return type;
58  }
59 
60  public Map<Long, EntryContract> getContracts() {
61  return contracts;
62  }
63 
64  public double getRetention() {
65  double total = 0.0;
66  for(EntryContract ec : contracts.values()) {
67  total += ec.getRetention();
68  }
69  return total;
70  }
71 
72  public Dao getDao() {
73  return set.getDao();
74  }
75 
76  public void addValue(long contractId, String contractName, long documentId, double retention, double taxable) {
77  EntryContract ec = contracts.get(contractId);
78  if(ec == null) {
79  ec = new EntryContract(contractId, contractName);
80  contracts.put(contractId, ec);
81  }
82  ec.addDocument(documentId, retention, taxable);
83  //this.taxable += taxable;
84  }
85 
86  @Override
87  public int compareTo(ModelEntry o) {
88  int result = CompareUtil.compare(type.getOrder(), o.type.getOrder());
89  if(result == 0) {
90  result = CompareUtil.compare(perCent, o.perCent);
91  }
92  return result;
93  }
94 
95 }
void addDocument(long documentId, double retention, double taxable)
ModelEntry(ModelSet set, ModelType type, double perCent)
void addValue(long contractId, String contractName, long documentId, double retention, double taxable)
Round decimals(int digits)
Definition: Round.java:32