refactored packages
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / structure / Utils.java
1 /*
2  * JavaInspect - Utility to visualize java software
3  * Copyright (C) 2013, 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 2 of the GNU General Public License
7  * 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> systemMethods = 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                 initSystemMethods();
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 initDarkColors() {
65                 darkColors.add("antiquewhite4");
66                 darkColors.add("blueviolet");
67                 darkColors.add("brown4");
68                 darkColors.add("chartreuse4");
69                 darkColors.add("cyan4");
70                 darkColors.add("deeppink1");
71                 darkColors.add("deepskyblue3");
72                 darkColors.add("firebrick1");
73                 darkColors.add("goldenrod3");
74                 darkColors.add("gray0");
75         }
76
77         public static void initEnumMethods() {
78                 enumMethods.add("values");
79                 enumMethods.add("valueOf");
80                 enumMethods.add("name");
81                 enumMethods.add("compareTo");
82                 enumMethods.add("valueOf");
83                 enumMethods.add("getDeclaringClass");
84                 enumMethods.add("ordinal");
85         }
86
87         public static void initLightColors() {
88                 lightColors.add("olivedrab2");
89                 lightColors.add("peachpuff2");
90                 lightColors.add("seagreen1");
91                 lightColors.add("yellow");
92                 lightColors.add("violet");
93         }
94
95         public static void initSystemDataTypes() {
96                 systemDataTypes.add("void");
97                 systemDataTypes.add("int");
98                 systemDataTypes.add("long");
99                 systemDataTypes.add("float");
100                 systemDataTypes.add("double");
101                 systemDataTypes.add("boolean");
102                 systemDataTypes.add("char");
103                 systemDataTypes.add("short");
104                 systemDataTypes.add("byte");
105         }
106
107         public static void initSystemMethods() {
108                 systemMethods.add("wait");
109                 systemMethods.add("equals");
110                 systemMethods.add("toString");
111                 systemMethods.add("hashCode");
112                 systemMethods.add("notify");
113                 systemMethods.add("notifyAll");
114                 systemMethods.add("getClass");
115         }
116
117         public static void initSystemPackages() {
118                 systemPackages.add("java.");
119                 systemPackages.add("javax.");
120                 systemPackages.add("sun.");
121         }
122
123         public static boolean isEnumMethod(final String name) {
124                 return enumMethods.contains(name);
125         }
126
127         public static boolean isSystemDataType(final String name) {
128                 return systemDataTypes.contains(name);
129         }
130
131         public static boolean isSystemMethod(final String name) {
132                 return systemMethods.contains(name);
133         }
134
135         public static boolean isSystemPackage(final String name) {
136
137                 for (final String packagePrefix : systemPackages)
138                         if (name.startsWith(packagePrefix))
139                                 return true;
140
141                 return false;
142         }
143
144 }