gpt4 book ai didi

org.apache.brooklyn.util.yaml.Yamls.getAs()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 13:10:40 27 4
gpt4 key购买 nike

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

Yamls.getAs介绍

[英]returns the given (yaml-parsed) object as the given yaml type.

if the object is an iterable or iterator this method will fully expand it as a list. if the requested type is not an iterable or iterator, and the list contains a single item, this will take that single item.

in other cases this method simply does a type-check and cast (no other type coercion).
[中]将给定的(yaml解析的)对象作为给定的yaml类型返回。
如果对象是一个iterable或iterator,这个方法将把它完全扩展为一个列表。如果请求的类型不是iterable或iterator,并且列表包含单个项,则将采用该单个项。
在其他情况下,此方法只执行类型检查和强制转换(无其他类型强制)。

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

/** simplifies new Yaml().loadAll, and converts to list to prevent single-use iterable bug in yaml */
@SuppressWarnings("unchecked")
public static Iterable<Object> parseAll(String yaml) {
  Iterable<Object> result = newYaml().loadAll(yaml);
  return getAs(result, List.class);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

/** as {@link #parseAll(String)} */
@SuppressWarnings("unchecked")
public static Iterable<Object> parseAll(Reader yaml) {
  Iterable<Object> result = newYaml().loadAll(yaml);
  return getAs(result, List.class);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public static Map<?,?> getCatalogMetadata(String yaml) {
  Map<?,?> itemDef = Yamls.getAs(Yamls.parseAll(yaml), Map.class);
  return getFirstAsMap(itemDef, "brooklyn.catalog").orNull();        
}

代码示例来源:origin: org.apache.brooklyn.camp/camp-base

@SuppressWarnings("unchecked")
public DeploymentPlan parseDeploymentPlan(String yaml) {
  Iterable<Object> template = Yamls.parseAll(yaml);
  
  Map<String, Object> dpRootUninterpreted = null;
  try {
    dpRootUninterpreted = Yamls.getAs(template, Map.class);
  } catch (Exception e) {
    Exceptions.propagateIfFatal(e);
    throw new YAMLException("Plan not in acceptable format: "+(e.getMessage()!=null ? e.getMessage() : ""+e), e);
  }
  Map<String, Object> dpRootInterpreted = applyInterpreters(dpRootUninterpreted);
  
  return DeploymentPlan.of(dpRootInterpreted, yaml);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

@Test
public void testGetAs() throws Exception {
  MutableList<String> list = MutableList.of("x");
  assertEquals(Yamls.getAs(list.iterator(), List.class), list);
  assertEquals(Yamls.getAs(list.iterator(), Iterable.class), list);
  assertEquals(Yamls.getAs(list.iterator(), Iterator.class), list.iterator());
  assertEquals(Yamls.getAs(list.iterator(), String.class), "x");
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

return Yamls.getAs( Yamls.parseAll(input), Map.class );
} catch (Exception e) {
  Exceptions.propagateIfFatal(e);

代码示例来源:origin: org.apache.brooklyn.camp/camp-base

@SuppressWarnings("unchecked")
public void testToyInterpreter() {
  @SuppressWarnings("rawtypes")
  Map y1 = Yamls.getAs( Yamls.parseAll( Streams.reader(getClass().getResourceAsStream("yaml-sample-toy-interpreter.yaml"))), Map.class );
  log.info("pre-interpreter have: "+y1);
  
  BasicCampPlatform p = new BasicCampPlatform();
  p.pdp().addInterpreter(new ToyInterpreter());
  Map<String, Object> y2 = p.pdp().applyInterpreters(y1);
  log.info("interpreter gives: "+y2);
  
  Map<String, Object> y3 = Yamls.getAs( Yamls.parseAll( Streams.reader(getClass().getResourceAsStream("yaml-sample-toy-interpreter-result.yaml"))), Map.class );
  Assert.assertEquals(y2, y3);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

List<CatalogItemDtoAbstract<?, ?>> resultLegacyFormat, Map<RegisteredType, RegisteredType> resultNewFormat, 
  boolean requireValidation, Map<?, ?> parentMeta, int depth, boolean force) {
Map<?,?> itemDef = Yamls.getAs(Yamls.parseAll(yaml), Map.class);
Map<?,?> catalogMetadata = getFirstAsMap(itemDef, "brooklyn.catalog").orNull();
if (catalogMetadata==null)

代码示例来源:origin: org.apache.brooklyn/brooklyn-camp

public Object parseDslExpression(String input) {
  String s1 = Yamls.getAs( Yamls.parseAll( Streams.reader(Streams.newInputStreamWithContents(input)) ), String.class );
  BasicCampPlatform p = new BasicCampPlatform();
  p.pdp().addInterpreter(new BrooklynDslInterpreter());
  Object out = p.pdp().applyInterpreters(MutableMap.of("key", s1)).get("key");
  log.debug("parsed "+input+" as "+out+" ("+(out==null ? "null" : out.getClass())+")");
  return out;
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com