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