com.google.android.agera.Function类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中com.google.android.agera.Function类的一些代码示例,展示了Function类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Function类的具体详情如下:
包路径:com.google.android.agera.Function
类名称:Function

Function介绍

[英]Determines an output value based on an input value.

The Functions class provides common functions and related utilities.
[中]根据输入值确定输出值。
Functions类提供常用函数和相关实用程序。

代码示例

代码示例来源:origin: google/agera

@NonNull
 @Override
 public T get() {
  return function.apply(from);
 }
}

代码示例来源:origin: google/agera

@Override
public boolean areItemsTheSame(final int oldItemPosition, final int newItemPosition) {
 final Object oldKey = keyForItem.apply(oldItems.get(oldItemPosition));
 final Object newKey = keyForItem.apply(newItems.get(newItemPosition));
 return oldKey.equals(newKey);
}

代码示例来源:origin: google/agera

@NonNull
 @Override
 @SuppressWarnings("unchecked")
 public Object apply(@NonNull final Object input) {
  Object item = input;
  for (final Function function : functions) {
   item = function.apply(item);
  }
  return item;
 }
}

代码示例来源:origin: google/agera

private int runTransform(@NonNull final Object[] directives, final int index) {
 final Function function = (Function) directives[index + 1];
 intermediateValue = checkNotNull(function.apply(intermediateValue));
 return index + 2;
}

代码示例来源:origin: google/agera

/**
 * Returns a {@link Result} wrapping the result of applying the given {@code function} to the
 * output value encapsulated in this result, or if this is the result of a {@link #failed}
 * attempt, returns the {@link #sameFailure}.
 */
@NonNull
public <U> Result<U> ifSucceededMap(@NonNull final Function<? super T, U> function) {
 if (value != null) {
  return success(function.apply(value));
 }
 return sameFailure();
}

代码示例来源:origin: google/agera

private int runCheck(@NonNull final Object[] directives, final int index) {
 final Function caseFunction = (Function) directives[index + 1];
 final Predicate casePredicate = (Predicate) directives[index + 2];
 final Function terminatingValueFunction = (Function) directives[index + 3];
 final Object caseValue = caseFunction.apply(intermediateValue);
 if (casePredicate.apply(caseValue)) {
  return index + 4;
 } else {
  runTerminate(caseValue, terminatingValueFunction);
  return -1;
 }
}

代码示例来源:origin: google/agera

@Before
public void setUp() {
 initMocks(this);
 viewHolder = new RecyclerView.ViewHolder(view) {};
 when(layoutForItem.apply(SECOND_STRING)).thenReturn(DYNAMIC_LAYOUT_ID);
}

代码示例来源:origin: google/agera

@Test
public void shouldGetOutputStreamForPutWithBody() throws Throwable {
 final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 final ByteArrayInputStream inputStream = new ByteArrayInputStream(RESPONSE_BODY);
 when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
 when(mockHttpURLConnection.getInputStream()).thenReturn(inputStream);
 assertThat(httpFunction().apply(HTTP_PUT_WITH_BODY_REQUEST), is(notNullValue()));
 verify(mockHttpURLConnection).setDoInput(true);
 verify(mockHttpURLConnection).disconnect();
 assertThat(outputStream.toByteArray(), is(REQUEST_BODY));
}

代码示例来源:origin: google/agera

@Test
public void shouldPassOnRequestHeaders() throws Throwable {
 assertThat(httpFunction().apply(HTTP_GET_REQUEST_WITH_HEADERS), is(notNullValue()));
 verify(mockHttpURLConnection).addRequestProperty("name", "value");
 verify(mockHttpURLConnection).addRequestProperty("name2", "value2");
 verify(mockHttpURLConnection).disconnect();
}

代码示例来源:origin: google/agera

@Test
public void shouldPassOnPostMethod() throws Throwable {
 assertThat(httpFunction()
     .apply(HTTP_POST_REQUEST),
   is(notNullValue()));
 verify(mockHttpURLConnection).setRequestMethod(POST_METHOD);
 verify(mockHttpURLConnection).disconnect();
}

代码示例来源:origin: google/agera

@Test
public void shouldPassOnGetMethod() throws Throwable {
 assertThat(httpFunction()
     .apply(HTTP_GET_REQUEST),
   is(notNullValue()));
 verify(mockHttpURLConnection).setRequestMethod(GET_METHOD);
 verify(mockHttpURLConnection).disconnect();
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnValueOfSucceededFromAppliedFunctionForFlatMapOfSucceeded() {
 assertThat(SUCCESS_WITH_OTHER_VALUE.ifSucceededAttemptMap(mockSucceededValueFunction),
   equalTo(SUCCESS_WITH_VALUE));
 verify(mockSucceededValueFunction).apply(OTHER_VALUE);
}

代码示例来源:origin: google/agera

@Test
public void shouldGetByteArrayFromGetResponse() throws Throwable {
 final ByteArrayInputStream inputStream = new ByteArrayInputStream(RESPONSE_BODY);
 when(mockHttpURLConnection.getInputStream()).thenReturn(inputStream);
 when(mockHttpURLConnection.getContentLength()).thenReturn(RESPONSE_BODY.length);
 assertThat(httpFunction().apply(HTTP_GET_REQUEST).get().getBody(), is(RESPONSE_BODY));
 verify(mockHttpURLConnection).disconnect();
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnRecoverSuccessForAttemptRecoverOfFailure() {
 assertThat(FAILURE_WITH_THROWABLE.attemptRecover(mockAttemptRecoverValueFunction),
   equalTo(SUCCESS_WITH_VALUE));
 verify(mockAttemptRecoverValueFunction).apply(THROWABLE);
}

代码示例来源:origin: google/agera

@Test
public void shouldGracefullyHandleProtocolExceptionForInvalidMethod() throws Throwable {
 doThrow(ProtocolException.class).when(mockHttpURLConnection).setRequestMethod(anyString());
 assertThat(httpFunction().apply(HTTP_DELETE_REQUEST).getFailure(),
   instanceOf(ProtocolException.class));
 verify(mockHttpURLConnection).disconnect();
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnFailureIfAttemptFromAppliedFunctionForFlatMapOfValueReturnsFailure() {
 assertThat(SUCCESS_WITH_VALUE.ifSucceededAttemptMap(mockFailedFunction),
   equalTo(FAILURE_WITH_THROWABLE));
 verify(mockFailedFunction).apply(VALUE);
}

代码示例来源:origin: google/agera

@Test
public void shouldGetEmptyBodyFromGetResponseOfZeroLength() throws Throwable {
 final InputStream inputStream = mock(InputStream.class);
 when(mockHttpURLConnection.getInputStream()).thenReturn(inputStream);
 when(mockHttpURLConnection.getContentLength()).thenReturn(0);
 assertThat(httpFunction().apply(HTTP_GET_REQUEST).get().getBody(), is(EMPTY_BODY));
 verify(mockHttpURLConnection).disconnect();
 verifyZeroInteractions(inputStream);
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnEmptyStringForNullResponseMessage() throws Throwable {
 when(mockHttpURLConnection.getResponseMessage()).thenReturn(null);
 final HttpResponse httpResponse = httpFunction().apply(HTTP_GET_REQUEST).get();
 assertThat(httpResponse.getResponseMessage(), is(""));
 verify(mockHttpURLConnection).disconnect();
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnObjectFromSupplierForSupplierAsFunction() {
 assertThat(supplierAsFunction(mockSupplier).apply(new Object()),
   is(sameInstance(INPUT_STRING)));
}

代码示例来源:origin: google/agera

@Test
public void shouldWrapThrowableInFailedResult() {
 final Throwable throwable = new Throwable();
 assertThat(failedResult().apply(throwable).getFailure(), is(throwable));
}

相关文章