当前位置: 首页>>代码示例>>Java>>正文


Java NamedParameterNode类代码示例

本文整理汇总了Java中org.apache.reef.tang.types.NamedParameterNode的典型用法代码示例。如果您正苦于以下问题:Java NamedParameterNode类的具体用法?Java NamedParameterNode怎么用?Java NamedParameterNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NamedParameterNode类属于org.apache.reef.tang.types包,在下文中一共展示了NamedParameterNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractParameterConf

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
/**
 * Extracts configuration which is only related to {@code parameterClassList} from {@code totalConf}.
 */
public static Configuration extractParameterConf(final List<Class<? extends Name<?>>> parameterClassList,
                                                 final Configuration totalConf) {
  final ClassHierarchy totalConfClassHierarchy = totalConf.getClassHierarchy();
  final JavaConfigurationBuilder parameterConfBuilder = Tang.Factory.getTang().newConfigurationBuilder();
  for (final Class<? extends Name<?>> parameterClass : parameterClassList) {
    final NamedParameterNode parameterNode
        = (NamedParameterNode) totalConfClassHierarchy.getNode(parameterClass.getName());
    final String parameterValue = totalConf.getNamedParameter(parameterNode);
    // if this parameter is not included in the total configuration, parameterValue will be null
    if (parameterValue != null) {
      parameterConfBuilder.bindNamedParameter(parameterClass, parameterValue);
    }
  }
  return parameterConfBuilder.build();
}
 
开发者ID:snuspl,项目名称:cruise,代码行数:19,代码来源:ConfigurationUtils.java

示例2: registerShortNameOfClass

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
public CommandLine registerShortNameOfClass(final String s) throws BindException {

    final Node n;
    try {
      n = conf.getClassHierarchy().getNode(s);
    } catch (final NameResolutionException e) {
      throw new BindException("Problem loading class " + s, e);
    }

    if (n instanceof NamedParameterNode) {
      final NamedParameterNode<?> np = (NamedParameterNode<?>) n;
      final String shortName = np.getShortName();
      final String longName = np.getFullName();
      if (shortName == null) {
        throw new BindException(
            "Can't register non-existent short name of named parameter: " + longName);
      }
      shortNames.put(shortName, longName);
    } else {
      throw new BindException("Can't register short name for non-NamedParameterNode: " + n);
    }

    return this;
  }
 
开发者ID:apache,项目名称:reef,代码行数:25,代码来源:CommandLine.java

示例3: visit

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
/**
 * Process current configuration node for the named parameter.
 *
 * @param node Current configuration node.
 * @return true to proceed with the next node, false to cancel.
 */
@Override
public boolean visit(final NamedParameterNode<?> node) {
  this.graphStr
      .append("  ")
      .append(node.getName())
      .append(" [label=\"")
      .append(node.getSimpleArgName())           // parameter type, e.g. "Integer"
      .append("\\n")
      .append(node.getName())                    // short name, e.g. "NumberOfThreads"
      .append(" = ")
      .append(config.getNamedParameter(node))   // bound value, e.g. "16"
      .append("\\n(default = ")
      .append(instancesToString(node.getDefaultInstanceAsStrings())) // default value, e.g. "4"
      .append(")\", shape=oval];\n");
  return true;
}
 
开发者ID:apache,项目名称:reef,代码行数:23,代码来源:GraphvizConfigVisitor.java

示例4: bindNamedParameter

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
@Override
public JavaConfigurationBuilder bindNamedParameter(final Class<? extends Name<?>> name, final String value)
    throws BindException {
  if (value == null) {
    throw new IllegalStateException("The value null set to the named parameter is illegal: " + name);
  }
  final Node np = getNode(name);
  if (np instanceof NamedParameterNode) {
    super.bindParameter((NamedParameterNode<?>) np, value);
    return this;
  } else {
    throw new BindException(
        "Detected type mismatch when setting named parameter " + name
            + "  Expected NamedParameterNode, but namespace contains a " + np);
  }
}
 
开发者ID:apache,项目名称:reef,代码行数:17,代码来源:JavaConfigurationBuilderImpl.java

