001/* 002 * Copyright 2020 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.ametys.plugins.odfpilotage.cost.entity; 018 019import java.util.HashMap; 020import java.util.Map; 021 022/** 023 * Class representing an {@link EqTD} 024 */ 025public class EqTD 026{ 027 /** The global eqTD value */ 028 private Double _globalEqTD; 029 030 /** The local eqTD value */ 031 private Map<String, Double> _localEqTD; 032 033 /** The pro-rated eqTD value */ 034 private Map<String, Double> _proRatedEqTD; 035 036 /** The program item id */ 037 private String _programItemId; 038 039 /** 040 * The constructor 041 * @param programItemId the program item id 042 */ 043 public EqTD(String programItemId) 044 { 045 _programItemId = programItemId; 046 _proRatedEqTD = new HashMap<>(); 047 _localEqTD = new HashMap<>(); 048 _globalEqTD = 0d; 049 } 050 051 /** 052 * Get the local eqTD value 053 * @param programItemPath the program item path 054 * @return the local eqTD value 055 */ 056 public Double getLocalEqTD(String programItemPath) 057 { 058 return _localEqTD.getOrDefault(programItemPath, 0d); 059 } 060 061 /** 062 * Get all local eqTD values 063 * @return all local eqTD values 064 */ 065 public Map<String, Double> getLocalEqTD() 066 { 067 return _localEqTD; 068 } 069 070 /** 071 * Set the local eqTD value 072 * @param programItemPath the program item path 073 * @param eqTD the value 074 */ 075 public void addLocalEqTD(String programItemPath, Double eqTD) 076 { 077 _localEqTD.put(programItemPath, eqTD); 078 } 079 080 /** 081 * Get the global eqTD value 082 * @return the global eqTD value 083 */ 084 public Double getGlobalEqTD() 085 { 086 return _globalEqTD; 087 } 088 089 /** 090 * Set the global eqTD value 091 * @param eqTD the value 092 */ 093 public void setGlobalEqTD(Double eqTD) 094 { 095 _globalEqTD = eqTD; 096 } 097 098 /** 099 * Set the pro-rated eqTD value 100 * @param programItemPath the program item path 101 * @param eqTD the value 102 */ 103 public void addProRatedEqTD(String programItemPath, Double eqTD) 104 { 105 _proRatedEqTD.put(programItemPath, eqTD); 106 } 107 108 /** 109 * Get the pro-rated eqTD value 110 * @param programItemPath the program item path 111 * @return the pro-rated eqTD value 112 */ 113 public Double getProRatedEqTD(String programItemPath) 114 { 115 return _proRatedEqTD.getOrDefault(programItemPath, 0d); 116 } 117 118 /** 119 * Get all pro-rated eqTD values 120 * @return all pro-rated eqTD values 121 */ 122 public Map<String, Double> getProRatedEqTD() 123 { 124 return _proRatedEqTD; 125 } 126 /** 127 * Get the program item id 128 * @return the program item id 129 */ 130 public String getProgramItemId() 131 { 132 return _programItemId; 133 } 134 135 /** 136 * Sum pro-rated and local eqTD values 137 * @param eqTD The second eqTD object to sum 138 * @param weight the weight 139 * @param childPath the path of the old eqTD value 140 * @param parentPath the path of the new eqTD value 141 */ 142 public void sum(EqTD eqTD, Double weight, String childPath, String parentPath) 143 { 144 Double newLocalEqTD = eqTD.getLocalEqTD(childPath) * weight; 145 addLocalEqTD(parentPath, newLocalEqTD + getLocalEqTD(parentPath)); 146 147 Double newProRatedEqTD = eqTD.getProRatedEqTD(childPath) * weight; 148 addProRatedEqTD(parentPath, newProRatedEqTD + getProRatedEqTD(parentPath)); 149 } 150}