use of java.util.EnumSet in project API by RockBottomGame.
the class DataSet method getEnum.
public <T extends Enum<T>> T getEnum(String key, Class<T> type) {
if (this.hasKey(key)) {
int ordinal = this.getInt(key);
EnumSet set = EnumSet.allOf(type);
if (set.size() > ordinal) {
return (T) set.toArray()[ordinal];
}
}
return null;
}
use of java.util.EnumSet in project accumulo by apache.
the class TableOperationsHelperTest method testAttachIterator.
@Test
public void testAttachIterator() throws Exception {
TableOperationsHelper t = getHelper();
Map<String, String> empty = Collections.emptyMap();
t.attachIterator("table", new IteratorSetting(10, "someName", "foo.bar", empty), EnumSet.of(IteratorScope.scan));
check(t, "table", new String[] { "table.iterator.scan.someName=10,foo.bar" });
t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan));
check(t, "table", new String[] {});
IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
setting.addOptions(Collections.singletonMap("key", "value"));
t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc));
setting = new IteratorSetting(10, "someName", "foo.bar");
t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan));
check(t, "table", new String[] { "table.iterator.majc.someName=10,foo.bar", "table.iterator.majc.someName.opt.key=value", "table.iterator.scan.someName=10,foo.bar" });
t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan));
setting = new IteratorSetting(20, "otherName", "some.classname");
setting.addOptions(Collections.singletonMap("key", "value"));
t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc));
setting = new IteratorSetting(20, "otherName", "some.classname");
t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan));
Map<String, EnumSet<IteratorScope>> two = t.listIterators("table");
assertEquals(2, two.size());
assertTrue(two.containsKey("otherName"));
assertEquals(2, two.get("otherName").size());
assertTrue(two.get("otherName").contains(IteratorScope.majc));
assertTrue(two.get("otherName").contains(IteratorScope.scan));
assertTrue(two.containsKey("someName"));
assertEquals(1, two.get("someName").size());
assertTrue(two.get("someName").contains(IteratorScope.majc));
t.removeIterator("table", "someName", EnumSet.allOf(IteratorScope.class));
check(t, "table", new String[] { "table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value", "table.iterator.scan.otherName=20,some.classname" });
setting = t.getIteratorSetting("table", "otherName", IteratorScope.scan);
assertEquals(20, setting.getPriority());
assertEquals("some.classname", setting.getIteratorClass());
assertTrue(setting.getOptions().isEmpty());
final IteratorSetting setting1 = t.getIteratorSetting("table", "otherName", IteratorScope.majc);
assertEquals(20, setting1.getPriority());
assertEquals("some.classname", setting1.getIteratorClass());
assertFalse(setting1.getOptions().isEmpty());
assertEquals(Collections.singletonMap("key", "value"), setting1.getOptions());
t.attachIterator("table", setting1, EnumSet.of(IteratorScope.minc));
check(t, "table", new String[] { "table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value", "table.iterator.minc.otherName=20,some.classname", "table.iterator.minc.otherName.opt.key=value", "table.iterator.scan.otherName=20,some.classname" });
assertThrows(AccumuloException.class, () -> t.attachIterator("table", setting1));
setting1.setName("thirdName");
assertThrows(AccumuloException.class, () -> t.attachIterator("table", setting1));
setting1.setPriority(10);
t.setProperty("table", "table.iterator.minc.thirdName.opt.key", "value");
assertThrows(AccumuloException.class, () -> t.attachIterator("table", setting1));
t.removeProperty("table", "table.iterator.minc.thirdName.opt.key");
t.attachIterator("table", setting1);
}
use of java.util.EnumSet in project accumulo by apache.
the class TableOperationsHelper method listIterators.
@Override
public Map<String, EnumSet<IteratorScope>> listIterators(String tableName) throws AccumuloException, TableNotFoundException {
EXISTING_TABLE_NAME.validate(tableName);
Map<String, EnumSet<IteratorScope>> result = new TreeMap<>();
for (Entry<String, String> property : this.getProperties(tableName)) {
String name = property.getKey();
String[] parts = name.split("\\.");
if (parts.length == 4) {
if (parts[0].equals("table") && parts[1].equals("iterator")) {
IteratorScope scope = IteratorScope.valueOf(parts[2]);
if (!result.containsKey(parts[3]))
result.put(parts[3], EnumSet.noneOf(IteratorScope.class));
result.get(parts[3]).add(scope);
}
}
}
return result;
}
use of java.util.EnumSet in project accumulo by apache.
the class NamespaceOperationsHelper method listIterators.
@Override
public Map<String, EnumSet<IteratorScope>> listIterators(String namespace) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException {
if (!exists(namespace))
throw new NamespaceNotFoundException(null, namespace, null);
Map<String, EnumSet<IteratorScope>> result = new TreeMap<>();
for (Entry<String, String> property : this.getProperties(namespace)) {
String name = property.getKey();
String[] parts = name.split("\\.");
if (parts.length == 4) {
if (parts[0].equals("table") && parts[1].equals("iterator")) {
IteratorScope scope = IteratorScope.valueOf(parts[2]);
if (!result.containsKey(parts[3]))
result.put(parts[3], EnumSet.noneOf(IteratorScope.class));
result.get(parts[3]).add(scope);
}
}
}
return result;
}
use of java.util.EnumSet in project accumulo by apache.
the class ListIterCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
boolean tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !shellState.getTableName().isEmpty();
boolean namespaces = cl.hasOption(OptUtil.namespaceOpt().getOpt());
final Map<String, EnumSet<IteratorScope>> iterators;
if (namespaces) {
iterators = shellState.getAccumuloClient().namespaceOperations().listIterators(OptUtil.getNamespaceOpt(cl, shellState));
} else if (tables) {
iterators = shellState.getAccumuloClient().tableOperations().listIterators(OptUtil.getTableOpt(cl, shellState));
} else {
throw new IllegalArgumentException("No table or namespace specified");
}
if (cl.hasOption(nameOpt.getOpt())) {
final String name = cl.getOptionValue(nameOpt.getOpt());
if (!iterators.containsKey(name)) {
Shell.log.warn("no iterators found that match your criteria");
return 0;
}
final EnumSet<IteratorScope> scopes = iterators.get(name);
iterators.clear();
iterators.put(name, scopes);
}
final boolean allScopes = cl.hasOption(allScopesOpt.getOpt());
Set<IteratorScope> desiredScopes = new HashSet<>();
for (IteratorScope scope : IteratorScope.values()) {
if (allScopes || cl.hasOption(scopeOpts.get(scope).getOpt()))
desiredScopes.add(scope);
}
if (desiredScopes.isEmpty()) {
throw new IllegalArgumentException("You must select at least one scope to configure");
}
final StringBuilder sb = new StringBuilder("-\n");
for (Entry<String, EnumSet<IteratorScope>> entry : iterators.entrySet()) {
final String name = entry.getKey();
final EnumSet<IteratorScope> scopes = entry.getValue();
for (IteratorScope scope : scopes) {
if (desiredScopes.contains(scope)) {
IteratorSetting setting;
if (namespaces) {
setting = shellState.getAccumuloClient().namespaceOperations().getIteratorSetting(OptUtil.getNamespaceOpt(cl, shellState), name, scope);
} else if (tables) {
setting = shellState.getAccumuloClient().tableOperations().getIteratorSetting(OptUtil.getTableOpt(cl, shellState), name, scope);
} else {
throw new IllegalArgumentException("No table or namespace specified");
}
sb.append("- Iterator ").append(setting.getName()).append(", ").append(scope).append(" scope options:\n");
sb.append("- ").append("iteratorPriority").append(" = ").append(setting.getPriority()).append("\n");
sb.append("- ").append("iteratorClassName").append(" = ").append(setting.getIteratorClass()).append("\n");
for (Entry<String, String> optEntry : setting.getOptions().entrySet()) {
sb.append("- ").append(optEntry.getKey()).append(" = ").append(optEntry.getValue()).append("\n");
}
}
}
}
sb.append("-");
shellState.getWriter().println(sb);
return 0;
}
Aggregations