検証対象の値が、指定したクラスを継承しているかどうか検証する。

@since 2.0
@param arg 検証対象の値
@param clazz 親クラス
@param name 検証対象の引数の名前
497311
public static void instanceOf(final Object arg, final Class<?> clazz, final String name) {
        
        if(arg == null) {
            throw new IllegalArgumentException(String.format("%s should not be null.", name));
        }
        
        if(!clazz.isAssignableFrom(arg.getClass())) {
            throw new IllegalArgumentException(String.format("%s should not be class with '%s'.", name, clazz.getName()));
        }
        
    }
1110966
public static void notEmpty(final String arg, final String name) {
        if(arg == null) {
            throw new NullPointerException(String.format("%s should not be null.", name));
        }
        
        if(arg.isEmpty()) {
            throw new IllegalArgumentException(String.format("%s should not be empty.", name));
        }
    }
1291701
public Object invokeMethod(String name, Object args) {
        try {
            return super.invokeMethod(name, args);
        }
        // if the method was not found in the current scope (the script's methods)
        // let's try to see if there's a method closure with the same name in the binding
        catch (MissingMethodException mme) {
            try {
                if (name.equals(mme.getMethod())) {
                    Object boundClosure = getProperty(name);
                    if (boundClosure != null && boundClosure instanceof Closure) {
                        return ((Closure) boundClosure).call((Object[])args);
                    } else {
                        throw mme;
                    }
                } else {
                    throw mme;
                }
            } catch (MissingPropertyException mpe) {
                throw mme;
            }
        }
    }
52500
public static void isNotEmpty( String argument,
                                   String name ) {
        isNotZeroLength(argument, name);
        if (argument != null && argument.trim().length() == 0) {
            throw new IllegalArgumentException(CommonI18n.argumentMayNotBeNullOrZeroLengthOrEmpty.text(name));
        }
    }
532178
static
	public void putFunction(String name, Class<? extends Function> functionClazz){
		FunctionRegistry.functionClazzes.put(Objects.requireNonNull(name), checkClass(functionClazz));
	}
742634
private function _checkArgument($argument, $name)
    {
        if (!is_string($argument)) {
            $argument = strval($argument);
        }

        if (strlen($argument) == 0) {
            throw new Klarna_ArgumentNotSetException($name);
        }
    }
990631
public static void notNull(final Object arg, final String name) {
        if(arg == null) {
            throw new IllegalArgumentException(String.format("%s should not be null.", name));
        }
    }
62149
public static <T> NamedParameterNode<T> createNamedParameterNode(final Node parent,
                                                                   final Class<? extends Name<T>> clazz,
                                                                   final Type argClass)
      throws ClassHierarchyException {

    Class<?> argRawClass = ReflectionUtilities.getRawClass(argClass);

    final boolean isSet = argRawClass.equals(Set.class);
    final boolean isList = argRawClass.equals(List.class);

    final Type argClazz;

    if (isSet || isList) {
      argClazz = ReflectionUtilities.getInterfaceTarget(Collection.class, argClass);
    } else {
      argClazz = argClass;
    }

    final String simpleName = ReflectionUtilities.getSimpleName(clazz);
    final String fullName = ReflectionUtilities.getFullName(clazz);
    final String fullArgName = ReflectionUtilities.getFullName(argClazz);
    final String simpleArgName = ReflectionUtilities.getSimpleName(argClazz);


    final NamedParameter namedParameter = clazz.getAnnotation(NamedParameter.class);

    if (namedParameter == null) {
      throw new IllegalStateException("Got name without named parameter post-validation!");
    }
    final boolean hasStringDefault, hasClassDefault, hasStringSetDefault, hasClassSetDefault;

    int defaultCount = 0;
    if (namedParameter.default_value().equals(NamedParameter.REEF_UNINITIALIZED_VALUE)) {
      hasStringDefault = false;
    } else {
      hasStringDefault = true;
      defaultCount++;
    }
    if (namedParameter.default_class() != Void.class) {
      hasClassDefault = true;
      defaultCount++;
    } else {
      hasClassDefault = false;
    }
    if (namedParameter.default_values() != null && namedParameter.default_values().length > 0) {
      hasStringSetDefault = true;
      defaultCount++;
    } else {
      hasStringSetDefault = false;
    }
    if (namedParameter.default_classes() != null && namedParameter.default_classes().length > 0) {
      hasClassSetDefault = true;
      defaultCount++;
    } else {
      hasClassSetDefault = false;
    }
    if (defaultCount > 1) {
      throw new ClassHierarchyException("Named parameter " + fullName +
          " defines more than one of default_value, default_class, default_values and default_classes");
    }

    final String[] defaultInstanceAsStrings;

    if (defaultCount == 0) {
      defaultInstanceAsStrings = new String[]{};
    } else if (hasClassDefault) {
      final Class<?> defaultClass = namedParameter.default_class();
      assertIsSubclassOf(clazz, defaultClass, argClazz);
      defaultInstanceAsStrings = new String[]{ReflectionUtilities.getFullName(defaultClass)};
    } else if (hasStringDefault) {
      // Don't know if the string is a class or literal here, so don't bother validating.
      defaultInstanceAsStrings = new String[]{namedParameter.default_value()};
    } else if (hasClassSetDefault) {
      final Class<?>[] clzs = namedParameter.default_classes();
      defaultInstanceAsStrings = new String[clzs.length];
      for (int i = 0; i < clzs.length; i++) {
        assertIsSubclassOf(clazz, clzs[i], argClazz);
        defaultInstanceAsStrings[i] = ReflectionUtilities.getFullName(clzs[i]);
      }
    } else if (hasStringSetDefault) {
      defaultInstanceAsStrings = namedParameter.default_values();
    } else {
      throw new IllegalStateException("The named parameter " + namedParameter.short_name() + " has a default value,"
              + " but the value cannot be retrieved. The defaultCount is " + defaultCount
              + ", but hasClassDefault, hasStringDefault, hasClassSetDefault, hasStringSetDefault"
              + " conditions are all false");
    }

    final String documentation = namedParameter.doc();

    final String shortName = namedParameter.short_name().isEmpty()
        ? null : namedParameter.short_name();

    return new NamedParameterNodeImpl<>(parent, simpleName, fullName,
        fullArgName, simpleArgName, isSet, isList, documentation, shortName, defaultInstanceAsStrings);
  }
