|
| 1 | +/* |
| 2 | + * To change this template, choose Tools | Templates |
| 3 | + * and open the template in the editor. |
| 4 | + */ |
| 5 | +package homework.nott.util; |
| 6 | + |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.TreeMap; |
| 10 | + |
| 11 | +/** |
| 12 | + * |
| 13 | + * @author pszgp, 23 april 2012 |
| 14 | + */ |
| 15 | +public class Device { |
| 16 | + private String timestamp;//as date string, not unix timestamp |
| 17 | + private String ip; |
| 18 | + private String name; |
| 19 | + private String type; |
| 20 | + private String user; |
| 21 | + private long allowance; |
| 22 | + private long nbytes; |
| 23 | + private double nbytesMb; |
| 24 | + |
| 25 | + public double getNbytesMb() { |
| 26 | + return (double) (nbytes / (1024 * 1024)); |
| 27 | + } |
| 28 | + |
| 29 | + private TreeMap<Integer,TreeMap<Integer,TreeMap<Integer,Long>>> usage; |
| 30 | + private TreeMap<Integer,TreeMap<Integer,TreeMap<Integer,Long>>> usageFlows;//from flows... |
| 31 | + //total usage, split per years, months, days using the usage map |
| 32 | + private ArrayList<TreeMap> totalUsageSplitDetails = new ArrayList(); |
| 33 | + private ArrayList<TreeMap> totalUsageSplitDetailsFlows = new ArrayList();//from flows (30 april 2012) |
| 34 | + private long totalUsage; |
| 35 | + private long totalUsageFlows; |
| 36 | + private String macaddr; |
| 37 | + private HashMap<String, Long> nbytesMonths; |
| 38 | + |
| 39 | + public ArrayList<TreeMap> getTotalUsageSplitDetails() { |
| 40 | + return totalUsageSplitDetails; |
| 41 | + } |
| 42 | + |
| 43 | + public ArrayList<TreeMap> getTotalUsageSplitDetailsFlows() { |
| 44 | + return totalUsageSplitDetailsFlows; |
| 45 | + } |
| 46 | + //not for beans, but for use in the code |
| 47 | + public void setTotalUsageDetailsFlows(ArrayList totalUsageDetailsFlows) |
| 48 | + { |
| 49 | + this.totalUsageSplitDetailsFlows = totalUsageDetailsFlows; |
| 50 | + } |
| 51 | + |
| 52 | + private String MONTHS[] = new String[]{"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", |
| 53 | + "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"}; |
| 54 | + |
| 55 | + public static String[] getMONTHs(){ |
| 56 | + return new String[]{"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", |
| 57 | + "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"}; |
| 58 | + } |
| 59 | + public static String getMONTH(int month){ |
| 60 | + return getMONTHs()[month]; |
| 61 | + } |
| 62 | + public static int getMONTHId(String MONTH){ |
| 63 | + for (int i=0; i< getMONTHs().length; i++) |
| 64 | + { |
| 65 | + String month = getMONTHs()[i]; |
| 66 | + if (month.equals(MONTH)) |
| 67 | + return i; |
| 68 | + } |
| 69 | + return -1; |
| 70 | + } |
| 71 | + |
| 72 | + public void setTotalUsageSplitDetails() { |
| 73 | + try{ |
| 74 | + if (usage==null) return; |
| 75 | + |
| 76 | + this.totalUsageSplitDetails = new ArrayList(); |
| 77 | + |
| 78 | + for (Integer year: usage.keySet()){ |
| 79 | + TreeMap<Integer,TreeMap<Integer, Long>> yearUsage = usage.get(year); |
| 80 | + for (Integer month: yearUsage.keySet()) |
| 81 | + { |
| 82 | + TreeMap<Integer,Long> monthUsage = yearUsage.get(month); |
| 83 | + for (Integer day: monthUsage.keySet()){ |
| 84 | + |
| 85 | + long dayUsage = monthUsage.get(day); |
| 86 | + |
| 87 | + TreeMap<String,Long> mapDay = new TreeMap(); |
| 88 | + String monthName = MONTHS[month]; |
| 89 | + String dateName = day + " "+ monthName+" "+year; |
| 90 | + |
| 91 | + mapDay.put(dateName, dayUsage); |
| 92 | + |
| 93 | + this.totalUsageSplitDetails.add(mapDay); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + }catch(Exception e){e.printStackTrace();}; |
| 98 | + } |
| 99 | + |
| 100 | + public void setTotalUsageSplitDetailsFlows() { |
| 101 | + try{ |
| 102 | + if (usageFlows==null) return; |
| 103 | + |
| 104 | + this.totalUsageSplitDetailsFlows = new ArrayList(); |
| 105 | + |
| 106 | + for (Integer year: usageFlows.keySet()){ |
| 107 | + TreeMap<Integer,TreeMap<Integer, Long>> yearUsage = usageFlows.get(year); |
| 108 | + for (Integer month: yearUsage.keySet()) |
| 109 | + { |
| 110 | + TreeMap<Integer,Long> monthUsage = yearUsage.get(month); |
| 111 | + for (Integer day: monthUsage.keySet()){ |
| 112 | + |
| 113 | + long dayUsage = monthUsage.get(day); |
| 114 | + |
| 115 | + TreeMap<String,Long> mapDay = new TreeMap(); |
| 116 | + String monthName = MONTHS[month]; |
| 117 | + String dateName = day + " "+ monthName+" "+year; |
| 118 | + |
| 119 | + mapDay.put(dateName, dayUsage); |
| 120 | + |
| 121 | + this.totalUsageSplitDetailsFlows.add(mapDay); |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | + }catch(Exception e){e.printStackTrace();}; |
| 126 | + } |
| 127 | + |
| 128 | + public long getAllowance() { |
| 129 | + return allowance; |
| 130 | + } |
| 131 | + |
| 132 | + public void setAllowance(long allowance) { |
| 133 | + this.allowance = allowance; |
| 134 | + } |
| 135 | + |
| 136 | + public long getNbytes() { |
| 137 | + return nbytes; |
| 138 | + } |
| 139 | + |
| 140 | + public void setNbytes(long nbytes) { |
| 141 | + this.nbytes = nbytes; |
| 142 | + } |
| 143 | + |
| 144 | + public Device(String timestamp, String ip, String name, String type, String user, long allowance, long nbytes) |
| 145 | + { |
| 146 | + this.timestamp = timestamp; |
| 147 | + this.ip = ip; |
| 148 | + this.name = name; |
| 149 | + this.type = type; |
| 150 | + this.user = user; |
| 151 | + this.allowance = allowance; |
| 152 | + this.nbytes = nbytes; |
| 153 | + } |
| 154 | + public String getTimestamp() |
| 155 | + { |
| 156 | + return this.timestamp; |
| 157 | + } |
| 158 | + public void setTimestamp(String timestamp) |
| 159 | + { |
| 160 | + this.timestamp = timestamp; |
| 161 | + } |
| 162 | + |
| 163 | + public String getType() { |
| 164 | + return type; |
| 165 | + } |
| 166 | + |
| 167 | + public void setType(String type) { |
| 168 | + this.type = type; |
| 169 | + } |
| 170 | + public String getIp() |
| 171 | + { |
| 172 | + return this.ip; |
| 173 | + } |
| 174 | + |
| 175 | + public void setIp(String ip) { |
| 176 | + this.ip = ip; |
| 177 | + } |
| 178 | + |
| 179 | + public String getUser() { |
| 180 | + return user; |
| 181 | + } |
| 182 | + |
| 183 | + public void setUser(String user) { |
| 184 | + this.user = user; |
| 185 | + } |
| 186 | + |
| 187 | + public void setName(String name) { |
| 188 | + this.name = name; |
| 189 | + } |
| 190 | + |
| 191 | + public String getName() { |
| 192 | + return name; |
| 193 | + } |
| 194 | + |
| 195 | + public String toString(){ |
| 196 | + return "Device=[timestamp:"+timestamp+";ip:"+ip+";name:"+name+";type:"+type+";user:"+user+";allowance="+allowance+";usage="+nbytes+"]"; |
| 197 | + } |
| 198 | + |
| 199 | + public void setUsage(TreeMap<Integer, TreeMap<Integer, TreeMap<Integer, Long>>> usage) { |
| 200 | + this.usage = new TreeMap(usage); |
| 201 | + this.setTotalUsageSplitDetails(); |
| 202 | + } |
| 203 | + |
| 204 | + public void setUsageFlows(TreeMap<Integer, TreeMap<Integer, TreeMap<Integer, Long>>> usage) { |
| 205 | + this.usageFlows = new TreeMap(usage); |
| 206 | + this.setTotalUsageSplitDetailsFlows(); |
| 207 | + } |
| 208 | + |
| 209 | + public TreeMap getUsage() |
| 210 | + { |
| 211 | + return this.usage; |
| 212 | + } |
| 213 | + |
| 214 | + public TreeMap getUsageFlows() |
| 215 | + { |
| 216 | + return this.usage; |
| 217 | + } |
| 218 | + public void setTotalUsage(long totalUsage) { |
| 219 | + this.totalUsage = totalUsage; |
| 220 | + } |
| 221 | + public long getTotalUsage() |
| 222 | + { |
| 223 | + return this.totalUsage; |
| 224 | + } |
| 225 | + |
| 226 | + public void setTotalUsageFlows(long totalUsage) { |
| 227 | + this.totalUsageFlows = totalUsageFlows; |
| 228 | + } |
| 229 | + public long getTotalUsageFlows() |
| 230 | + { |
| 231 | + return this.totalUsageFlows; |
| 232 | + } |
| 233 | + |
| 234 | + public String getMacaddr() { |
| 235 | + return this.macaddr; |
| 236 | + } |
| 237 | + |
| 238 | + public void setMacaddr(String macaddr) { |
| 239 | + this.macaddr = macaddr; |
| 240 | + } |
| 241 | + |
| 242 | + public void setNbytesMonths(HashMap<String, Long> nbytesMonths) { |
| 243 | + this.nbytesMonths = new HashMap(nbytesMonths); |
| 244 | + } |
| 245 | + public HashMap<String, Long> getNbytesMonths() { |
| 246 | + return this.nbytesMonths; |
| 247 | + } |
| 248 | + |
| 249 | +} |
0 commit comments