Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.Serializable;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.ArrayList;
- import java.util.Collections;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author ebesard
- */
- public class Fonds implements Comparable<Fonds>, Serializable{
- private static final long serialVersionUID=2017;
- private String isin;
- private String naam;
- private String markt;
- private Munteenheid munteenheid;
- private HashSet<PercentageMetLabel> sectoren;
- private HashSet<PercentageMetLabel> regios;
- private ArrayList<FondsSnap> snaps;
- public Fonds(String isin, String naam, String markt, Munteenheid munteenheid,
- HashSet<PercentageMetLabel> sectoren, HashSet<PercentageMetLabel> regios){
- this.isin=isin;
- this.naam=naam;
- this.markt=markt;
- this.munteenheid=munteenheid;
- this.sectoren=sectoren;
- this.regios=regios;
- this.snaps= new ArrayList<FondsSnap>();
- }
- public String getIsin() {
- return isin;
- }
- public String getNaam() {
- return naam;
- }
- public String getMarkt() {
- return markt;
- }
- public Munteenheid getMunteenheid() {
- return munteenheid;
- }
- public HashSet<PercentageMetLabel> getSectoren() {
- return sectoren;
- }
- public HashSet<PercentageMetLabel> getRegios() {
- return regios;
- }
- public ArrayList<FondsSnap> getSnaps() {
- return snaps;
- }
- public boolean equals(Object o){
- /**boolean areEquals=false;
- if(this==o){
- areEquals=true;
- }
- if(o==null){
- areEquals=false;
- }
- else if(this.getClass().equals(o.getClass())){
- Fonds compared= (Fonds) o;
- if(this.isin==null){
- areEquals=false;
- }
- if(this.isin.equals(compared.getIsin())){
- areEquals=true;
- }
- else{
- areEquals=false;
- }
- }
- return areEquals;**/
- if(this==o)
- return true;
- if(o==null)
- return false;
- if(this.getClass()!=o.getClass())
- return false;
- Fonds compared= (Fonds) o;
- if(isin==null){
- if(compared.isin!=null){
- return false;}
- }else if(!isin.equals(compared.isin))
- return false;
- return true;
- }
- public int compareTo(Fonds other){
- if(this.markt.equals(other.getMarkt())){
- return this.isin.compareTo(other.getIsin());
- }
- else{
- return this.markt.compareTo(other.getMarkt());
- }
- }
- public void voegSnapToe(FondsSnap fondsSnap)throws FondsException{
- //try{
- for(FondsSnap fs: this.snaps){
- if(fs.getTimestamp().equals(fondsSnap.getTimestamp())){
- throw new FondsException(fondsSnap);
- }
- }
- this.snaps.add(fondsSnap); // enkel toevoegen als ze niet in de lijst zitten!!
- /**for(FondsSnap fs: this.snaps){
- if(fs.getTimestamp().isAfter(fondsSnap.getTimestamp())){
- this.snaps.set(this.snaps.indexOf(fs), fondsSnap);
- }
- }**/
- //snaps automatisch sorteren dankzij comparable die al sorteert obv timestamp
- Collections.sort(this.snaps);
- //}
- //catch(FondsException e){
- //System.out.println(e.getMessage());
- //}
- }
- public boolean isGeldigFonds(){
- double sumSectoren=0.0;
- double sumRegios= 0.0;
- for(PercentageMetLabel percentage:this.sectoren){
- sumSectoren+=percentage.getPercentage();
- }
- for(PercentageMetLabel percentage: this.regios){
- sumRegios+=percentage.getPercentage();
- }
- if((sumSectoren < 100.1 && sumSectoren>99.9) && (sumRegios<100.1 && sumRegios>99.9)){
- return true;
- }
- else{
- return false;
- }
- }
- /**public FondsSnap getSnapVan2(TimeStamp timestamp)throws FondsException{
- try{
- for(FondsSnap fondssnap: this.snaps){
- if(fondssnap.getTimestamp().equals(timestamp)){
- return fondssnap;
- }
- }
- FondsSnap fondssnapVoor=null;
- FondsSnap fondssnapNa=null;
- int totaalAantalDagen=0;
- int aantalDagen=0;
- double verschilSnaps=0.0;
- //voor en na zoeken
- for(FondsSnap fondssnap:this.snaps){
- /**if((fondssnap.getTimestamp().getJaar()==timestamp.getJaar())
- && fondssnap.getTimestamp().getMaand()==timestamp.getMaand()
- && fondssnap.getTimestamp().isBefore(timestamp)){
- fondssnapVoor=fondssnap;
- }
- else if ((fondssnap.getTimestamp().getJaar()==timestamp.getJaar())
- && fondssnap.getTimestamp().getMaand()==timestamp.getMaand()
- && fondssnap.getTimestamp().isAfter(timestamp)){
- fondssnapNa=fondssnap;
- }
- else{
- throw new FondsException(timestamp);
- }
- }
- totaalAantalDagen=fondssnapNa.getTimestamp().getDagVanDeMaand()-
- fondssnapVoor.getTimestamp().getDagVanDeMaand();
- aantalDagen= timestamp.getDagVanDeMaand()-fondssnapVoor.getTimestamp().getDagVanDeMaand();
- verschilSnaps= fondssnapNa.getSnapWaarde()-fondssnapVoor.getSnapWaarde();
- double nieuweSnapWaarde= fondssnapVoor.getSnapWaarde() + aantalDagen * verschilSnaps / totaalAantalDagen;
- //}
- /**catch(FondsException e){
- System.out.println(e.getMessage());
- }
- return null;
- }**/
- // OPM Ward: De methode mag 'throws FondsException' doen volgens de opgave.
- public FondsSnap getSnapVan(TimeStamp timestamp) throws FondsException {
- for (FondsSnap fondssnap : this.snaps) {
- if (fondssnap.getTimestamp().equals(timestamp)) {
- return fondssnap;
- }
- }
- FondsSnap fondssnapVoor = null;
- FondsSnap fondssnapNa = null;
- // OPM Ward: eerst fondsnapVoor en fondssnapNa zoeken
- for (FondsSnap fondssnap : this.snaps) {
- TimeStamp fondssnapTimestamp = fondssnap.getTimestamp();
- if (fondssnapTimestamp.isBefore(timestamp)) {
- if (fondssnapVoor == null || fondssnapTimestamp.isAfter(fondssnapVoor.getTimestamp())) {
- fondssnapVoor = fondssnap;
- }
- } else {
- if (fondssnapNa == null || fondssnapTimestamp.isBefore(fondssnapNa.getTimestamp())) {
- fondssnapNa = fondssnap;
- }
- }
- }
- // OPM Ward: als er geen gevonden is FondsException
- if (fondssnapVoor == null || fondssnapNa == null) {
- throw new FondsException(timestamp);
- }
- // OPM Ward: om totaal aantal dagen te berekenen kan je methode getDaysBetween berekenen
- // Als je enkel de day of month gebruikt hou je geen rekening met feit dat tijdstippen in andere maan kunnen liggen
- int totaalAantalDagen = TimeStamp.getDaysBetween(fondssnapNa.getTimestamp(), fondssnapVoor.getTimestamp());
- int aantalDagen = TimeStamp.getDaysBetween(fondssnapVoor.getTimestamp(), timestamp);
- double verschilSnaps = fondssnapNa.getSnapWaarde() - fondssnapVoor.getSnapWaarde();
- double nieuweSnapWaarde = fondssnapVoor.getSnapWaarde() + aantalDagen * verschilSnaps / totaalAantalDagen;
- // OPM Ward: nu moet er nieuwe Fondssnap worden aangemaakt met de timestamp en deze waarde
- return new FondsSnap(timestamp, nieuweSnapWaarde);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement