2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
3 * Copyright (c) 2024 PANTHEON.tech, s.r.o.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mdsal.common.api;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.util.concurrent.FluentFuture;
13 import com.google.common.util.concurrent.Futures;
14 import java.io.ObjectStreamException;
15 import java.time.Instant;
16 import java.util.UUID;
17 import org.eclipse.jdt.annotation.NonNull;
20 * Default {@link CommitInfo} implementation.
22 record CI(UUID uuid, Instant instant) implements CommitInfo {
24 private static final long serialVersionUID = 0L;
26 static final @NonNull CI EMPTY = new CI(null, null);
27 static final @NonNull FluentFuture<@NonNull CommitInfo> EMPTY_FUTURE =
28 FluentFuture.from(Futures.immediateFuture(EMPTY));
30 static @NonNull CI of(final UUID uuid, final Instant time) {
31 return time != null || uuid != null ? new CI(uuid, time) : EMPTY;
35 public String toString() {
36 return MoreObjects.toStringHelper(CommitInfo.class).omitNullValues()
38 .add("instant", instant)
43 private Object readResolve() throws ObjectStreamException {
44 return instant != null || uuid != null ? this : EMPTY;