source: java/main/src/main/java/com/framsticks/params/Flags.java @ 85

Last change on this file since 85 was 85, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • upgrade to Java 7
    • use try-multi-catch clauses
    • use try-with-resources were appropriate
  • configure FindBugs? (use mvn site and then navigate in browser to the report)
    • remove most bugs found
  • parametrize Dispatching environment (Dispatcher, RunAt?) to enforce more control on the place of closures actual call

CHANGELOG:
Rework FavouritesXMLFactory.

FindBugs?. Thread start.

FindBugs?. Minor change.

FindBugs?. Iterate over entrySet.

FindBugs?. Various.

FindBug?.

FindBug?. Encoding.

FindBug?. Final fields.

FindBug?.

Remove synchronization bug in ClientConnection?.

Experiments with findbugs.

Finish parametrization.

Make RunAt? an abstract class.

More changes in parametrization.

More changes in parametrizing dispatching.

Several changes to parametrize tasks.

Rename Runnable to RunAt?.

Add specific framsticks Runnable.

Add JSR305 (annotations).

Add findbugs reporting.

More improvements to ParamBuilder? wording.

Make FramsClass? accept also ParamBuilder?.

Change wording of ParamBuilder?.

Change wording of Request creation.

Use Java 7 exception catch syntax.

Add ScopeEnd? class.

Upgrade to Java 7.

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