All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.ShadowCaptureResult Maven / Gradle / Ivy

The newest version!
package org.robolectric.shadows;

import android.annotation.Nullable;
import android.hardware.camera2.CaptureResult;
import android.hardware.camera2.CaptureResult.Key;
import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Map;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.util.ReflectionHelpers;

/** Shadow of {@link CaptureResult}. */
@Implements(value = CaptureResult.class)
public class ShadowCaptureResult {

  private final Map, Object> resultsKeyToValue = new HashMap<>();

  /** Convenience method which returns a new instance of {@link CaptureResult}. */
  public static CaptureResult newCaptureResult() {
    return ReflectionHelpers.callConstructor(CaptureResult.class);
  }

  /** Obtain a property of the CaptureResult. */
  @Implementation
  @Nullable
  @SuppressWarnings("unchecked")
  protected  T get(Key key) {
    return (T) resultsKeyToValue.get(key);
  }

  /**
   * Sets the value for a given key.
   *
   * @throws IllegalArgumentException if there's an existing value for the key.
   */
  public  void set(Key key, T value) {
    Preconditions.checkArgument(!resultsKeyToValue.containsKey(key));
    resultsKeyToValue.put(key, value);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy