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.io.Serializable;
16 import java.time.Instant;
17 import java.util.UUID;
18 import org.eclipse.jdt.annotation.NonNull;
21 * Default {@link CommitInfo} implementation.
23 record CI(UUID uuid, Instant instant) implements CommitInfo, Serializable {
25 private static final long serialVersionUID = 0L;
27 static final @NonNull CI EMPTY = new CI(null, null);
28 static final @NonNull FluentFuture<@NonNull CommitInfo> EMPTY_FUTURE =
29 FluentFuture.from(Futures.immediateFuture(EMPTY));
31 static @NonNull CI of(final UUID uuid, final Instant time) {
32 return time != null || uuid != null ? new CI(uuid, time) : EMPTY;
36 public String toString() {
37 return MoreObjects.toStringHelper(CommitInfo.class).omitNullValues()
39 .add("instant", instant)
44 private Object readResolve() throws ObjectStreamException {
45 return instant != null || uuid != null ? this : EMPTY;