2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.batch.helpers;
24 import java.io.BufferedReader;
26 import java.io.FileReader;
27 import java.io.IOException;
28 import java.io.PrintStream;
29 import java.util.HashSet;
31 import java.util.Map.Entry;
33 import org.onap.aaf.misc.env.util.Split;
36 import java.util.TreeMap;
38 public class MonthData {
39 public final Map<Integer,Set<Row>> data = new TreeMap<>();
42 public MonthData(String env) throws IOException {
43 f = new File("Monthly"+env+".dat");
46 BufferedReader br = new BufferedReader(new FileReader(f));
50 while ((line=br.readLine())!=null) {
51 if (!line.startsWith("#")) {
52 split = Split.split(',', line);
53 if (split.length==5) {
54 add(Integer.parseInt(split[0]),split[1],
55 Integer.parseInt(split[2]),
56 Integer.parseInt(split[3]),
57 Integer.parseInt(split[4])
68 public void add(int yr_mon, String target, long total, long adds, long drops) {
69 Set<Row> row = data.get(yr_mon);
71 data.put(yr_mon, (row=new HashSet<>()));
73 row.add(new Row(target,total,adds,drops));
76 public boolean notExists(int yr_mon) {
77 return data.get(yr_mon)==null;
80 public static class Row implements Comparable<Row> {
81 public final String target;
82 public final long total;
83 public final long adds;
84 public final long drops;
86 public Row(String t, long it, long a, long d) {
94 public int compareTo(Row o) {
95 return target.compareTo(o.target);
98 public String toString() {
99 return target + '|' + total + '|' + drops + '|' + adds;
103 public void write() throws IOException {
105 File bu = new File(f.getName()+".bak");
108 PrintStream ps = new PrintStream(f);
110 for ( Entry<Integer, Set<Row>> rows : data.entrySet()) {
111 for (Row row : rows.getValue()) {
112 ps.printf("%d,%s,%d,%d,%d\n",rows.getKey(),row.target,row.total,row.adds,row.drops);