示例5: bindSetEntry

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
@SuppressWarnings("unchecked")
  @Override
  public <T> JavaConfigurationBuilder bindSetEntry(final Class<? extends Name<Set<T>>> iface, final String value)
      throws BindException {
    final Node n = getNode(iface);

    if (!(n instanceof NamedParameterNode)) {
      throw new BindException("BindSetEntry got an interface that resolved to " + n + "; expected a NamedParameter");
    }
    final Type setType = ReflectionUtilities.getInterfaceTarget(Name.class, iface);
    if (!ReflectionUtilities.getRawClass(setType).equals(Set.class)) {
      throw new BindException("BindSetEntry got a NamedParameter that takes a " + setType + "; expected Set<...>");
    }
//    Type valType = ReflectionUtilities.getInterfaceTarget(Set.class, setType);
    super.bindSetEntry((NamedParameterNode<Set<T>>) n, value);
    return this;
  }
 
开发者ID:apache,项目名称:reef,代码行数:18,代码来源:JavaConfigurationBuilderImpl.java

示例6: testBindFromString

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testBindFromString() throws BindException, InjectionException, IOException {
  final JavaConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
  b.bindNamedParameter(IdName.class, "b://b");

  final Configuration c = b.build();
  final String s = avroSerializer.toString(c);

  final JavaConfigurationBuilder b2 = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
  avroSerializer.configurationBuilderFromString(s, b2);
  final Configuration c2 = b2.build();

  Assert.assertEquals("b://b", c2.getNamedParameter(
      (NamedParameterNode<?>) c2.getClassHierarchy().getNode(ReflectionUtilities.getFullName(IdName.class))));
  final Injector i = Tang.Factory.getTang().newInjector(c2);

  Assert.assertEquals("b://b", i.getNamedInstance(IdName.class).toString());
  Assert.assertTrue(i.getNamedInstance(IdName.class) instanceof BIdentifier);

}
 
开发者ID:apache,项目名称:reef,代码行数:22,代码来源:TestImplicitConversions.java

示例7: testBindSubclassFromString

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testBindSubclassFromString() throws BindException, InjectionException, IOException {
  final JavaConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
  b.bindNamedParameter(AIdName.class, "a://a");
  b.bindNamedParameter(BIdName.class, "b://b");

  final Configuration c = b.build();
  final String s = avroSerializer.toString(c);

  final JavaConfigurationBuilder b2 = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
  avroSerializer.configurationBuilderFromString(s, b2);
  final Configuration c2 = b2.build();

  Assert.assertEquals("b://b", c2.getNamedParameter(
      (NamedParameterNode<?>) c2.getClassHierarchy().getNode(ReflectionUtilities.getFullName(BIdName.class))));
  final Injector i = Tang.Factory.getTang().newInjector(c2);

  Assert.assertEquals("b://b", i.getNamedInstance(BIdName.class).toString());
  Assert.assertTrue(i.getNamedInstance(BIdName.class) instanceof BIdentifier);
  Assert.assertEquals("a://a", i.getNamedInstance(AIdName.class).toString());
  Assert.assertTrue(i.getNamedInstance(AIdName.class) instanceof AIdentifier);
}
 
开发者ID:apache,项目名称:reef,代码行数:24,代码来源:TestImplicitConversions.java

示例8: testStringInjectConfigurationBuilder

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
/**
 * Test code for injecting list of strings with ConfigurationBuilder.
 *
 * @throws InjectionException
 */
@Test
public void testStringInjectConfigurationBuilder() throws InjectionException {
  final JavaClassHierarchy namespace = Tang.Factory.getTang().getDefaultClassHierarchy();
  final NamedParameterNode<List<String>> np = (NamedParameterNode) namespace.getNode(StringList.class);
  final List<String> injected = new ArrayList<>();
  injected.add("hi");
  injected.add("hello");
  injected.add("bye");

  final ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
  cb.bindList(np, injected);
  final List<String> actual = 
      Tang.Factory.getTang().newInjector(cb.build()).getInstance(StringClass.class).getStringList();
  final List<String> expected = new ArrayList<>();
  expected.add("hi");
  expected.add("hello");
  expected.add("bye");
  Assert.assertEquals(expected, actual);
}
 
