 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.model.archetypetype;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.List;
30 import org.apache.log4j.Category;
31 import org.apache.log4j.Logger;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
60 private final List<String>
bitName =
new ArrayList<>();
72 private final Map<String, Integer>
namedValues =
new HashMap<>();
78 private final Map<Integer, String>
encodings =
new HashMap<>();
84 private final Map<Integer, String>
names =
new HashMap<>();
122 return Integer.toString(value);
125 final StringBuilder sb =
new StringBuilder();
127 if (sb.length() > 0) {
132 return sb.toString();
146 private Iterable<String>
encodeValueAsList(
final int value, @NotNull
final Map<Integer, String> strings) {
149 final Collection<String> negResult =
new ArrayList<>();
150 negResult.add(
"all");
152 if (value == moveAll) {
155 final Collection<String> result =
new ArrayList<>();
157 final String str = strings.get(0);
158 result.add(str ==
null ?
"0" : str);
168 for (
int i = moveAll; i != 0; i >>= 1) {
169 final String strNull = strings.get(1 << count);
170 final String str = strNull ==
null ? Integer.toString(1 << count) : strNull;
171 if ((value & (1 << count)) == 0) {
172 negResult.add(
"-" + str);
179 if ((value & ~moveAll) != 0) {
180 result.add(Integer.toString(value & ~moveAll));
188 return count >= 4 && allCount <= 1 ? negResult : result;
201 if (encodedValue.isEmpty()) {
207 final boolean negated;
209 if (word.startsWith(
"-")) {
211 name = word.substring(1);
218 if (integerValue ==
null) {
220 value = Integer.parseInt(
name);
221 }
catch (
final NumberFormatException ignored) {
222 LOG.warn(
"Ignoring unknown bitmask value: " +
name);
226 value = integerValue;
242 return (1 <<
bitName.size()) - 1;
268 public void addName(@NotNull
final String
name,
final int value) {
298 if (bitValue >=
bitName.size()) {
301 }
while (bitValue >=
bitName.size());
302 }
else if (
bitName.get(bitValue) !=
null) {
static int parseInt(@NotNull final String s)
Parses an integer string.
int getNumber()
Returns the number of bitmask entries (not counting zero).
final Map< Integer, String > encodings
Maps bit value to external representation.
void append(final String str)
Appends a word.
Base package of all Gridarta classes.
int getMaxValue()
Returns the maximum allowed bitmask value.
final boolean isNamed
Set if the bitmask value may be encoded as strings in external representation; unset if the value is ...
Iterable< String > encodeValueAsList(final int value, @NotNull final Map< Integer, String > strings)
Convert a value to string representation.
AttributeBitmask(final boolean isNamed)
Constructor of a bitmask from XML element.
String getText(final int value)
Generate the text to be displayed for a given bitmask value.
final Map< String, Integer > namedValues
Maps names for value encoding in external representation.
final List< String > bitName
The names of the bitmask entries.
Implements a string buffer that separates words by "," and wraps lines at a given margin.
int decodeValue(@NotNull final String encodedValue)
Convert a value from external representation.
boolean addBitName(final int bitValue, @NotNull final String name)
Defines a bit name for a bit value.
String encodeValue(final int value)
Convert a value to external representation.
String getBitName(final int index)
Returns the name of a bitmask value.
boolean containsEncoding(final int value)
Returns whether an external encoding for value exists.
This class manages bitmask values which appear in Gridarta archetype attributes.
Utility class for string manipulation.
static final Pattern PATTERN_SPACES
The pattern that matches a non-empty sequence of spaces.
static final Category LOG
The Logger for printing log messages.
void addNamedValue(@NotNull final String name, final int value)
Adds a name for external encoding of a value.
void addName(@NotNull final String name, final int value)
Adds a readable name for a bit value.
static final int MAX_CHARS_PER_LINE
Maximum number of characters in a line before line break (see {}).
String toString()
Returns the concatenated words as a string.
Utility class for parsing strings into numbers.
final Map< Integer, String > names
Maps bit value to readable name.