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

com.apollographql.apollo.api.internal.Functions Maven / Gradle / Ivy

There is a newer version: 3.4.2
Show newest version
/**
 * Copyright 2018-2019 Amazon.com,
 * Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Amazon Software License (the "License").
 * You may not use this file except in compliance with the
 * License. A copy of the License is located at
 *
 *     http://aws.amazon.com/asl/
 *
 * or in the "license" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, express or implied. See the License
 * for the specific language governing permissions and
 * limitations under the License.
 */

package com.apollographql.apollo.api.internal;


import javax.annotation.Nullable;

import static com.apollographql.apollo.api.internal.Utils.checkNotNull;

public class Functions {
  /**
   * Returns the identity function.
   */
  // implementation is "fully variant"; E has become a "pass-through" type
  public static  Function identity() {
    return (Function) IdentityFunction.INSTANCE;
  }

  // enum singleton pattern
  private enum IdentityFunction implements Function {
    INSTANCE;

    @Override
    @Nullable
    public Object apply(@Nullable Object o) {
      return o;
    }

    @Override
    public String toString() {
      return "Functions.identity()";
    }
  }

  /**
   * Returns a function that calls {@code toString()} on its argument. The function does not accept
   * nulls; it will throw a {@link NullPointerException} when applied to {@code null}.
   *
   * 

Warning: The returned function may not be consistent with equals (as * documented at {@link Function#apply}). For example, this function yields different results for * the two equal instances {@code ImmutableSet.of(1, 2)} and {@code ImmutableSet.of(2, 1)}. */ public static Function toStringFunction() { return ToStringFunction.INSTANCE; } // enum singleton pattern private enum ToStringFunction implements Function { INSTANCE; @Override public String apply(Object o) { checkNotNull(o); // eager for GWT. return o.toString(); } @Override public String toString() { return "Functions.toStringFunction()"; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy