htFetch method

dynamic htFetch(
  1. String varName
)

Implementation

dynamic htFetch(String varName) {
  switch (varName) {
    case 'nextDouble':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          nextDouble();
    case 'nextInt':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          nextInt(positionalArgs[0].toInt());
    case 'nextBool':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          nextBool();
    case 'nextColorHex':
      return (HTEntity entity,
          {List<dynamic> positionalArgs = const [],
          Map<String, dynamic> namedArgs = const {},
          List<HTType> typeArgs = const []}) {
        var prefix = '#';
        if (namedArgs['hasAlpha']) {
          prefix += 'ff';
        }
        return prefix +
            (nextDouble() * 16777215)
                .truncate()
                .toRadixString(16)
                .padLeft(6, '0');
      };
    case 'nextBrightColorHex':
      return (HTEntity entity,
          {List<dynamic> positionalArgs = const [],
          Map<String, dynamic> namedArgs = const {},
          List<HTType> typeArgs = const []}) {
        var prefix = '#';
        if (namedArgs['hasAlpha']) {
          prefix += 'ff';
        }
        return prefix +
            (nextDouble() * 5592405 + 11184810)
                .truncate()
                .toRadixString(16)
                .padLeft(6, '0');
      };
    case 'nextIterable':
      return (HTEntity entity,
          {List<dynamic> positionalArgs = const [],
          Map<String, dynamic> namedArgs = const {},
          List<HTType> typeArgs = const []}) {
        final iterable = positionalArgs.first as Iterable;
        if (iterable.isNotEmpty) {
          return iterable.elementAt(nextInt(iterable.length));
        } else {
          return null;
        }
      };
    case 'shuffle':
      return (HTEntity entity,
          {List<dynamic> positionalArgs = const [],
          Map<String, dynamic> namedArgs = const {},
          List<HTType> typeArgs = const []}) sync* {
        final Iterable list = positionalArgs.first;
        if (list.isNotEmpty) {
          // ignore: prefer_collection_literals
          final Set indexes = LinkedHashSet();
          int index;
          do {
            do {
              index = nextInt(list.length);
            } while (indexes.contains(index));
            indexes.add(index);
            yield list.elementAt(index);
          } while (indexes.length < list.length);
        }
      };
    default:
      throw HTError.undefined(varName);
  }
}