Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / news / NewsItem.java
1 /* NewsItem.java
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 package de.dhbwloe.campusapp.news;
17 import java.text.DateFormat;
18 import java.text.SimpleDateFormat;
19 import java.util.Date;
20 import java.util.Locale;
21 import java.util.zip.CRC32;
22
23 /**
24  * Created by pk910 on 23.01.2016.
25  */
26 public class NewsItem {
27     private int id;
28     private String sSource;
29     private long iTime;
30     private String sUniqueId;
31     private long iChkSum;
32     private String sTitle;
33     private String sSummary;
34     private String sContent;
35     private String sLink;
36     private String sCategories;
37
38     private boolean bIsNew;
39
40     public NewsItem(int id, String source, long time, String uniqueid, long chksum, String title, String summary, String content, String link, String categories) {
41         this.id = id;
42         sSource= source;
43         iTime = time;
44         sUniqueId = uniqueid;
45         sTitle = title.trim();
46         sSummary = summary;
47         sContent = content;
48         sLink = link;
49         sCategories = categories;
50     }
51
52     public long calculateChkSum() {
53         CRC32 crc = new CRC32();
54         crc.update(sTitle.getBytes());
55         crc.update(sUniqueId.getBytes());
56         crc.update((int)iTime);
57         crc.update(sSummary.getBytes());
58         if(sContent != null)
59             crc.update(sContent.getBytes());
60         if(sLink != null)
61             crc.update(sLink.getBytes());
62         if(sCategories != null)
63             crc.update(sCategories.getBytes());
64
65         long crcvalue = crc.getValue();
66         iChkSum = crcvalue;
67         return crcvalue;
68     }
69
70     public long getChkSum() {
71         return iChkSum;
72     }
73
74     public void setIsNew(int id) {
75         bIsNew = true;
76         this.id = id;
77     }
78
79     public boolean getIsNew(boolean reset) {
80         boolean isnew = bIsNew;
81         if(reset)
82             bIsNew = false;
83         return isnew;
84     }
85
86     public int getId() {
87         return id;
88     }
89
90     public String getSource() {
91         return sSource;
92     }
93
94     public long getTime() {
95         return iTime;
96     }
97
98     public String getFormatedDate() {
99         return getFormatedDate("dd.MM.yyyy");
100     }
101
102     public String getFormatedDate(String format) {
103         DateFormat df = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
104         return df.format(new Date(iTime * 1000));
105     }
106
107     public String getUniqueId() {
108         return sUniqueId;
109     }
110
111     public String getTitle() {
112         return sTitle;
113     }
114
115     public String getSummary() {
116         return sSummary;
117     }
118
119     public String getContent() {
120         return sContent;
121     }
122
123     public String getLink() {
124         return sLink;
125     }
126
127     public String getCategories() {
128         return sCategories;
129     }
130 }