scala.collection.Iterable Java Examples

The following examples show how to use scala.collection.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: ScalaPrimitiveTypeListOfListSerializer.java    From beakerx with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canBeUsed(Object obj, boolean expand) {
  if (!expand)
    return false;

  if (!(obj instanceof scala.collection.immutable.Seq<?>))
    return false;

  Collection<?> col = scala.collection.JavaConversions.asJavaCollection((Iterable<?>) obj);
  if (col.isEmpty())
    return false;

  for (Object o : col) {
    if (!(o instanceof scala.collection.immutable.Seq))
      return false;

    Collection<?> col2 = scala.collection.JavaConversions.asJavaCollection((Iterable<?>) o);
    for (Object o2 : col2) {
      if (!parent.isPrimitiveType(o2.getClass().getName()))
        return false;
    }
  }
  return true;
}
 
Example #2
Source File: PartialCallGraph.java    From fasten with Apache License 2.0 5 votes vote down vote up
/**
 * Finds non abstract and non private methods of the artifact as entrypoints for call graph
 * generation.
 * @param methods are all of the {@link org.opalj.br.Method} in an OPAL-loaded project.
 * @return An {@link Iterable} of entrypoints to be consumed by scala-written OPAL.
 */
public static Iterable<org.opalj.br.Method> findEntryPoints(
    final java.lang.Iterable<org.opalj.br.Method> methods) {

    final List<org.opalj.br.Method> result = new ArrayList<>();

    for (final var method : methods) {
        if (!(method.isAbstract()) && !(method.isPrivate())) {
            result.add(method);
        }
    }
    return JavaConverters.collectionAsScalaIterable(result);

}
 
Example #3
Source File: PartialCallGraph.java    From fasten with Apache License 2.0 5 votes vote down vote up
/**
 * Assign each method an id. Ids start from the the first parameter and increase by one number
 * for every method.
 * @param keyStartsFrom Starting point of the Methods's ids.
 * @param methods       Iterable of {@link org.opalj.br.Method} to get mapped to ids.
 * @return A map of passed methods and their ids.
 * @implNote Methods are keys of the result map and values are the generated Integer keys.
 */
private static Map<org.opalj.br.Method, Integer> getMethodsMap(
    final int keyStartsFrom,
    final java.lang.Iterable<org.opalj.br.Method> methods) {

    final Map<org.opalj.br.Method, Integer> result = new HashMap<>();
    final AtomicInteger i = new AtomicInteger(keyStartsFrom);
    for (final var method : methods) {
        result.put(method, i.get());
        i.addAndGet(1);
    }
    return result;
}
 
Example #4
Source File: JavaToScalaConverter.java    From fasten with Apache License 2.0 5 votes vote down vote up
/**
 * Imitate a scala function0 in case of passing entrypoints as an scala function.
 * @param entryPoints Scala Iterable of methods.
 * @return An scala function including the results.
 */
public static Function0<Iterable<Method>> asScalaFunction0EntryPionts(
    final Iterable<Method> entryPoints) {
    return new AbstractFunction0<>() {

        @Override
        public Iterable<Method> apply() {
            return entryPoints;
        }
    };
}
 
Example #5
Source File: JavaToScalaConverter.java    From fasten with Apache License 2.0 5 votes vote down vote up
/**
 * Imitates a scala function2 in case of java method to be passed to scala.
 * @param javaFunction A java function in order to do things on scala.
 * @return Execution of java function as scala function2.
 */
public static AbstractFunction2<Method, Map<Object, Iterable<Method>>, Object> asScalaFunction2(
    final ScalaFunction2 javaFunction) {
    return new AbstractFunction2<>() {

        @Override
        public Object apply(Method v1, Map<Object, Iterable<Method>> v2) {
            return javaFunction.execute(v1, v2);
        }
    };
}
 
Example #6
Source File: ScalaCollectionSerializer.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean writeObject(Object obj, JsonGenerator jgen, boolean expand) throws JsonProcessingException, IOException {
  logger.debug("collection");
  // convert this 'on the fly' to an array of objects
  Collection<?> c = scala.collection.JavaConversions.asJavaCollection((Iterable<?>) obj);
  jgen.writeStartArray();
  for (Object o : c) {
    if (!parent.writeObject(o, jgen, false))
      jgen.writeObject(o.toString());
  }
  jgen.writeEndArray();
  return true;
}
 
