2 * Copyright (c) 2020 PANTHEON.tech, 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.plugin.generator.api;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import com.google.common.base.CharMatcher;
15 import com.google.common.base.MoreObjects;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
21 * A relative path to a generated file.
23 * @author Robert Varga
27 public final class GeneratedFilePath {
28 public static final char SEPARATOR = '/';
29 public static final String SEPARATOR_STR = "/";
31 private static final CharMatcher FS_MATCHER = CharMatcher.is(File.separatorChar);
33 private final String path;
35 private GeneratedFilePath(final String path) {
36 this.path = requireNonNull(path);
37 checkArgument(!path.isEmpty());
40 public static GeneratedFilePath ofPath(final String path) {
41 return new GeneratedFilePath(path);
44 public static GeneratedFilePath ofFile(final File file) {
45 return ofFilePath(file.getPath());
48 public static GeneratedFilePath ofFilePath(final String filePath) {
49 return ofPath(FS_MATCHER.replaceFrom(filePath, SEPARATOR));
52 public String getPath() {
57 public int hashCode() {
58 return path.hashCode();
62 public boolean equals(final @Nullable Object obj) {
63 return this == obj || obj instanceof GeneratedFilePath && path.equals(((GeneratedFilePath) obj).path);
67 public String toString() {
68 return MoreObjects.toStringHelper(this).add("path", path).toString();