Пример #1
0
 private static <T> void fillWithConstructor(
     @NonNull final CursorGetter getter,
     final List<T> lists,
     final @NonNull Constructor<T> constructor) {
   try {
     while (getter.moveToNext()) {
       lists.add(constructor.newInstance(getter));
     }
   } catch (final InstantiationException e) {
     throw new IllegalArgumentException(
         "go and make the constructor "
             + constructor.getName()
             + "(CursorWrapper.CursorGetter) accessible",
         e);
   } catch (final IllegalAccessException e) {
     throw new IllegalArgumentException(
         "go and make the constructor "
             + constructor.getName()
             + "(CursorWrapper.CursorGetter) accessible",
         e);
   } catch (final InvocationTargetException e) {
     throw new IllegalArgumentException(
         "go and make the constructor "
             + constructor.getName()
             + "(CursorWrapper.CursorGetter) accessible",
         e);
   }
 }
Пример #2
0
 private static <T> void fillWithConvertor(
     @NonNull final CursorGetter getter,
     final List<T> list,
     final CursorWrapper.CursorConverter<T> converter) {
   while (getter.moveToNext()) {
     list.add(converter.convert(getter));
   }
 }
Пример #3
0
 @Override
 public List<T> convert(@NonNull final CursorGetter getter) {
   final List<T> list = new ArrayList<>(getter.getCount());
   if (converter.isLeft()) {
     fillWithConstructor(getter, list, converter.getLeftOrThrow());
   } else if (converter.isRight()) {
     fillWithConvertor(getter, list, converter.getRightOrThrow());
   } else {
     throw new IllegalStateException("Cannot be reached");
   }
   return list;
 }