use of com.google.common.collect.BiMap in project pinot by linkedin.
the class GenericResultSetMapper method toResultMapList.
List<Map<String, Object>> toResultMapList(ResultSet rs, Class<? extends AbstractEntity> entityClass) throws Exception {
List<Map<String, Object>> resultMapList = new ArrayList<>();
String tableName = entityMappingHolder.tableToEntityNameMap.inverse().get(entityClass.getSimpleName());
BiMap<String, String> dbNameToEntityNameMapping = entityMappingHolder.columnMappingPerTable.get(tableName);
while (rs.next()) {
ResultSetMetaData resultSetMetaData = rs.getMetaData();
int numColumns = resultSetMetaData.getColumnCount();
HashMap<String, Object> map = new HashMap<>();
for (int i = 1; i <= numColumns; i++) {
String dbColumnName = resultSetMetaData.getColumnLabel(i).toLowerCase();
String entityFieldName = dbNameToEntityNameMapping.get(dbColumnName);
Object val = rs.getObject(i);
if (val != null) {
map.put(entityFieldName, val.toString());
}
}
resultMapList.add(map);
}
System.out.println(resultMapList);
return resultMapList;
}
use of com.google.common.collect.BiMap in project hadoop by apache.
the class TestShellBasedIdMapping method testUpdateMapIncr.
@Test
public void testUpdateMapIncr() throws IOException {
Configuration conf = new Configuration();
conf.setLong(IdMappingConstant.USERGROUPID_UPDATE_MILLIS_KEY, 600000);
ShellBasedIdMapping refIdMapping = new ShellBasedIdMapping(conf, true);
ShellBasedIdMapping incrIdMapping = new ShellBasedIdMapping(conf);
// Command such as "getent passwd <userName>" will return empty string if
// <username> is numerical, remove them from the map for testing purpose.
BiMap<Integer, String> uidNameMap = refIdMapping.getUidNameMap();
BiMap<Integer, String> gidNameMap = refIdMapping.getGidNameMap();
// Force empty map, to see effect of incremental map update of calling
// getUserName()
incrIdMapping.clearNameMaps();
uidNameMap = refIdMapping.getUidNameMap();
for (BiMap.Entry<Integer, String> me : uidNameMap.entrySet()) {
Integer id = me.getKey();
String name = me.getValue();
String tname = incrIdMapping.getUserName(id, null);
assertEquals(name, tname);
}
assertEquals(uidNameMap.size(), incrIdMapping.getUidNameMap().size());
// Force empty map, to see effect of incremental map update of calling
// getUid()
incrIdMapping.clearNameMaps();
for (BiMap.Entry<Integer, String> me : uidNameMap.entrySet()) {
Integer id = me.getKey();
String name = me.getValue();
Integer tid = incrIdMapping.getUid(name);
assertEquals(id, tid);
}
assertEquals(uidNameMap.size(), incrIdMapping.getUidNameMap().size());
// Force empty map, to see effect of incremental map update of calling
// getGroupName()
incrIdMapping.clearNameMaps();
gidNameMap = refIdMapping.getGidNameMap();
for (BiMap.Entry<Integer, String> me : gidNameMap.entrySet()) {
Integer id = me.getKey();
String name = me.getValue();
String tname = incrIdMapping.getGroupName(id, null);
assertEquals(name, tname);
}
assertEquals(gidNameMap.size(), incrIdMapping.getGidNameMap().size());
// Force empty map, to see effect of incremental map update of calling
// getGid()
incrIdMapping.clearNameMaps();
gidNameMap = refIdMapping.getGidNameMap();
for (BiMap.Entry<Integer, String> me : gidNameMap.entrySet()) {
Integer id = me.getKey();
String name = me.getValue();
Integer tid = incrIdMapping.getGid(name);
assertEquals(id, tid);
}
assertEquals(gidNameMap.size(), incrIdMapping.getGidNameMap().size());
}
use of com.google.common.collect.BiMap in project HuskyCrates-Sponge by codeHusky.
the class CrateRewardHolderParser method itemFromNode.
private static ItemStack itemFromNode(ConfigurationNode itemRoot) {
try {
ItemStack item = ItemStack.builder().itemType(itemRoot.getNode("id").getValue(TypeToken.of(ItemType.class))).quantity(itemRoot.getNode("count").getInt(1)).add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(itemRoot.getNode("name").getString())).build();
if (!itemRoot.getNode("variant").isVirtual()) {
//if(Sponge.getRegistry().getType(TreeType.class,itemRoot.getNode("variant").getString()).isPresent()) {
//System.out.println(item.offer(Keys.TREE_TYPE,getTreeType(itemRoot.getNode("variant").getString("oak"))));
//System.out.println(itemRoot.getNode("variant").getValue());
//}
}
if (!itemRoot.getNode("lore").isVirtual()) {
ArrayList<Text> lore = new ArrayList<>();
for (String ll : itemRoot.getNode("lore").getList(TypeToken.of(String.class))) {
lore.add(TextSerializers.FORMATTING_CODE.deserialize(ll));
}
item.offer(Keys.ITEM_LORE, lore);
}
if (!itemRoot.getNode("name").isVirtual()) {
item.offer(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(itemRoot.getNode("name").getString()));
}
if (!itemRoot.getNode("enchants").isVirtual()) {
ArrayList<ItemEnchantment> enchantments = new ArrayList<>();
for (Object key : itemRoot.getNode("enchants").getChildrenMap().keySet()) {
int level = itemRoot.getNode("enchants").getChildrenMap().get(key).getInt();
String enchantID = (String) key;
// STRINGS ONLY!
Enchantment enc = getEnchantment(enchantID);
ItemEnchantment itemEnchantment = new ItemEnchantment(enc, level);
enchantments.add(itemEnchantment);
}
item.offer(Keys.ITEM_ENCHANTMENTS, enchantments);
}
if (!itemRoot.getNode("damage").isVirtual()) {
//HuskyCrates.instance.logger.info("damage override called");
item = ItemStack.builder().fromContainer(//OVERRIDE DAMAGE VAL! :)
item.toContainer().set(DataQuery.of("UnsafeDamage"), itemRoot.getNode("damage").getInt(0))).build();
}
if (!itemRoot.getNode("nbt").isVirtual()) {
//nbt overrrides
LinkedHashMap items = (LinkedHashMap) itemRoot.getNode("nbt").getValue();
if (item.toContainer().get(DataQuery.of("UnsafeData")).isPresent()) {
BiMap real = ((BiMap) item.toContainer().getMap(DataQuery.of("UnsafeData")).get());
items.putAll(real);
}
//System.out.println(item.toContainer().get(DataQuery.of("UnsafeData")).get().getClass());
item = ItemStack.builder().fromContainer(item.toContainer().set(DataQuery.of("UnsafeData"), items)).build();
}
//item.offer(Keys.PICKUP_DELAY,itemRoot.getNode("pickupdelay").getInt())
return item;
} catch (ObjectMappingException e) {
e.printStackTrace();
}
return null;
}
Aggregations