use of java.util.EnumMap in project zxing-android-embedded by journeyapps.
the class DecodeHintManager method parseDecodeHints.
static Map<DecodeHintType, ?> parseDecodeHints(Uri inputUri) {
String query = inputUri.getEncodedQuery();
if (query == null || query.isEmpty()) {
return null;
}
// Extract parameters
Map<String, String> parameters = splitQuery(query);
Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
for (DecodeHintType hintType : DecodeHintType.values()) {
if (hintType == DecodeHintType.CHARACTER_SET || hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK || hintType == DecodeHintType.POSSIBLE_FORMATS) {
// This hint is specified in another way
continue;
}
String parameterName = hintType.name();
String parameterText = parameters.get(parameterName);
if (parameterText == null) {
continue;
}
if (hintType.getValueType().equals(Object.class)) {
// This is an unspecified type of hint content. Use the value as is.
// TODO: Can we make a different assumption on this?
hints.put(hintType, parameterText);
continue;
}
if (hintType.getValueType().equals(Void.class)) {
// Void hints are just flags: use the constant specified by DecodeHintType
hints.put(hintType, Boolean.TRUE);
continue;
}
if (hintType.getValueType().equals(String.class)) {
// A string hint: use the decoded value.
hints.put(hintType, parameterText);
continue;
}
if (hintType.getValueType().equals(Boolean.class)) {
// An empty parameter is simply a flag-style parameter, assuming true
if (parameterText.isEmpty()) {
hints.put(hintType, Boolean.TRUE);
} else if ("0".equals(parameterText) || "false".equalsIgnoreCase(parameterText) || "no".equalsIgnoreCase(parameterText)) {
hints.put(hintType, Boolean.FALSE);
} else {
hints.put(hintType, Boolean.TRUE);
}
continue;
}
if (hintType.getValueType().equals(int[].class)) {
// Strip a trailing comma as in Java style array initialisers.
if (!parameterText.isEmpty() && parameterText.charAt(parameterText.length() - 1) == ',') {
parameterText = parameterText.substring(0, parameterText.length() - 1);
}
String[] values = COMMA.split(parameterText);
int[] array = new int[values.length];
for (int i = 0; i < values.length; i++) {
try {
array[i] = Integer.parseInt(values[i]);
} catch (NumberFormatException ignored) {
Log.w(TAG, "Skipping array of integers hint " + hintType + " due to invalid numeric value: '" + values[i] + '\'');
array = null;
break;
}
}
if (array != null) {
hints.put(hintType, array);
}
continue;
}
Log.w(TAG, "Unsupported hint type '" + hintType + "' of type " + hintType.getValueType());
}
Log.i(TAG, "Hints from the URI: " + hints);
return hints;
}
use of java.util.EnumMap in project neo4j-mobile-android by neo4j-contrib.
the class StandardExpander method temporaryTypeMapFrom.
private static Map<Direction, Collection<RelationshipType>> temporaryTypeMapFrom(Map<Direction, RelationshipType[]> typeMap) {
Map<Direction, Collection<RelationshipType>> map = new EnumMap<Direction, Collection<RelationshipType>>(Direction.class);
for (Direction direction : Direction.values()) {
ArrayList<RelationshipType> types = new ArrayList<RelationshipType>();
map.put(direction, types);
RelationshipType[] existing = typeMap.get(direction);
if (existing != null) {
types.addAll(asList(existing));
}
}
return map;
}
use of java.util.EnumMap in project neo4j-mobile-android by neo4j-contrib.
the class ReadTransaction method getMoreRelationships.
static Pair<Map<DirectionWrapper, Iterable<RelationshipRecord>>, Long> getMoreRelationships(long nodeId, long position, int grabSize, RelationshipStore relStore) {
// initialCapacity=grabSize saves the lists the trouble of resizing
List<RelationshipRecord> out = new ArrayList<RelationshipRecord>();
List<RelationshipRecord> in = new ArrayList<RelationshipRecord>();
List<RelationshipRecord> loop = null;
Map<DirectionWrapper, Iterable<RelationshipRecord>> result = new EnumMap<DirectionWrapper, Iterable<RelationshipRecord>>(DirectionWrapper.class);
result.put(DirectionWrapper.OUTGOING, out);
result.put(DirectionWrapper.INCOMING, in);
for (int i = 0; i < grabSize && position != Record.NO_NEXT_RELATIONSHIP.intValue(); i++) {
RelationshipRecord relRecord = relStore.getChainRecord(position);
if (relRecord == null) {
// return what we got so far
return Pair.of(result, position);
}
long firstNode = relRecord.getFirstNode();
long secondNode = relRecord.getSecondNode();
if (relRecord.inUse()) {
if (firstNode == secondNode) {
if (loop == null) {
// This is done lazily because loops are probably quite
// rarely encountered
loop = new ArrayList<RelationshipRecord>();
result.put(DirectionWrapper.BOTH, loop);
}
loop.add(relRecord);
} else if (firstNode == nodeId) {
out.add(relRecord);
} else if (secondNode == nodeId) {
in.add(relRecord);
}
} else {
i--;
}
if (firstNode == nodeId) {
position = relRecord.getFirstNextRel();
} else if (secondNode == nodeId) {
position = relRecord.getSecondNextRel();
} else {
throw new InvalidRecordException("Node[" + nodeId + "] is neither firstNode[" + firstNode + "] nor secondNode[" + secondNode + "] for Relationship[" + relRecord.getId() + "]");
}
}
return Pair.of(result, position);
}
use of java.util.EnumMap in project querydsl by querydsl.
the class EntitySerializerTest method original_category.
@Test
public void original_category() throws IOException {
Map<TypeCategory, String> categoryToSuperClass = new EnumMap<TypeCategory, String>(TypeCategory.class);
categoryToSuperClass.put(TypeCategory.COMPARABLE, "ComparablePath<Entity>");
categoryToSuperClass.put(TypeCategory.ENUM, "EnumPath<Entity>");
categoryToSuperClass.put(TypeCategory.DATE, "DatePath<Entity>");
categoryToSuperClass.put(TypeCategory.DATETIME, "DateTimePath<Entity>");
categoryToSuperClass.put(TypeCategory.TIME, "TimePath<Entity>");
categoryToSuperClass.put(TypeCategory.NUMERIC, "NumberPath<Entity>");
categoryToSuperClass.put(TypeCategory.STRING, "StringPath");
categoryToSuperClass.put(TypeCategory.BOOLEAN, "BooleanPath");
for (Map.Entry<TypeCategory, String> entry : categoryToSuperClass.entrySet()) {
SimpleType type = new SimpleType(entry.getKey(), "Entity", "", "Entity", false, false);
EntityType entityType = new EntityType(type);
typeMappings.register(entityType, queryTypeFactory.create(entityType));
serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
assertTrue(entry.toString(), writer.toString().contains("public class QEntity extends " + entry.getValue() + " {"));
}
}
use of java.util.EnumMap in project robovm by robovm.
the class EnumMapTest method test_ConstructorLjava_util_Map.
/**
* java.util.EnumMap#EnumMap(Map)
*/
@SuppressWarnings({ "unchecked", "boxing" })
public void test_ConstructorLjava_util_Map() {
EnumMap enumMap;
Map enumColorMap = null;
try {
enumMap = new EnumMap(enumColorMap);
fail("Expected NullPointerException");
} catch (NullPointerException e) {
// Expected
}
enumColorMap = new EnumMap<Color, Double>(Color.class);
enumMap = new EnumMap(enumColorMap);
enumColorMap.put(Color.Blue, 3);
enumMap = new EnumMap(enumColorMap);
HashMap hashColorMap = null;
try {
enumMap = new EnumMap(hashColorMap);
fail("Expected NullPointerException");
} catch (NullPointerException e) {
// Expected
}
hashColorMap = new HashMap();
try {
enumMap = new EnumMap(hashColorMap);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
hashColorMap.put(Color.Green, 2);
enumMap = new EnumMap(hashColorMap);
assertEquals("Constructor fails", 2, enumMap.get(Color.Green));
assertNull("Constructor fails", enumMap.get(Color.Red));
enumMap.put(Color.Red, 1);
assertEquals("Wrong value", 1, enumMap.get(Color.Red));
hashColorMap.put(Size.Big, 3);
try {
enumMap = new EnumMap(hashColorMap);
fail("Expected ClassCastException");
} catch (ClassCastException e) {
// Expected
}
hashColorMap = new HashMap();
hashColorMap.put(new Integer(1), 1);
try {
enumMap = new EnumMap(hashColorMap);
fail("Expected ClassCastException");
} catch (ClassCastException e) {
// Expected
}
}
Aggregations