1 | package com.framsticks.params; |
---|
2 | |
---|
3 | import java.lang.reflect.Field; |
---|
4 | import org.apache.log4j.Logger; |
---|
5 | |
---|
6 | /** |
---|
7 | * The class Flags contains constants connected with parameter features as |
---|
8 | * well as feedback about set operation (when setting parameter value). |
---|
9 | * |
---|
10 | * Based on c++ defines located in: cpp/gdk/param.h |
---|
11 | * |
---|
12 | * @author Jarek Szymczak <name.surname@gmail.com> |
---|
13 | * (please replace name and surname with my personal data) |
---|
14 | * |
---|
15 | * @@author Piotr Sniegowski |
---|
16 | */ |
---|
17 | public final class Flags { |
---|
18 | |
---|
19 | private final static Logger logger = Logger.getLogger(Flags.class.getName()); |
---|
20 | |
---|
21 | |
---|
22 | public static final int READONLY = 1; |
---|
23 | |
---|
24 | public static final int DONTSAVE = 2; |
---|
25 | |
---|
26 | public static final int USERREADONLY = 16; |
---|
27 | |
---|
28 | public static final int USERHIDDEN = 32; |
---|
29 | |
---|
30 | public static final int MUTALLOCENTRY = 64; |
---|
31 | |
---|
32 | public static final int MUTALLOCDATA = 128; |
---|
33 | |
---|
34 | public static final int NOSTATIC = 256; |
---|
35 | |
---|
36 | public static final int CONST = 512; |
---|
37 | |
---|
38 | public static final int CANOMITNAME = 1024; |
---|
39 | |
---|
40 | public static final int DONTLOAD = 2048; |
---|
41 | |
---|
42 | public static final int PSET_RONLY = 1; |
---|
43 | |
---|
44 | public static final int PSET_CHANGED = 2; |
---|
45 | |
---|
46 | public static final int PSET_HITMIN = 4; |
---|
47 | |
---|
48 | public static final int PSET_HITMAX = 8; |
---|
49 | |
---|
50 | public static Integer read(String flags) { |
---|
51 | Integer allFlags = 0; |
---|
52 | String[] flagsSplitted = flags.split("\\+"); |
---|
53 | for (String flag : flagsSplitted) { |
---|
54 | try { |
---|
55 | allFlags |= Integer.valueOf(flag); |
---|
56 | } catch (NumberFormatException ex) { |
---|
57 | try { |
---|
58 | Field field = Flags.class.getDeclaredField(flag.toUpperCase()); |
---|
59 | allFlags |= Integer.parseInt(field.get(null).toString()); |
---|
60 | } catch (SecurityException e) { |
---|
61 | logger.warn("security exception was thrown while trying to read flag (" |
---|
62 | + flag + ")"); |
---|
63 | } catch (NoSuchFieldException e) { |
---|
64 | logger.warn("selected flag is not known (" + flag + ")"); |
---|
65 | } catch (IllegalArgumentException e) { |
---|
66 | logger.warn("selected flag is not known (" + flag + ")"); |
---|
67 | } catch (IllegalAccessException e) { |
---|
68 | logger.warn("selected flag is not known (" + flag + ")"); |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | return allFlags; |
---|
73 | } |
---|
74 | } |
---|