java.lang.Iterable Java Examples

The following examples show how to use java.lang.Iterable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Find_data_paths.java    From EvilCoder with MIT License 6 votes vote down vote up
public static String member_to_var_name (Object var_name)
{
  if(var_name instanceof Iterable)
   {
   List<String> casted = (List<String>)(var_name);
   String s = "";
     for(int i=0, i_end=casted.size(); i<i_end; ++i)
      {
        if(i > 0)
         {
          s += " -> ";
         }
       s += casted.get(i).replaceAll("* ", "");
      }
    return s;
   }
 else
  {
   return (String)(var_name);
  }
}
 
Example #2
Source File: LinkedHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private static<E> int iterableSize(Iterable<E> iterable) {
    int result = 0;
    for (E element : iterable) {
        result++;
    }
    return result;
}
 
Example #3
Source File: CalculatorAddParameterizedTest.java    From testing-samples with Apache License 2.0 5 votes vote down vote up
/**
 * @return {@link Iterable} that contains the values that should be passed to the constructor.
 * In this example we are going to use three parameters: operand one, operand two and the
 * expected result.
 */
@Parameters
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            {0, 0, 0},
            {0, -1, -1},
            {2, 2, 4},
            {8, 8, 16},
            {16, 16, 32},
            {32, 0, 32},
            {64, 64, 128}});
}
 
Example #4
Source File: CalculatorAddParameterizedTest.java    From testing-samples with Apache License 2.0 5 votes vote down vote up
/**
 * @return {@link Iterable} that contains the values that should be passed to the constructor.
 * In this example we are going to use three parameters: operand one, operand two and the
 * expected result.
 */
@Parameters
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            {0, 0, 0},
            {0, -1, -1},
            {2, 2, 4},
            {8, 8, 16},
            {16, 16, 32},
            {32, 0, 32},
            {64, 64, 128}});
}
 
