Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.11 KB | None | 0 0
  1.  
  2. import java.io.Serializable;
  3. import java.util.HashMap;
  4. import java.util.HashSet;
  5. import java.util.ArrayList;
  6. import java.util.Collections;
  7.  
  8. /*
  9. * To change this license header, choose License Headers in Project Properties.
  10. * To change this template file, choose Tools | Templates
  11. * and open the template in the editor.
  12. */
  13.  
  14. /**
  15. *
  16. * @author ebesard
  17. */
  18. public class Fonds implements Comparable<Fonds>, Serializable{
  19.  
  20. private static final long serialVersionUID=2017;
  21. private String isin;
  22. private String naam;
  23. private String markt;
  24. private Munteenheid munteenheid;
  25. private HashSet<PercentageMetLabel> sectoren;
  26. private HashSet<PercentageMetLabel> regios;
  27. private ArrayList<FondsSnap> snaps;
  28.  
  29.  
  30. public Fonds(String isin, String naam, String markt, Munteenheid munteenheid,
  31. HashSet<PercentageMetLabel> sectoren, HashSet<PercentageMetLabel> regios){
  32. this.isin=isin;
  33. this.naam=naam;
  34. this.markt=markt;
  35. this.munteenheid=munteenheid;
  36. this.sectoren=sectoren;
  37. this.regios=regios;
  38. this.snaps= new ArrayList<FondsSnap>();
  39. }
  40.  
  41. public String getIsin() {
  42. return isin;
  43. }
  44.  
  45. public String getNaam() {
  46. return naam;
  47. }
  48.  
  49. public String getMarkt() {
  50. return markt;
  51. }
  52.  
  53. public Munteenheid getMunteenheid() {
  54. return munteenheid;
  55. }
  56.  
  57. public HashSet<PercentageMetLabel> getSectoren() {
  58. return sectoren;
  59. }
  60.  
  61. public HashSet<PercentageMetLabel> getRegios() {
  62. return regios;
  63. }
  64.  
  65. public ArrayList<FondsSnap> getSnaps() {
  66. return snaps;
  67. }
  68.  
  69. public boolean equals(Object o){
  70. /**boolean areEquals=false;
  71. if(this==o){
  72. areEquals=true;
  73. }
  74. if(o==null){
  75. areEquals=false;
  76. }
  77. else if(this.getClass().equals(o.getClass())){
  78. Fonds compared= (Fonds) o;
  79. if(this.isin==null){
  80. areEquals=false;
  81. }
  82. if(this.isin.equals(compared.getIsin())){
  83. areEquals=true;
  84. }
  85. else{
  86. areEquals=false;
  87. }
  88. }
  89. return areEquals;**/
  90. if(this==o)
  91. return true;
  92. if(o==null)
  93. return false;
  94.  
  95. if(this.getClass()!=o.getClass())
  96. return false;
  97.  
  98. Fonds compared= (Fonds) o;
  99. if(isin==null){
  100. if(compared.isin!=null){
  101. return false;}
  102. }else if(!isin.equals(compared.isin))
  103. return false;
  104.  
  105. return true;
  106. }
  107.  
  108. public int compareTo(Fonds other){
  109. if(this.markt.equals(other.getMarkt())){
  110. return this.isin.compareTo(other.getIsin());
  111. }
  112. else{
  113. return this.markt.compareTo(other.getMarkt());
  114. }
  115. }
  116.  
  117. public void voegSnapToe(FondsSnap fondsSnap)throws FondsException{
  118. //try{
  119. for(FondsSnap fs: this.snaps){
  120.  
  121. if(fs.getTimestamp().equals(fondsSnap.getTimestamp())){
  122. throw new FondsException(fondsSnap);
  123. }
  124. }
  125. this.snaps.add(fondsSnap); // enkel toevoegen als ze niet in de lijst zitten!!
  126. /**for(FondsSnap fs: this.snaps){
  127. if(fs.getTimestamp().isAfter(fondsSnap.getTimestamp())){
  128. this.snaps.set(this.snaps.indexOf(fs), fondsSnap);
  129. }
  130. }**/
  131.  
  132. //snaps automatisch sorteren dankzij comparable die al sorteert obv timestamp
  133. Collections.sort(this.snaps);
  134. //}
  135. //catch(FondsException e){
  136. //System.out.println(e.getMessage());
  137. //}
  138. }
  139.  
  140. public boolean isGeldigFonds(){
  141. double sumSectoren=0.0;
  142. double sumRegios= 0.0;
  143. for(PercentageMetLabel percentage:this.sectoren){
  144. sumSectoren+=percentage.getPercentage();
  145. }
  146. for(PercentageMetLabel percentage: this.regios){
  147. sumRegios+=percentage.getPercentage();
  148. }
  149. if((sumSectoren < 100.1 && sumSectoren>99.9) && (sumRegios<100.1 && sumRegios>99.9)){
  150. return true;
  151. }
  152. else{
  153. return false;
  154. }
  155. }
  156.  
  157. /**public FondsSnap getSnapVan2(TimeStamp timestamp)throws FondsException{
  158. try{
  159. for(FondsSnap fondssnap: this.snaps){
  160. if(fondssnap.getTimestamp().equals(timestamp)){
  161. return fondssnap;
  162. }
  163. }
  164. FondsSnap fondssnapVoor=null;
  165. FondsSnap fondssnapNa=null;
  166. int totaalAantalDagen=0;
  167. int aantalDagen=0;
  168. double verschilSnaps=0.0;
  169. //voor en na zoeken
  170. for(FondsSnap fondssnap:this.snaps){
  171. /**if((fondssnap.getTimestamp().getJaar()==timestamp.getJaar())
  172. && fondssnap.getTimestamp().getMaand()==timestamp.getMaand()
  173. && fondssnap.getTimestamp().isBefore(timestamp)){
  174. fondssnapVoor=fondssnap;
  175. }
  176. else if ((fondssnap.getTimestamp().getJaar()==timestamp.getJaar())
  177. && fondssnap.getTimestamp().getMaand()==timestamp.getMaand()
  178. && fondssnap.getTimestamp().isAfter(timestamp)){
  179. fondssnapNa=fondssnap;
  180. }
  181. else{
  182. throw new FondsException(timestamp);
  183. }
  184.  
  185.  
  186. }
  187. totaalAantalDagen=fondssnapNa.getTimestamp().getDagVanDeMaand()-
  188. fondssnapVoor.getTimestamp().getDagVanDeMaand();
  189. aantalDagen= timestamp.getDagVanDeMaand()-fondssnapVoor.getTimestamp().getDagVanDeMaand();
  190. verschilSnaps= fondssnapNa.getSnapWaarde()-fondssnapVoor.getSnapWaarde();
  191. double nieuweSnapWaarde= fondssnapVoor.getSnapWaarde() + aantalDagen * verschilSnaps / totaalAantalDagen;
  192. //}
  193. /**catch(FondsException e){
  194. System.out.println(e.getMessage());
  195. }
  196. return null;
  197.  
  198. }**/
  199.  
  200. // OPM Ward: De methode mag 'throws FondsException' doen volgens de opgave.
  201. public FondsSnap getSnapVan(TimeStamp timestamp) throws FondsException {
  202.  
  203. for (FondsSnap fondssnap : this.snaps) {
  204. if (fondssnap.getTimestamp().equals(timestamp)) {
  205. return fondssnap;
  206. }
  207. }
  208. FondsSnap fondssnapVoor = null;
  209. FondsSnap fondssnapNa = null;
  210.  
  211. // OPM Ward: eerst fondsnapVoor en fondssnapNa zoeken
  212. for (FondsSnap fondssnap : this.snaps) {
  213.  
  214. TimeStamp fondssnapTimestamp = fondssnap.getTimestamp();
  215.  
  216. if (fondssnapTimestamp.isBefore(timestamp)) {
  217.  
  218. if (fondssnapVoor == null || fondssnapTimestamp.isAfter(fondssnapVoor.getTimestamp())) {
  219. fondssnapVoor = fondssnap;
  220. }
  221.  
  222. } else {
  223.  
  224. if (fondssnapNa == null || fondssnapTimestamp.isBefore(fondssnapNa.getTimestamp())) {
  225. fondssnapNa = fondssnap;
  226. }
  227.  
  228. }
  229.  
  230. }
  231.  
  232. // OPM Ward: als er geen gevonden is FondsException
  233. if (fondssnapVoor == null || fondssnapNa == null) {
  234. throw new FondsException(timestamp);
  235. }
  236.  
  237.  
  238. // OPM Ward: om totaal aantal dagen te berekenen kan je methode getDaysBetween berekenen
  239. // Als je enkel de day of month gebruikt hou je geen rekening met feit dat tijdstippen in andere maan kunnen liggen
  240. int totaalAantalDagen = TimeStamp.getDaysBetween(fondssnapNa.getTimestamp(), fondssnapVoor.getTimestamp());
  241. int aantalDagen = TimeStamp.getDaysBetween(fondssnapVoor.getTimestamp(), timestamp);
  242. double verschilSnaps = fondssnapNa.getSnapWaarde() - fondssnapVoor.getSnapWaarde();
  243.  
  244. double nieuweSnapWaarde = fondssnapVoor.getSnapWaarde() + aantalDagen * verschilSnaps / totaalAantalDagen;
  245.  
  246. // OPM Ward: nu moet er nieuwe Fondssnap worden aangemaakt met de timestamp en deze waarde
  247. return new FondsSnap(timestamp, nieuweSnapWaarde);
  248.  
  249. }
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement