org.simpleflatmapper.reflect.Getter.get()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.simpleflatmapper.reflect.Getter.get()方法的一些代码示例,展示了Getter.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Getter.get()方法的具体详情如下:
包路径:org.simpleflatmapper.reflect.Getter
类名称:Getter
方法名:get

Getter.get介绍

[英]Return the property from the specified object.
[中]从指定对象返回属性。

代码示例

代码示例来源:origin: arnaudroger/SimpleFlatMapper

public Object[] build(S source) throws Exception {
  Object[] args = new Object[getters.length];
  
  for(int i = 0; i < args.length; i++) {
    args[i] = getters[i].get(source);
  }
  
  return args;
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public Byte get(T target) throws Exception {
    return delegate.get(target);
  }
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public Float get(T target) throws Exception {
    return delegate.get(target);
  }
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
public BigInteger get(final ResultSet target) throws Exception {
  String val = getter.get(target);
  if (val == null) return null;
  return new BigInteger(val);
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
public Calendar get(ResultSet target) throws Exception {
  Date d = dateGetter.get(target);
  if (d != null) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);
    return cal;
  }
  return null;
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public void set(T target, P value) throws Exception {
    setter.set(target, getter.get(value));
  }
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
public void mapTo(final S source, final T target, final MappingContext<? super S> mappingContext) throws Exception {
  final P value = getter.get(source);
  setter.set(target, value, mappingContext);
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@SuppressWarnings("unchecked")
  @Override
  public GenericBuilder<S, T> newInstance(S o, MappingContext<? super S> o2) throws Exception {
    Object value = getter.get(o);
    
    BiInstantiator<S, MappingContext<? super S>, GenericBuilder<S, T>> instantiator = instantiators.get(value);
    
    if (instantiator == null)
      throw new IllegalArgumentException("No discrimator matched " + value);
    return instantiator.newInstance(o, o2);
  }
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
public T apply(S1 s1, S2 s2) {
  try {
    return getter.get(s1);
  } catch (Exception e) {
    return ErrorHelper.rethrow(e);
  }
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testJavaOffsetDateTime() throws Exception {
  final OffsetDateTime offsetDateTime = OffsetDateTime.now();
  when(resultSet.getObject(1)).thenReturn(offsetDateTime, (OffsetDateTime) null);
  Getter<ResultSet, java.time.OffsetDateTime> getter = factory.<java.time.OffsetDateTime>newGetter(java.time.OffsetDateTime.class, key(Types.TIMESTAMP_WITH_TIMEZONE));
  assertEquals(offsetDateTime, getter.get(resultSet));
  assertNull(getter.get(resultSet));
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testClob() throws Exception {
  Clob blob = mock(Clob.class);
  when(resultSet.getClob(1)).thenReturn(blob);
  Getter<ResultSet, Object> getter = factory.newGetter(Clob.class, key(Types.CLOB), IDENTITY.properties());
  assertEquals(blob, getter.get(resultSet));
  assertEquals("ClobResultSetGetter{property=1}", getter.toString());
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testObject() throws Exception {
  Object object = new Object();
  when(resultSet.getObject(1)).thenReturn(object);
  Getter<ResultSet, Object> getter = factory.newGetter(Object.class, key(JdbcColumnKey.UNDEFINED_TYPE), IDENTITY.properties());
  assertEquals(object, getter.get(resultSet));
  assertEquals("ObjectResultSetGetter{property=1}", getter.toString());
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testTimestamp() throws Exception {
  Timestamp time = new Timestamp(10000);
  when(resultSet.getTimestamp(1)).thenReturn(time);
  assertEquals(time, factory.newGetter(Timestamp.class, key(JdbcColumnKey.UNDEFINED_TYPE), IDENTITY.properties()).get(resultSet));
  Getter<ResultSet, Object> getter = factory.newGetter(java.util.Date.class, key(Types.TIMESTAMP), IDENTITY.properties());
  assertEquals(time, getter.get(resultSet));
  assertEquals("TimestampResultSetGetter{property=1}", getter.toString());
}
@Test

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testNClob() throws Exception {
  NClob blob = mock(NClob.class);
  when(resultSet.getNClob(1)).thenReturn(blob);
  Getter<ResultSet, Object> getter = factory.newGetter(NClob.class, key(Types.NCLOB), IDENTITY.properties());
  assertEquals(blob, getter.get(resultSet));
  assertEquals("NClobResultSetGetter{property=1}", getter.toString());
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testUrl() throws Exception {
  URL url = new URL("http://url.net");
  when(resultSet.getURL(1)).thenReturn(url);
  Getter<ResultSet, Object> getter = factory.newGetter(URL.class, key(Types.DATALINK), IDENTITY.properties());
  assertEquals(url, getter.get(resultSet));
  assertEquals("UrlResultSetGetter{property=1}", getter.toString());
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testObjectGetterNoAsm() throws Exception {
  assertEquals(dbo.getName(), noAsm.getGetter(DbObject.class, "name").get(dbo));
  assertEquals(dbfo.getName(), noAsm.getGetter(DbFinalObject.class, "name").get(dbfo));
  assertEquals(dbpo.name, noAsm.getGetter(DbPublicObject.class, "name").get(dbpo));
  assertEquals("MethodGetter{method=public java.lang.String org.simpleflatmapper.test.beans.DbObject.getName()}", noAsm.getGetter(DbObject.class, "name").toString());
  assertEquals("MethodGetter{method=public java.lang.String org.simpleflatmapper.test.beans.DbFinalObject.getName()}", noAsm.getGetter(DbFinalObject.class, "name").toString());
  assertEquals("FieldGetter{field=public java.lang.String org.simpleflatmapper.test.beans.DbPublicObject.name}", noAsm.getGetter(DbPublicObject.class, "name").toString());
}
@Test

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void test() throws Exception {
  @SuppressWarnings("unchecked") Getter<Object, String> stringGetter = mock(Getter.class);
  StringEnumGetter<Object, ENUM> getter = new StringEnumGetter<Object, ENUM>(stringGetter, ENUM.class);
  when(stringGetter.get(any())).thenReturn("ZERO", "ONE", "TWO", "THREE");
  assertEquals(ENUM.ZERO, getter.get(null));
  assertEquals(ENUM.ONE, getter.get(null));
  assertEquals(ENUM.TWO, getter.get(null));
  assertEquals(ENUM.THREE, getter.get(null));
  getter.toString();
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void methodBetterThanField() throws Exception {
  ScoredGetter<Object, Object> method = ScoredGetter.ofMethod(Getters.class.getDeclaredMethod("getValue"), new ConstantGetter<Object, Object>("val"));
  ScoredGetter<Object, Object> field = ScoredGetter.ofField(Getters.class.getDeclaredField("value"), NullGetter.getter());
  assertTrue(method.isBetterThan(field));
  assertEquals("val", method.getGetter().get(null));
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

private Object testSet(TypeReference<?> typeReference) throws Exception {
  ClassMeta<?> classMeta = ReflectionService.newInstance().getClassMeta(typeReference.getType());
  assertTrue(classMeta instanceof ArrayClassMeta);
  PropertyMeta p = findProperty(classMeta);
  Set<String> list = (Set<String>) instantiate(classMeta);
  p.getSetter().set(list, "aaa");
  assertEquals(null, p.getGetter().get(list));
  assertEquals("aaa", list.iterator().next());
  return list;
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
  public void testNullGetter() throws Exception {
    assertTrue(NullGetter.isNull(null));
    assertTrue(NullGetter.isNull(NullGetter.getter()));
    assertFalse(NullGetter.isNull(new ConstantGetter<Object, Object>(null)));
    assertNull(NullGetter.getter().get(null));

    assertEquals("NullGetter{}", NullGetter.getter().toString());
  }
}

相关文章

Getter类方法