2 * Copyright (c) 2015 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.common;
10 import com.google.common.util.concurrent.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.io.Serializable;
13 import java.util.concurrent.CompletableFuture;
14 import java.util.concurrent.CompletionStage;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.concepts.Immutable;
20 * Dedicated type for YANG's {@code type empty} value.
23 public final class Empty implements Immutable, Serializable {
25 private static final long serialVersionUID = 1L;
26 private static final Empty VALUE = new Empty();
27 private static final CompletionStage<Empty> COMPLETED_FUTURE = CompletableFuture.completedFuture(VALUE);
28 private static final ListenableFuture<Empty> IMMEDIATE_FUTURE = Futures.immediateFuture(VALUE);
35 * Return the singleton {@link Empty} value.
37 * @return Empty value.
39 public static Empty value() {
44 * Return a {@link CompletionStage} completed with {@link #value()}.
46 * @return A completed CompletionStage
48 public static CompletionStage<Empty> completedFuture() {
49 return COMPLETED_FUTURE;
53 * Return a {@link ListenableFuture} completed with {@link #value()}.
55 * @return A completed ListenableFuture
57 public static ListenableFuture<Empty> immediateFuture() {
58 return IMMEDIATE_FUTURE;
62 public int hashCode() {
67 public boolean equals(final @Nullable Object obj) {
68 // Note: this is nominally a singleton, but due to it being Serializable multiple instances might be created
69 // via hand-crafted serialization streams. We therefore do not rely on '==' but on 'instanceof' check.
70 return obj instanceof Empty;
74 public String toString() {
79 @SuppressWarnings("static-method")
80 private Object readResolve() {