some fixes
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / mensaplan / MensaTagesplan.java
1 package de.dhbwloe.campusapp.mensaplan;
2
3 import java.text.DateFormat;
4 import java.text.ParseException;
5 import java.text.SimpleDateFormat;
6 import java.util.Date;
7 import java.util.Locale;
8 import java.util.zip.CRC32;
9
10 /**
11  * Created by pk910 on 22.01.2016.
12  */
13 public class MensaTagesplan {
14     private long iPlanDate;
15     private long iChkSum;
16     private String sMenuName, sName, sNameHtml, sAdditional, sNotes;
17     private int[] aPriceArray = new int[4];
18
19     private boolean bIsNew = false;
20
21     public MensaTagesplan(long plandate, String menuname, long chksum, String name, String namehtml, String additional, String notes, int price1, int price2, int price3, int price4) {
22         iPlanDate = plandate;
23         sMenuName = menuname;
24         iChkSum = chksum;
25         sName = name;
26         sNameHtml = namehtml;
27         sAdditional = (additional == null ? "" : additional);
28         sNotes = notes;
29         aPriceArray[0] = price1; // Student
30         aPriceArray[1] = price2; // Employees
31         aPriceArray[2] = price3; // Guest
32         aPriceArray[3] = price4; // School
33     }
34
35     public long calculateChkSum() {
36         CRC32 crc = new CRC32();
37         crc.update(sMenuName.getBytes());
38         if(sName != null)
39             crc.update(sName.getBytes());
40         if(sNameHtml != null)
41             crc.update(sNameHtml.getBytes());
42         if(sAdditional!= null)
43             crc.update(sAdditional.getBytes());
44         if(sNotes!= null)
45             crc.update(sNotes.getBytes());
46         crc.update(aPriceArray[0]);
47         crc.update(aPriceArray[1]);
48         crc.update(aPriceArray[2]);
49         crc.update(aPriceArray[3]);
50
51         long crcvalue = crc.getValue();
52         iChkSum = crcvalue;
53         return crcvalue;
54     }
55
56     public long getPlanDate() {
57         return iPlanDate;
58     }
59
60     public String getFormatedDate() {
61         DateFormat df = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
62         return df.format(new Date(iPlanDate * 1000));
63     }
64
65     public long getChkSum() {
66         return iChkSum;
67     }
68
69     public String getMenuName() {
70         return sMenuName;
71     }
72
73     public String getName() {
74         return sName;
75     }
76
77     public String getNameHtml() {
78         return sNameHtml;
79     }
80
81     public String getAdditional() {
82         return sAdditional;
83     }
84
85     public String getNotes() {
86         return sNotes;
87     }
88
89     public int[] getPlainPrice() {
90         return aPriceArray;
91     }
92
93     public double getStudentPrice() {
94         double price = (aPriceArray[0] / 100.0);
95         return price;
96     }
97
98     public double getEmployeePrice() {
99         double price = (aPriceArray[1] / 100.0);
100         return price;
101     }
102
103     public double getGuestPrice() {
104         double price = (aPriceArray[2] / 100.0);
105         return price;
106     }
107
108     public double getSchoolPrice() {
109         double price = (aPriceArray[3] / 100.0);
110         return price;
111     }
112
113     public void setIsNew() {
114         bIsNew = true;
115     }
116
117     public boolean getIsNew(boolean reset) {
118         boolean isnew = bIsNew;
119         if(reset)
120             bIsNew = false;
121         return isnew;
122     }
123
124 }