1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.tools.jlink.internal; 27 28 import java.util.Objects; 29 import jdk.tools.jlink.plugin.ResourcePoolEntry; 30 31 /** 32 * A LinkResourcePoolEntry is the elementary unit of data inside an image. It is 33 * generally a file. e.g.: a java class file, a resource file, a shared library, 34 * ... 35 * <br> 36 * A LinkResourcePoolEntry is identified by a path of the form: 37 * <ul> 38 * <li>For jimage content: /{module name}/{package1}/.../{packageN}/{file 39 * name}</li> 40 * <li>For other files (shared lib, launchers, config, ...):/{module name}/ 41 * {@literal bin|conf|lib}/{dir1}>/.../{dirN}/{file name}</li> 42 * </ul> 43 */ 44 abstract class AbstractResourcePoolEntry implements ResourcePoolEntry { 45 private final String path; 46 private final String module; 47 private final Type type; 48 49 /** 50 * Create a new AbstractResourcePoolEntry. 51 * 52 * @param module The module name. 53 * @param path The data path identifier. 54 * @param type The data type. 55 */ 56 AbstractResourcePoolEntry(String module, String path, Type type) { 57 this.module = Objects.requireNonNull(module); 58 this.path = Objects.requireNonNull(path); 59 this.type = Objects.requireNonNull(type); 60 } 61 62 @Override 63 public final String moduleName() { 64 return module; 65 } 66 67 @Override 68 public final String path() { 69 return path; 70 } 71 72 @Override 73 public final Type type() { 74 return type; 75 } 76 77 @Override 78 public int hashCode() { 79 return Objects.hashCode(this.path); 80 } 81 82 @Override 83 public boolean equals(Object other) { 84 if (!(other instanceof AbstractResourcePoolEntry)) { 85 return false; 86 } 87 AbstractResourcePoolEntry f = (AbstractResourcePoolEntry) other; 88 return f.path.equals(path); 89 } 90 91 @Override 92 public String toString() { 93 return path(); 94 } 95 }