本文整理了Java中com.obsidiandynamics.yconf.YObject
类的一些代码示例,展示了YObject
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YObject
类的具体详情如下:
包路径:com.obsidiandynamics.yconf.YObject
类名称:YObject
[英]Encapsulates a DOM fragment, as well as the current MappingContext.
[中]封装DOM片段以及当前映射上下文。
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
@Override public Object map(YObject y, Class<?> type) {
return of(y.mapAttribute("value", Object.class), y.mapAttribute("error", String.class));
}
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public YObject getAttribute(String att) {
checkNotNull();
return new YObject(this.<Map<?, ?>>value().get(att), context);
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
@Override
public Object map(YObject y, Class<?> type) {
return y.asList().stream().map(o -> o.map(Object.class)).collect(Collectors.toCollection(ArrayList::new));
}
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public <T> YObject thenMap(Class<? extends T> type, Consumer<T> consumer) {
if (! y.isNull()) {
consumer.accept(y.map(type));
}
return YObject.this;
}
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public List<YObject> asList() {
checkNotNull();
final List<?> items = (List<?>) dom;
final List<YObject> list = new ArrayList<>(items.size());
for (Object i : items) {
list.add(new YObject(i, context));
}
return list;
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public <T> T mapAttribute(String att, Class<? extends T> type) {
return context.map(getAttribute(att).value(), type);
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
@Override
public Object map(YObject y, Class<?> type) {
if (y.is(coercedType)) {
return y.value();
} else {
final String str = String.valueOf(y.<Object>value());
try {
return converter.convert(str);
} catch (Throwable e) {
throw new CoercionException(null, e);
}
}
}
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
@Override
public Object map(YObject y, Class<?> type) {
final Object val = y.value();
final String typeVal;
if (val instanceof Map) {
return y.map(concreteType);
} else {
return y.value();
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
@Override
public Object map(YObject y, Class<?> type) {
final Map<String, YObject> source = y.asMap();
final Map<String, Object> target = new LinkedHashMap<>(source.size());
for (Map.Entry<String, YObject> entry : source.entrySet()) {
target.put(entry.getKey(), entry.getValue().map(Object.class));
}
return target;
}
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public <T> T map(Class<? extends T> type) {
return context.map(value(), type);
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
@Override
public Object map(YObject y, Class<?> type) {
final Constructor<?> constr;
try {
constr = getConstructor(type);
} catch (NoSuchMethodException | SecurityException e) {
throw new NoSuitableConstructorException("Class " + type.getName() + " does not have a suitable constructor", e);
}
final Object[] args = new Object[constr.getParameterCount()];
final Parameter[] params = constr.getParameters();
for (int i = 0; i < params.length; i++) {
final YInject inj = params[i].getAnnotation(YInject.class);
final Class<?> t = inj.type() != Void.class ? inj.type() : params[i].getType();
if (inj.name().isEmpty()) {
throw new NoNameSpecifiedException("No name specified for attribute of type " + t.getName());
}
final Class<? extends TypeMapper> mapperType = inj.mapper() != NullMapper.class ? inj.mapper() : null;
args[i] = y.getAttribute(inj.name()).map(t, mapperType);
}
final Object target;
try {
target = constr.newInstance(args);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new ObjectInstantiationException("Error instantiating " + type.getName(), e);
}
return y.mapReflectively(target);
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public <T> T map(Object dom, Class<? extends T> type, Class<? extends TypeMapper> mapperType) {
if (dom instanceof YObject) throw new IllegalArgumentException("Cannot map an instance of " + YObject.class.getSimpleName());
if (dom == null) return null;
if (type.isArray()) {
final Class<?> componentType = type.getComponentType();
final List<?> items = (List<?>) dom;
final List<Object> list = new ArrayList<>(items.size());
for (Object i : items) {
list.add(new YObject(i, this).map(componentType));
}
final Object[] array = MappingContext.cast(Array.newInstance(componentType, list.size()));
return cast(list.toArray(array));
} else if (type.isEnum()) {
return cast(Enum.valueOf(cast(type), String.valueOf(dom)));
} else {
final TypeMapper mapper = getMapper(type, mapperType);
final YObject y = new YObject(dom, this);
return cast(mapper.map(y, type));
}
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
final Class<?> type = inj.type() != Void.class ? inj.type() : field.getType();
final Class<? extends TypeMapper> mapperType = inj.mapper() != NullMapper.class ? inj.mapper() : null;
final Object value = getAttribute(name).map(type, mapperType);
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public YObject fromString(String str) throws IOException {
ensureParser();
final Object root = parser.load(new StringReader(str));
return new YObject(root, this);
}
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public YObject then(Consumer<YObject> consumer) {
if (! y.isNull()) {
consumer.accept(y);
}
return YObject.this;
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public YConditional when(String att) {
return new YConditional(getAttribute(att));
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
@Override
public Object map(YObject y, Class<?> type) {
final Map<String, YObject> source = y.asMap();
final Properties target = new Properties();
for (Map.Entry<String, YObject> entry : source.entrySet()) {
target.setProperty(entry.getKey(), entry.getValue().map(String.class));
}
return target;
}
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public <T> T map(Class<? extends T> type, Class<? extends TypeMapper> mapperType) {
return context.map(value(), type, mapperType);
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public Map<String, YObject> asMap() {
checkNotNull();
final Map<?, ?> items = (Map<?, ?>) dom;
final Map<String, YObject> map = new LinkedHashMap<>(items.size());
for (Map.Entry<?, ?> i : items.entrySet()) {
final String key = (String) i.getKey();
if (key.equals(context.getRuntimeMapper().getTypeAttribute())) continue;
map.put(key, new YObject(i.getValue(), context));
}
return map;
}
代码示例来源:origin: com.obsidiandynamics.yconf/yconf-core
public YObject fromStream(InputStream stream) throws IOException {
try (InputStream s = stream) {
ensureParser();
final Object root = parser.load(new InputStreamReader(stream));
return new YObject(root, this);
}
}
内容来源于网络,如有侵权,请联系作者删除!