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

com.apollographql.apollo3.api.internal.Present.kt Maven / Gradle / Ivy

/*
 * Copyright (C) 2011 The Guava Authors
 *
 * 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 com.apollographql.apollo3.api.internal


/**
 * Implementation of an [Optional] containing a reference.
 */
@Deprecated("This shouldn't be used anymore with Kotlin APIs")
internal class Present(private val reference: T) : Optional() {
  override val isPresent: Boolean
    get() = true

  override fun get(): T {
    return reference
  }

  override fun or(defaultValue: T): T {
    return reference
  }

  override fun or(secondChoice: Optional): Optional {
    return this
  }

  override fun  transform(function: Function): Optional {
    return Present(function.apply(reference))
  }

  override fun  map(function: Function): Optional {
    return Present(function.apply(reference))
  }

  override fun  flatMap(function: Function>): Optional {
    return function.apply(reference)
  }

  override fun apply(action: Action): Optional {
    return map(object : Function {
      override fun apply(t: T): T {
        action.apply(t)
        return t
      }
    })
  }

  override fun orNull(): T? {
    return reference
  }

  override fun asSet(): Set {
    return setOf(reference)
  }

  override fun equals(`object`: Any?): Boolean {
    if (`object` is Present<*>) {
      return reference == `object`.reference
    }
    return false
  }

  override fun hashCode(): Int {
    return 0x598df91c + reference.hashCode()
  }

  override fun toString(): String {
    return "Optional.of($reference)"
  }

  companion object {
    private const val serialVersionUID: Long = 0
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy