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.io.InputStream; 29 import java.util.Objects; 30 import jdk.tools.jlink.plugin.ModuleEntry; 31 32 /** 33 * A LinkModuleEntry is the elementary unit of data inside an image. It is 34 * generally a file. e.g.: a java class file, a resource file, a shared library, 35 * ... 36 * <br> 37 * A LinkModuleEntry is identified by a path of the form: 38 * <ul> 39 * <li>For jimage content: /{module name}/{package1}/.../{packageN}/{file 40 * name}</li> 41 * <li>For other files (shared lib, launchers, config, ...):/{module name}/ 42 * {@literal bin|conf|native}/{dir1}>/.../{dirN}/{file name}</li> 43 * </ul> 44 */ 45 abstract class AbstractModuleEntry implements ModuleEntry { 46 private final String path; 47 private final String module; 48 private final Type type; 49 50 /** 51 * Create a new AbstractModuleEntry. 52 * 53 * @param module The module name. 54 * @param path The data path identifier. 55 * @param type The data type. 56 */ 57 AbstractModuleEntry(String module, String path, Type type) { 58 this.module = Objects.requireNonNull(module); 59 this.path = Objects.requireNonNull(path); 60 this.type = Objects.requireNonNull(type); 61 } 62 63 @Override 64 public final String getModule() { 65 return module; 66 } 67 68 @Override 69 public final String getPath() { 70 return path; 71 } 72 73 @Override 74 public final Type getType() { 75 return type; 76 } 77 78 @Override 79 public int hashCode() { 80 int hash = 7; 81 hash = 89 * hash + Objects.hashCode(this.path); 82 return hash; 83 } 84 85 @Override 86 public boolean equals(Object other) { 87 if (!(other instanceof AbstractModuleEntry)) { 88 return false; 89 } 90 AbstractModuleEntry f = (AbstractModuleEntry) other; 91 return f.path.equals(path); 92 } 93 94 @Override 95 public String toString() { 96 return getPath(); 97 } 98 }