Grundaufbau der App
[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         crc.update(sName.getBytes());
39         crc.update(sNameHtml.getBytes());
40         if(sAdditional!= null)
41             crc.update(sAdditional.getBytes());
42         if(sNotes!= null)
43             crc.update(sNotes.getBytes());
44         crc.update(aPriceArray[0]);
45         crc.update(aPriceArray[1]);
46         crc.update(aPriceArray[2]);
47         crc.update(aPriceArray[3]);
48
49         long crcvalue = crc.getValue();
50         iChkSum = crcvalue;
51         return crcvalue;
52     }
53
54     public long getPlanDate() {
55         return iPlanDate;
56     }
57
58     public String getFormatedDate() {
59         DateFormat df = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
60         return df.format(new Date(iPlanDate * 1000));
61     }
62
63     public long getChkSum() {
64         return iChkSum;
65     }
66
67     public String getMenuName() {
68         return sMenuName;
69     }
70
71     public String getName() {
72         return sName;
73     }
74
75     public String getNameHtml() {
76         return sNameHtml;
77     }
78
79     public String getAdditional() {
80         return sAdditional;
81     }
82
83     public String getNotes() {
84         return sNotes;
85     }
86
87     public int[] getPlainPrice() {
88         return aPriceArray;
89     }
90
91     public double getStudentPrice() {
92         double price = (aPriceArray[0] / 100.0);
93         return price;
94     }
95
96     public double getEmployeePrice() {
97         double price = (aPriceArray[1] / 100.0);
98         return price;
99     }
100
101     public double getGuestPrice() {
102         double price = (aPriceArray[2] / 100.0);
103         return price;
104     }
105
106     public double getSchoolPrice() {
107         double price = (aPriceArray[3] / 100.0);
108         return price;
109     }
110
111     public void setIsNew() {
112         bIsNew = true;
113     }
114
115     public boolean getIsNew(boolean reset) {
116         boolean isnew = bIsNew;
117         if(reset)
118             bIsNew = false;
119         return isnew;
120     }
121
122 }