@Test public void testGetValue() { BSONObject field = new BasicBSONObject("field", "TEST1"); BSONObject entry = new BasicBSONObject("enum", field); BSONWritable entity = new BSONWritable(entry); EnumValueMapper<Testing> m = new EnumValueMapper<Testing>("enum.field", Testing.class); Writable value = m.getValue(entity); assertFalse(value instanceof NullWritable); assertTrue(value instanceof Text); assertEquals(((Text) value).toString(), Testing.TEST1.toString()); }
@Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { value = Enum.valueOf(enumClass, value).toString(); rval = new Text(value); } } catch (IllegalArgumentException e) { log.severe(String.format("Failed to convert value {%s} to Enum", value)); } return rval; }
EnumValueMapper extends ValueMapper { @Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { value = Enum.valueOf(enumClass, value).toString(); rval = new Text(value); } } catch (IllegalArgumentException e) { log.severe(String.format("Failed to convert value {%s} to Enum", value)); } return rval; } }
EnumValueMapper extends ValueMapper { @Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { value = Enum.valueOf(enumClass, value).toString(); rval = new Text(value); } } catch (IllegalArgumentException e) { log.severe(String.format("Failed to convert value {%s} to Enum", value)); } return rval; } EnumValueMapper(String fieldName, Class<T> v); }
EnumValueMapper extends ValueMapper { @Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { value = Enum.valueOf(enumClass, value).toString(); rval = new Text(value); } } catch (IllegalArgumentException e) { log.severe(String.format("Failed to convert value {%s} to Enum", value)); } return rval; } EnumValueMapper(String fieldName, Class<T> v); @Override Writable getValue(BSONWritable entity); }
EnumValueMapper extends ValueMapper { @Override public Writable getValue(BSONWritable entity) { Writable rval = NullWritable.get(); String value = null; try { value = BSONUtilities.getValue(entity, fieldName); if (value != null) { value = Enum.valueOf(enumClass, value).toString(); rval = new Text(value); } } catch (IllegalArgumentException e) { log.severe(String.format("Failed to convert value {%s} to Enum", value)); } return rval; } EnumValueMapper(String fieldName, Class<T> v); @Override Writable getValue(BSONWritable entity);  }