1 /*******************************************************************************
2 * Copyright (c) 2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.common;
14 import org.eclipse.winery.common.ids.GenericId;
17 * Holds a reference to a file "object" stored in the repository
19 * Directories are NOT supported as we would have to reflect parent
20 * relationships there, too.
22 * One has to create TOSCAelementId-objects for directories (e.g., scc-data)
24 public class RepositoryFileReference implements Comparable<RepositoryFileReference> {
26 protected final GenericId parent;
27 protected final String fileName;
31 * @param parent the id of the toscaElement the file is nested in
32 * @param fileName the file name. <em>Must not</em> contain any illegal
33 * characters. java.nio.Path cannot be used as Path is tied to a
36 public RepositoryFileReference(GenericId parent, String fileName) {
38 throw new IllegalArgumentException("Parent must not be null.");
40 if (fileName == null) {
41 throw new IllegalArgumentException("Filename must not be null.");
44 this.fileName = fileName;
47 public GenericId getParent() {
51 public String getFileName() {
56 public boolean equals(Object obj) {
57 if (obj instanceof RepositoryFileReference) {
58 RepositoryFileReference otherRef = (RepositoryFileReference) obj;
59 return (otherRef.fileName.equals(this.fileName)) && (otherRef.getParent().equals(this.getParent()));
66 public int hashCode() {
67 return this.getParent().hashCode() ^ this.getFileName().hashCode();
71 public int compareTo(RepositoryFileReference o) {
73 res = this.parent.compareTo(o.parent);
75 res = this.fileName.compareTo(o.fileName);
81 public String toString() {
82 return this.getParent().toString() + "/" + this.getFileName();