1124428
public function callMacro(string $name, array $args)
    {
        if (isset($this->macros[$name])) {
            return call_user_func_array($this->macros[$name], $args);
        }
        throw new RuntimeException('There is no macro with the given name "'.$name.'" to call');
    }
74406
public static Field forName(Class cl, String name) {
        java.lang.reflect.Field result;

        try {
            result = cl.getDeclaredField(name);
        } catch (NoSuchFieldException e) {
            return null;
        }

        return create(result);
    }
831975
public static Name getArgumentAsName(Object arg) {
        if (arg instanceof String) {
            return LdapUtils.newLdapName((String) arg);
        } else if (arg instanceof Name) {
            return (Name) arg;
        } else {
            throw new IllegalArgumentException(
                    "First argument needs to be a Name or a String representation thereof");
        }
    }
69516
public IRMethodCallExpressionBuilder call(String name, IRExpressionBuilder... args) {
    return call(name, Arrays.asList(args));  
  }
818354
public static String generatedNameOf(Class<?> clazz, String name)
    {
        return builder(clazz, name).build();
    }
514305
public static String generatedNameOf(Class<?> clazz, Named named)
    {
        return builder(clazz, named).build();
    }
702915
public void dispatchMethod (String name, Object[] arguments)
    {
        // first check the cache
        Method method = _mcache.get(name);
        if (method == null) {
            // if we haven't already determined this method doesn't exist, try
            // to resolve it
            if (!_mcache.containsKey(name)) {
                _mcache.put(name, method = resolveMethod(name, arguments));
            }
        }
        if (method != null) {
            try {
                method.invoke(_target, arguments);
            } catch (Exception e) {
                log.warning("Failed to dispatch event callback " +
                    name + "(" + StringUtil.toString(arguments) + ").", e);
            }
        }
    }
1040964
public static Method bestMethod(Class<?> clazz, String name, Object[] args) throws AmbiguousMethodMatchException {
        return bestMethod(collectMethods(clazz, name), args);
    }
1358406
public void cli(String[] args) {
        CommandLineParser cli = new CommandLineParser();
        cli.addOption(NamedOption.builder()
                .name("data")
                .description("Data to use for training or testing")
                .required(true)
                .type(Resource.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("format")
                .description("Format for reading data")
                .defaultValue("JSON_OPL")
                .type(String.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("corpusType")
                .description("Type of corpus to create (e.g. in-memory)")
                .defaultValue("IN_MEMORY")
                .type(CorpusType.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("mode")
                .description("Train/Test/Split")
                .defaultValue("TEST")
                .type(Mode.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("model")
                .description("Model to save/load")
                .type(Resource.class)
                .required(true)
                .build());
        cli.addOption(NamedOption.builder()
                .name("undersample")
                .description("Undersample")
                .type(Boolean.class)
                .required(false)
                .defaultValue(false)
                .build());
        cli.addOption(NamedOption.builder()
                .name("oversample")
                .description("Oversample")
                .type(Boolean.class)
                .required(false)
                .defaultValue(false)
                .build());
        cli.parse(args);
        Hermes.initializeApplication(args);

        Dataset<Instance> data = getDataset(cli.get("data"), cli.get("format"), cli.get("corpusType"),
                cli.get("undersample"),
                cli.get("oversample"));

        Mode mode = cli.get("mode");
        switch (mode) {
            case TEST:
                try {
                    this.classifier = Cast.<BasicTextClassifier>as(TextClassifier.read(cli.get("model"))).classifier;
                } catch (Exception e) {
                    throw Throwables.propagate(e);
                }
                test(data);
                break;
            case SPLIT:
                TrainTestSplit<Instance> split = Iterables.getFirst(data.split(0.8), null);
                train(split.getTrain());
                test(split.getTest());
                break;
            case TRAIN:
                train(data);
                try {
                    write(cli.get("model"));
                } catch (Exception e) {
                    throw Throwables.propagate(e);
                }
                break;
            case CV3:
            case CV10:
                TrainTestSet<Instance> folds = data.fold(mode == Mode.CV3 ? 3 : 10);
                ClassifierEvaluation evaluation = new ClassifierEvaluation();
                for (TrainTestSplit<Instance> fold : folds) {
                    train(fold.getTrain());
                    evaluation.merge(test(fold.getTest(), false));
                }
                evaluation.output(System.out);
                break;
            default:
                System.err.println("Unknown option");
        }
    }