public class

TransformingAtom<I, O>

extends java.lang.Object

implements Atom<java.lang.Object>

 java.lang.Object

↳androidx.test.espresso.web.model.TransformingAtom<I, O>

Gradle dependencies

compile group: 'androidx.test.espresso', name: 'espresso-web', version: '3.6.1'

  • groupId: androidx.test.espresso
  • artifactId: espresso-web
  • version: 3.6.1

Artifact androidx.test.espresso:espresso-web:3.6.1 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test.espresso:espresso-web com.android.support.test.espresso:espresso-web

Androidx class mapping:

androidx.test.espresso.web.model.TransformingAtom android.support.test.espresso.web.model.TransformingAtom

Overview

Decorates another atom and transforms its output to another type.

Summary

Constructors
publicTransformingAtom(Atom<java.lang.Object> parent, TransformingAtom.Transformer<java.lang.Object, java.lang.Object> transformer)

Methods
public java.util.List<java.lang.Object>getArguments(ElementReference elementContext)

public java.lang.StringgetScript()

public java.lang.Objecttransform(Evaluation eval)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public TransformingAtom(Atom<java.lang.Object> parent, TransformingAtom.Transformer<java.lang.Object, java.lang.Object> transformer)

Methods

public java.lang.String getScript()

public java.util.List<java.lang.Object> getArguments(ElementReference elementContext)

public java.lang.Object transform(Evaluation eval)

Source

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.test.espresso.web.model;

import static androidx.test.internal.util.Checks.checkNotNull;

import androidx.annotation.Nullable;
import androidx.test.espresso.remote.annotation.RemoteMsgConstructor;
import androidx.test.espresso.remote.annotation.RemoteMsgField;
import java.util.List;

/**
 * Decorates another atom and transforms its output to another type.
 *
 * @param <I> the type of the parent Atom.
 * @param <O> the type of the parent atom after applying a transformation.
 */
public class TransformingAtom<I, O> implements Atom<O> {
  @RemoteMsgField(order = 0)
  private final Atom<I> parent;

  @RemoteMsgField(order = 1)
  private final Transformer<I, O> transformer;

  @RemoteMsgConstructor
  public TransformingAtom(Atom<I> parent, Transformer<I, O> transformer) {
    this.parent = checkNotNull(parent);
    this.transformer = checkNotNull(transformer);
  }

  @Override
  public String getScript() {
    return parent.getScript();
  }

  @Override
  public List<Object> getArguments(@Nullable ElementReference elementContext) {
    return parent.getArguments(elementContext);
  }

  @Override
  public O transform(Evaluation eval) {
    return transformer.apply(parent.transform(eval));
  }

  /** Converts input to output. */
  public interface Transformer<I, O> {
    public O apply(I input);
  }
}