开发者ID:apache,项目名称:reef,代码行数:25,代码来源:TestListInjection.java

示例9: testObjectInjectConfigurationBuilder

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
/**
 * Test code for injecting list of implementations with ConfigurationBuilder.
 *
 * @throws InjectionException
 */
@Test
public void testObjectInjectConfigurationBuilder() throws InjectionException {
  final Integer integer = 1;
  final Float ffloat = 1.001f;

  final JavaClassHierarchy namespace = Tang.Factory.getTang().getDefaultClassHierarchy();
  final NamedParameterNode<List<Class>> np = (NamedParameterNode) namespace.getNode(NumberList.class);
  final List<ClassNode> injected = new ArrayList<>();
  injected.add((ClassNode) namespace.getNode(Integer.class));
  injected.add((ClassNode) namespace.getNode(Float.class));

  final ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
  cb.bindList(np, injected);

  final Injector injector = Tang.Factory.getTang().newInjector(cb.build());
  injector.bindVolatileInstance(Integer.class, integer);
  injector.bindVolatileInstance(Float.class, ffloat);
  final List<Number> actual = injector.getInstance(NumberClass.class).getNumberList();
  final List<Number> expected = new ArrayList<>();
  expected.add(integer);
  expected.add(ffloat);
  Assert.assertEquals(expected, actual);
}
 
开发者ID:apache,项目名称:reef,代码行数:29,代码来源:TestListInjection.java

示例10: testBindSetEntryWithSetOfT

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
@Test
// Test bindSetEntry(NamedParameterNode<Set<T>> iface, String impl) in ConfigurationBuilderImpl
// with deserialized class hierarchy
public void testBindSetEntryWithSetOfT() throws IOException {
  final ClassHierarchy ns1 = Tang.Factory.getTang().getDefaultClassHierarchy();
  ns1.getNode(SetOfClasses.class.getName());
  final ClassHierarchy ns2 = classHierarchySerializer.fromString(classHierarchySerializer.toString(ns1));
  final ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder(ns2);

  final NamedParameterNode<Set<Number>> n2 =
      (NamedParameterNode<Set<Number>>) ns1.getNode(SetOfClasses.class.getName());
  final Node fn = ns1.getNode(Float.class.getName());
  cb.bindSetEntry(n2, fn);

  final Configuration c = configurationSerializer.fromString(configurationSerializer.toString(cb.build()), ns2);
}
 
开发者ID:apache,项目名称:reef,代码行数:17,代码来源:ClassHierarchyDeserializationTest.java

示例11: testBindSetEntryWithSetOfString

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
@Test
// Test public <T> void bindParameter(NamedParameterNode<T> name, String value) in ConfigurationBuilderImpl
// with deserialized class hierarchy
public void testBindSetEntryWithSetOfString() throws IOException {
  final ClassHierarchy ns1 = Tang.Factory.getTang().getDefaultClassHierarchy();
  ns1.getNode(SetOfStrings.class.getName());
  final ClassHierarchy ns2 = classHierarchySerializer.fromString(classHierarchySerializer.toString(ns1));
  final ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder(ns2);
  cb.bindSetEntry(SetOfStrings.class.getName(), "four");
  cb.bindSetEntry(SetOfStrings.class.getName(), "five");

  final NamedParameterNode<Set<String>> n2 =
      (NamedParameterNode<Set<String>>) ns1.getNode(SetOfStrings.class.getName());
  cb.bindSetEntry(n2, "six");

  final Configuration c = configurationSerializer.fromString(configurationSerializer.toString(cb.build()), ns2);
}
 
开发者ID:apache,项目名称:reef,代码行数:18,代码来源:ClassHierarchyDeserializationTest.java

示例12: createContextConfigCreatesForGivenWorkerId

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
@Test
public void createContextConfigCreatesForGivenWorkerId() {
  Configuration config = driver.createContextConfig(4);
  boolean found = false;
  for (NamedParameterNode<?> namedParameterNode : config.getNamedParameters()) {
    if (namedParameterNode.getName().equals(ContextIdentifier.class.getSimpleName())) {
      Assert.assertEquals("4", config.getNamedParameter(namedParameterNode));
      found = true;
    }
  }
  assertTrue("ContextIdentifier didn't exist.", found);
}
 