Example #5
Source File: MovieAPIHashIndex.java    From hollow-reference-implementation with Apache License 2.0 5 votes vote down vote up
public Iterable<Movie> findMovieMatches(Object... keys) {
    HollowHashIndexResult matches = idx.findMatches(keys);
    if(matches == null)
        return Collections.emptySet();

    final HollowOrdinalIterator iter = matches.iterator();

    return new Iterable<Movie>() {
        public Iterator<Movie> iterator() {
            return new Iterator<Movie>() {

                private int next = iter.next();

                public boolean hasNext() {
                    return next != HollowOrdinalIterator.NO_MORE_ORDINALS;
                }

                public Movie next() {
                    Movie obj = api.getMovie(next);
                    next = iter.next();
                    return obj;
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
 
Example #6
Source File: ElementFilter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private static <E extends Element> List<E> listFilter(Iterable<? extends Element> elements,
                                                      Set<ElementKind> targetKinds,
                                                      Class<E> clazz) {
    List<E> list = new ArrayList<E>();
    for (Element e : elements) {
        if (targetKinds.contains(e.getKind()))
            list.add(clazz.cast(e));
    }
    return list;
}
 
Example #7
Source File: MovieAPIHashIndex.java    From hollow-reference-implementation with Apache License 2.0 5 votes vote down vote up
public Iterable<SetOfActor> findSetOfActorMatches(Object... keys) {
    HollowHashIndexResult matches = idx.findMatches(keys);
    if(matches == null)
        return Collections.emptySet();

    final HollowOrdinalIterator iter = matches.iterator();

    return new Iterable<SetOfActor>() {
        public Iterator<SetOfActor> iterator() {
            return new Iterator<SetOfActor>() {

                private int next = iter.next();

                public boolean hasNext() {
                    return next != HollowOrdinalIterator.NO_MORE_ORDINALS;
                }

                public SetOfActor next() {
                    SetOfActor obj = api.getSetOfActor(next);
                    next = iter.next();
                    return obj;
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
 
Example #8
Source File: MovieAPIHashIndex.java    From hollow-reference-implementation with Apache License 2.0 5 votes vote down vote up
public Iterable<Actor> findActorMatches(Object... keys) {
    HollowHashIndexResult matches = idx.findMatches(keys);
    if(matches == null)
        return Collections.emptySet();

    final HollowOrdinalIterator iter = matches.iterator();

    return new Iterable<Actor>() {
        public Iterator<Actor> iterator() {
            return new Iterator<Actor>() {

                private int next = iter.next();

                public boolean hasNext() {
                    return next != HollowOrdinalIterator.NO_MORE_ORDINALS;
                }

                public Actor next() {
                    Actor obj = api.getActor(next);
                    next = iter.next();
                    return obj;
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
 
Example #9
Source File: MovieAPIHashIndex.java    From hollow-reference-implementation with Apache License 2.0 5 votes vote down vote up
public Iterable<HString> findStringMatches(Object... keys) {
    HollowHashIndexResult matches = idx.findMatches(keys);
    if(matches == null)
        return Collections.emptySet();

    final HollowOrdinalIterator iter = matches.iterator();

    return new Iterable<HString>() {
        public Iterator<HString> iterator() {
            return new Iterator<HString>() {

                private int next = iter.next();

                public boolean hasNext() {
                    return next != HollowOrdinalIterator.NO_MORE_ORDINALS;
                }

                public HString next() {
                    HString obj = api.getHString(next);
                    next = iter.next();
                    return obj;
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
 
Example #10
Source File: ElementFilter.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private static <E extends Element> List<E> listFilter(Iterable<? extends Element> elements,
                                                      Set<ElementKind> targetKinds,
                                                      Class<E> clazz) {
    List<E> list = new ArrayList<E>();
    for (Element e : elements) {
        if (targetKinds.contains(e.getKind()))
            list.add(clazz.cast(e));
    }
    return list;
}
 
Example #11
Source File: ElementFilter.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a list of types in {@code elements}.
 * @return a list of types in {@code elements}
 * @param elements the elements to filter
 */
public static List<TypeElement>
        typesIn(Iterable<? extends Element> elements) {
    return listFilter(elements, TYPE_KINDS, TypeElement.class);
}
 
Example #12
Source File: ElementFilter.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a list of packages in {@code elements}.
 * @return a list of packages in {@code elements}
 * @param elements the elements to filter
 */
public static List<PackageElement>
        packagesIn(Iterable<? extends Element> elements) {
    return listFilter(elements, PACKAGE_KIND, PackageElement.class);
}
 
Example #13
Source File: ElementFilter.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a list of fields in {@code elements}.
 * @return a list of fields in {@code elements}
 * @param elements the elements to filter
 */
public static List<VariableElement>
        fieldsIn(Iterable<? extends Element> elements) {
    return listFilter(elements, FIELD_KINDS, VariableElement.class);
}
 
Example #14
Source File: ElementFilter.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a list of methods in {@code elements}.
 * @return a list of methods in {@code elements}
 * @param elements the elements to filter
 */
public static List<ExecutableElement>
        methodsIn(Iterable<? extends Element> elements) {
    return listFilter(elements, METHOD_KIND, ExecutableElement.class);
}
 
Example #15
Source File: ElementFilter.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a list of constructors in {@code elements}.
 * @return a list of constructors in {@code elements}
 * @param elements the elements to filter
 */
public static List<ExecutableElement>
        constructorsIn(Iterable<? extends Element> elements) {
    return listFilter(elements, CONSTRUCTOR_KIND, ExecutableElement.class);
}
 
Example #16
Source File: ElementFilter.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a list of fields in {@code elements}.
 * @return a list of fields in {@code elements}
 * @param elements the elements to filter
 */
public static List<VariableElement>
        fieldsIn(Iterable<? extends Element> elements) {
    return listFilter(elements, FIELD_KINDS, VariableElement.class);
}
 
Example #17
Source File: ElementFilter.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a list of packages in {@code elements}.
 * @return a list of packages in {@code elements}
 * @param elements the elements to filter
 */
public static List<PackageElement>
        packagesIn(Iterable<? extends Element> elements) {
    return listFilter(elements, PACKAGE_KIND, PackageElement.class);
}
 
Example #18
Source File: ElementFilter.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a list of types in {@code elements}.
 * @return a list of types in {@code elements}
 * @param elements the elements to filter
 */
public static List<TypeElement>
        typesIn(Iterable<? extends Element> elements) {
    return listFilter(elements, TYPE_KINDS, TypeElement.class);
}
 
Example #19
Source File: ElementFilter.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a list of methods in {@code elements}.
 * @return a list of methods in {@code elements}
 * @param elements the elements to filter
 */
public static List<ExecutableElement>
        methodsIn(Iterable<? extends Element> elements) {
    return listFilter(elements, METHOD_KIND, ExecutableElement.class);
}
 
Example #20
Source File: ElementFilter.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a list of constructors in {@code elements}.
 * @return a list of constructors in {@code elements}
 * @param elements the elements to filter
 */
public static List<ExecutableElement>
        constructorsIn(Iterable<? extends Element> elements) {
    return listFilter(elements, CONSTRUCTOR_KIND, ExecutableElement.class);
}