reduced method visibility
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / structure / Utils.java
1 /*
2  * JavaInspect - Utility to visualize java software
3  * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.inspector.java.structure;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 public class Utils {
16
17         /**
18          * retrieves colors from predefined palette
19          */
20         protected static String getNextDarkColor() {
21                 lastChosenDarkColor++;
22                 if (lastChosenDarkColor >= darkColors.size())
23                         lastChosenDarkColor = 0;
24
25                 return darkColors.get(lastChosenDarkColor);
26         }
27
28         /**
29          * retrieves colors from predefined palette
30          */
31         protected static String getNextLightColor() {
32                 lastChosenLightColor++;
33                 if (lastChosenLightColor >= lightColors.size())
34                         lastChosenLightColor = 0;
35
36                 return lightColors.get(lastChosenLightColor);
37         }
38
39         private static void initCommonObjectMethods() {
40                 commonObjectMethods.add("wait");
41                 commonObjectMethods.add("equals");
42                 commonObjectMethods.add("toString");
43                 commonObjectMethods.add("hashCode");
44                 commonObjectMethods.add("notify");
45                 commonObjectMethods.add("notifyAll");
46                 commonObjectMethods.add("getClass");
47         }
48
49         protected static void initDarkColors() {
50                 darkColors.add("antiquewhite4");
51                 darkColors.add("blueviolet");
52                 darkColors.add("brown4");
53                 darkColors.add("chartreuse4");
54                 darkColors.add("cyan4");
55                 darkColors.add("deeppink1");
56                 darkColors.add("deepskyblue3");
57                 darkColors.add("firebrick1");
58                 darkColors.add("goldenrod3");
59                 darkColors.add("gray0");
60         }
61
62         private static void initEnumMethods() {
63                 enumMethods.add("values");
64                 enumMethods.add("valueOf");
65                 enumMethods.add("name");
66                 enumMethods.add("compareTo");
67                 enumMethods.add("valueOf");
68                 enumMethods.add("getDeclaringClass");
69                 enumMethods.add("ordinal");
70         }
71
72         private static void initLightColors() {
73                 lightColors.add("olivedrab2");
74                 lightColors.add("peachpuff2");
75                 lightColors.add("seagreen1");
76                 lightColors.add("violet");
77                 lightColors.add("aqua");
78                 lightColors.add("orange");
79         }
80
81         private static void initSystemDataTypes() {
82                 systemDataTypes.add("void");
83                 systemDataTypes.add("int");
84                 systemDataTypes.add("long");
85                 systemDataTypes.add("float");
86                 systemDataTypes.add("double");
87                 systemDataTypes.add("boolean");
88                 systemDataTypes.add("char");
89                 systemDataTypes.add("short");
90                 systemDataTypes.add("byte");
91         }
92
93         private static void initSystemPackages() {
94                 systemPackages.add("java.");
95                 systemPackages.add("javax.");
96                 systemPackages.add("sun.");
97         }
98
99         protected static boolean isCommonObjectMethod(final String name) {
100                 return commonObjectMethods.contains(name);
101         }
102
103         protected static boolean isEnumMethod(final String name) {
104                 return enumMethods.contains(name);
105         }
106
107         protected static boolean isSystemDataType(final String name) {
108                 return systemDataTypes.contains(name);
109         }
110
111         protected static boolean isSystemPackage(final String name) {
112
113                 for (final String packagePrefix : systemPackages)
114                         if (name.startsWith(packagePrefix))
115                                 return true;
116
117                 return false;
118         }
119
120         private static final List<String> systemDataTypes = new ArrayList<String>();
121
122         private static final List<String> commonObjectMethods = new ArrayList<String>();
123
124         private static final List<String> systemPackages = new ArrayList<String>();
125
126         private static final List<String> darkColors = new ArrayList<String>();
127
128         private static final List<String> lightColors = new ArrayList<String>();
129
130         private static final List<String> enumMethods = new ArrayList<String>();
131
132         private static int lastChosenDarkColor = -1;
133
134         private static int lastChosenLightColor = -1;
135
136         static {
137                 initEnumMethods();
138                 initSystemDataTypes();
139                 initDarkColors();
140                 initLightColors();
141                 initCommonObjectMethods();
142                 initSystemPackages();
143         }
144
145 }