开发者ID:twitter,项目名称:heron,代码行数:13,代码来源:HeronMasterDriverTest.java

示例13: getBoundNamedParameters

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
public Set<NamedParameterNode<?>> getBoundNamedParameters() {
  final Configuration c = this.builder.b.build();
  final Set<NamedParameterNode<?>> nps = new MonotonicSet<>();
  nps.addAll(c.getNamedParameters());
  for (final Class<?> np : this.builder.freeParams.keySet()) {
    try {
      nps.add((NamedParameterNode<?>) builder.b.getClassHierarchy().getNode(ReflectionUtilities.getFullName(np)));
    } catch (final NameResolutionException e) {
      throw new IllegalStateException(e);
    }
  }
  return nps;
}
 
开发者ID:apache,项目名称:reef,代码行数:14,代码来源:ConfigurationModule.java

示例14: visit

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
/**
 * Manually dispatch between different types of Nodes and call a proper visit() method.
 * Currently dispatches between ClassNode, PackageNode, and NamedParameterNode types.
 *
 * @param node TANG configuration node.
 * @return true to proceed with the next node, false to cancel.
 * @throws ClassCastException if Node is not one of ClassNode, PackageNode,
 *                            or NamedParameterNode.
 */
@Override
public boolean visit(final Node node) {
  if (node instanceof ClassNode) {
    return visit((ClassNode<?>) node);
  } else if (node instanceof PackageNode) {
    return visit((PackageNode) node);
  } else if (node instanceof NamedParameterNode) {
    return visit((NamedParameterNode<?>) node);
  }
  throw new ClassCastException(
      "Node " + node.getClass() + " cannot be casted to one of the known subclasses."
          + " Override this method to handle the case.");
}
 
开发者ID:apache,项目名称:reef,代码行数:23,代码来源:AbstractClassHierarchyNodeVisitor.java

示例15: bindList

import org.apache.reef.tang.types.NamedParameterNode; //导入依赖的package包/类
/**
 * Binding list method for JavaConfigurationBuilder. It checks the type of a given named parameter,
 * and whether all the list's elements can be applied to the named parameter. The elements' type
 * should be either java Class or String.
 * <p>
 * It does not check whether the list's String values can be parsed to T, like bindSetEntry.
 *
 * @param iface    target named parameter to be instantiated
 * @param implList implementation list used to instantiate the named parameter
 * @param <T>      type of the list
 * @return bound JavaConfigurationBuilder object
 * @throws BindException
 */
@SuppressWarnings("unchecked")
@Override
public <T> JavaConfigurationBuilder bindList(final Class<? extends Name<List<T>>> iface, final List implList)
    throws BindException {
  final Node n = getNode(iface);
  final List<Object> result = new ArrayList<>();

  if (!(n instanceof NamedParameterNode)) {
    throw new BindException("BindList got an interface that resolved to " + n + "; expected a NamedParameter");
  }
  final Type listType = ReflectionUtilities.getInterfaceTarget(Name.class, iface);
  if (!ReflectionUtilities.getRawClass(listType).equals(List.class)) {
    throw new BindException("BindList got a NamedParameter that takes a " + listType + "; expected List<...>");
  }
  if (!implList.isEmpty()) {
    final Type valType = ReflectionUtilities.getInterfaceTarget(List.class, listType);
    for (final Object item : implList) {
      if (item instanceof Class) {
        if (!ReflectionUtilities.getRawClass(valType).isAssignableFrom((Class) item)) {
          throw new BindException("BindList got a list element which is not assignable to the given Type; " +
              "expected: " + valType);
        }
        result.add(getNode((Class) item));
      } else if (item instanceof String) {
        result.add(item);
      } else {
        throw new BindException("BindList got an list element with unsupported type; expected Class or String " +
            "object");
      }
    }
  }

  super.bindList((NamedParameterNode<List<T>>) n, result);
  return this;
}
 
开发者ID:apache,项目名称:reef,代码行数:49,代码来源:JavaConfigurationBuilderImpl.java


注:本文中的org.apache.reef.tang.types.NamedParameterNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。