fixed javadoc issues
[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          * @return next available dark color name
21          */
22         protected static String getNextDarkColor() {
23                 lastChosenDarkColor++;
24                 if (lastChosenDarkColor >= darkColors.size())
25                         lastChosenDarkColor = 0;
26
27                 return darkColors.get(lastChosenDarkColor);
28         }
29
30         /**
31          * retrieves colors from predefined palette
32          *
33          * @return next available light color name
34          */
35         protected static String getNextLightColor() {
36                 lastChosenLightColor++;
37                 if (lastChosenLightColor >= lightColors.size())
38                         lastChosenLightColor = 0;
39
40                 return lightColors.get(lastChosenLightColor);
41         }
42
43         private static void initCommonObjectMethods() {
44                 commonObjectMethods.add("wait");
45                 commonObjectMethods.add("equals");
46                 commonObjectMethods.add("toString");
47                 commonObjectMethods.add("hashCode");
48                 commonObjectMethods.add("notify");
49                 commonObjectMethods.add("notifyAll");
50                 commonObjectMethods.add("getClass");
51         }
52
53         protected static void initDarkColors() {
54                 darkColors.add("antiquewhite4");
55                 darkColors.add("blueviolet");
56                 darkColors.add("brown4");
57                 darkColors.add("chartreuse4");
58                 darkColors.add("cyan4");
59                 darkColors.add("deeppink1");
60                 darkColors.add("deepskyblue3");
61                 darkColors.add("firebrick1");
62                 darkColors.add("goldenrod3");
63                 darkColors.add("gray0");
64         }
65
66         private static void initEnumMethods() {
67                 enumMethods.add("values");
68                 enumMethods.add("valueOf");
69                 enumMethods.add("name");
70                 enumMethods.add("compareTo");
71                 enumMethods.add("valueOf");
72                 enumMethods.add("getDeclaringClass");
73                 enumMethods.add("ordinal");
74         }
75
76         private static void initLightColors() {
77                 lightColors.add("olivedrab2");
78                 lightColors.add("peachpuff2");
79                 lightColors.add("seagreen1");
80                 lightColors.add("violet");
81                 lightColors.add("aqua");
82                 lightColors.add("orange");
83         }
84
85         private static void initSystemDataTypes() {
86                 systemDataTypes.add("void");
87                 systemDataTypes.add("int");
88                 systemDataTypes.add("long");
89                 systemDataTypes.add("float");
90                 systemDataTypes.add("double");
91                 systemDataTypes.add("boolean");
92                 systemDataTypes.add("char");
93                 systemDataTypes.add("short");
94                 systemDataTypes.add("byte");
95         }
96
97         private static void initSystemPackages() {
98                 systemPackages.add("java.");
99                 systemPackages.add("javax.");
100                 systemPackages.add("sun.");
101         }
102
103         protected static boolean isCommonObjectMethod(final String name) {
104                 return commonObjectMethods.contains(name);
105         }
106
107         protected static boolean isEnumMethod(final String name) {
108                 return enumMethods.contains(name);
109         }
110
111         protected static boolean isSystemDataType(final String name) {
112                 return systemDataTypes.contains(name);
113         }
114
115         protected static boolean isSystemPackage(final String name) {
116
117                 for (final String packagePrefix : systemPackages)
118                         if (name.startsWith(packagePrefix))
119                                 return true;
120
121                 return false;
122         }
123
124         private static final List<String> systemDataTypes = new ArrayList<String>();
125
126         private static final List<String> commonObjectMethods = new ArrayList<String>();
127
128         private static final List<String> systemPackages = new ArrayList<String>();
129
130         private static final List<String> darkColors = new ArrayList<String>();
131
132         private static final List<String> lightColors = new ArrayList<String>();
133
134         private static final List<String> enumMethods = new ArrayList<String>();
135
136         private static int lastChosenDarkColor = -1;
137
138         private static int lastChosenLightColor = -1;
139
140         static {
141                 initEnumMethods();
142                 initSystemDataTypes();
143                 initDarkColors();
144                 initLightColors();
145                 initCommonObjectMethods();
146                 initSystemPackages();
147         }
148
149 }