55public class Logger {
66 private static PrintStream out = System .out ;
77
8- enum Type {
9- UNDEFINED ,
10- STRING ,
11- INTEGER ,
12- BYTE
13- }
14-
15- static private String stringValue ;
16- static private int intValue ;
17- static private byte byteValue ;
18-
19- static Type type = Type .UNDEFINED ;
20- static int counter = 0 ;
21-
228 static LoggerController controller = new LoggerController ();
239
2410
2511 public static void flush () {
26- /*processPreviousValue(Type.UNDEFINED);
27- stringValue = "";
28- intValue = 0;
29- byteValue = 0;*/
3012 controller .flush ();
31-
32- }
33-
34- private static boolean processPreviousValue (Type currentType ) {
35- if (currentType .equals (type )) {
36- return false ;
37- }
38- switch (type ) {
39- case STRING :
40- decorateString ();
41- counter = 0 ;
42- break ;
43- case INTEGER :
44- decorateInt ();
45- break ;
46- case BYTE :
47- decorateByte ();
48- break ;
49- }
50- type = currentType ;
51- return true ;
52- }
53-
54- public static void setPrintStream (PrintStream newPrintStream ) {
55- out = newPrintStream ;
5613 }
5714
5815 public static void log (int message ) {
59- /*if (processPreviousValue(Type.INTEGER)) {
60- intValue = message;
61- } else {
62- handleOverFlow(intValue, message, Integer.MAX_VALUE);
63- intValue += message;
64- }*/
6516 controller .log (message );
6617 }
6718
6819 public static void log (byte message ) {
69- /*if (processPreviousValue(Type.BYTE)) {
70- byteValue = message;
71- } else {
72- handleOverFlow(byteValue, message, Byte.MAX_VALUE);
73- byteValue += message;
74- }*/
7520 controller .log (message );
7621 }
7722
@@ -80,11 +25,6 @@ public static void log(char message) {
8025 }
8126
8227 public static void log (String message ) {
83- /*if (processPreviousValue(Type.STRING)) {
84- stringValue = message;
85- } else {
86- processRepeatedStringValue(message);
87- }*/
8828 controller .log (message );
8929 }
9030
@@ -124,45 +64,8 @@ private static int getSumOfArray(int... array) {
12464 return sum ;
12565 }
12666
127- private static void decorateString () {
128- if (counter > 1 ) {
129- printToOutput ("string: " + stringValue + " (x" + counter + ")" );
130- } else {
131- printToOutput ("string: " + stringValue );
132- }
133- counter = 0 ;
134- }
135-
136- private static void decorateByte () {
137- printToOutput ("primitive: " + byteValue );
138- }
139-
140- private static void decorateInt () {
141- printToOutput ("primitive: " + intValue );
142- }
143-
14467 private static void printToOutput (String message ) {
14568 out .println (message );
14669 }
14770
148-
149- private static void handleOverFlow (int value , long message , int max ) {
150-
151- if (value + message > max ) {
152- printToOutput ("primitive: " + value );
153- printToOutput ("primitive: " + max );
154- }
155-
156- }
157-
158- private static void processRepeatedStringValue (String message ) {
159- if (message .equals (stringValue )) {
160- counter ++;
161- } else {
162- decorateString ();
163- stringValue = message ;
164- counter = 1 ;
165- }
166- }
167-
16871}
0 commit comments