Example #7
Source File: ScalaListOfPrimitiveTypeMapsSerializer.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canBeUsed(Object obj, boolean expand) {
  if (!expand)
    return false;

  if (!(obj instanceof scala.collection.immutable.Seq<?>))
    return false;

  Collection<?> col = scala.collection.JavaConversions.asJavaCollection((Iterable<?>) obj);
  if (col.isEmpty())
    return false;

  for (Object o : col) {
    if (!(o instanceof scala.collection.Map<?, ?>))
      return false;

    Map<?, ?> m = scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map<?, ?>) o);
    Set<?> keys = m.keySet();
    for (Object key : keys) {
      if (key != null && !parent.isPrimitiveType(key.getClass().getName()))
        return false;
      Object val = m.get(key);
      if (val != null && !parent.isPrimitiveType(val.getClass().getName()))
        return false;
    }
  }
  return true;
}
 
Example #8
Source File: ScalaListOfPrimitiveTypeMapsSerializer.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean writeObject(Object obj, JsonGenerator jgen, boolean expand) throws JsonProcessingException, IOException {
  logger.debug("list of maps");
  // convert this 'on the fly' to a datatable
  Collection<?> col = scala.collection.JavaConversions.asJavaCollection((Iterable<?>) obj);
  List<Map<String, Object>> tab = new ArrayList<Map<String, Object>>();
  for (Object o : col) {
    Map<String, Object> row = scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map<String, Object>) o);
    tab.add(row);
  }
  TableDisplay t = new TableDisplay(tab, parent);
  jgen.writeObject(t);
  return true;
}
 
Example #9
Source File: PartialCallGraph.java    From fasten with Apache License 2.0 4 votes vote down vote up
/**
 * Sorts the given Iterable.
 * @param iterable Iterable to be sorted.
 * @return Sorted List.
 */
private static List<?> sort(final java.lang.Iterable<?> iterable) {
    final var result = Lists.newArrayList(iterable);
    result.sort(Comparator.comparing(Object::toString));
    return result;
}
 
Example #10
Source File: DocumentFactoryTest.java    From baleen with Apache License 2.0 4 votes vote down vote up
@Test
public void canCreateDocumentWithCoreferences() throws UIMAException {
  JCas jCas = JCasFactory.createJCas();
  jCas.setDocumentText("John Smith was here. Then he went.");

  Sentence s1 = Annotations.createSentence(jCas, 0, 20);
  Sentence s2 = Annotations.createSentence(jCas, 21, 34);
  Person p1 = Annotations.createPerson(jCas, 0, 10, "John Smith");
  Person p2 = Annotations.createPerson(jCas, 26, 28, "he");
  Annotations.createReferenceTarget(jCas, p1, p2);

  OdinSentence sentence1 = mock(OdinSentence.class, "s1");
  OdinSentence sentence2 = mock(OdinSentence.class, "s2");
  CorefMention coref1 = new CorefMention(0, 0, p1.getBegin(), p1.getEnd(), 0);
  CorefMention coref2 = new CorefMention(1, 1, 5, 7, 0);

  when(sentenceFactory.create()).thenReturn(ImmutableList.of(sentence1, sentence2));
  when(sentence1.getBaleenSentence()).thenReturn(s1);
  when(sentence2.getBaleenSentence()).thenReturn(s2);
  when(sentence1.corefMention(p1, 0)).thenReturn(coref1);
  when(sentence2.corefMention(p2, 0)).thenReturn(coref2);

  DocumentFactory documentFactory = new DocumentFactory(jCas, sentenceFactory);

  Document document = documentFactory.create();
  assertEquals(2, document.sentences().length);

  Option<CorefChains> coreferenceChains = document.coreferenceChains();
  assertTrue(coreferenceChains.isDefined());

  CorefChains corefChains = coreferenceChains.get();
  assertFalse(corefChains.isEmpty());
  assertEquals(2, corefChains.rawMentions().size());

  Option<Iterable<CorefMention>> option1 = corefChains.getChain(0, 0);
  assertTrue(option1.isDefined());

  Iterator<CorefMention> iterator = option1.get().iterator();
  assertEquals(coref2, iterator.next());
  assertEquals(coref1, iterator.next());
  assertFalse(iterator.hasNext());
}
 
Example #11
Source File: SupervisorActor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void handleChildTerminated(akka.actor.ActorContext context, ActorRef child, Iterable<ActorRef> children) {
	akkaRpcActorTerminated(child);
}
 
Example #12
Source File: SupervisorActor.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void processFailure(akka.actor.ActorContext context, boolean restart, ActorRef child, Throwable cause, ChildRestartStats stats, Iterable<ChildRestartStats> children) {
	Preconditions.checkArgument(!restart, "The supervisor strategy should never restart an actor.");

	akkaRpcActorFailed(child, cause);
}
 
Example #13
Source File: ContextVariableWrapper.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public Iterable<String> keys() {
  Set<String> strings = context.keySet();
  return SetHasAsScala(strings).asScala();
}
 
Example #14
Source File: ScalaFunction2.java    From fasten with Apache License 2.0 votes vote down vote up
Boolean execute(final Method callee, final Map<Object, Iterable<Method>> caller);