jdk/src/java.base/share/classes/java/lang/module/ModuleReference.java
author alanb
Thu, 17 Mar 2016 19:04:16 +0000
changeset 36511 9d0388c6b336
child 37779 7c84df693837
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, chris.hegarty@oracle.com, alexandr.scherbatiy@oracle.com, amy.lu@oracle.com, calvin.cheung@oracle.com, daniel.fuchs@oracle.com, erik.joelsson@oracle.com, harold.seigel@oracle.com, jaroslav.bachorik@oracle.com, jean-francois.denise@oracle.com, jan.lahoda@oracle.com, james.laskey@oracle.com, lois.foltan@oracle.com, miroslav.kos@oracle.com, huaming.li@oracle.com, sean.mullan@oracle.com, naoto.sato@oracle.com, masayoshi.okutsu@oracle.com, peter.levart@gmail.com, philip.race@oracle.com, claes.redestad@oracle.com, sergey.bylokhov@oracle.com, alexandre.iline@oracle.com, volker.simonis@gmail.com, staffan.larsen@oracle.com, stuart.marks@oracle.com, semyon.sadetsky@oracle.com, serguei.spitsyn@oracle.com, sundararajan.athijegannathan@oracle.com, valerie.peng@oracle.com, vincent.x.ryan@oracle.com, weijun.wang@oracle.com, yuri.nesterenko@oracle.com, yekaterina.kantserova@oracle.com, alexander.kulyakhtin@oracle.com, felix.yang@oracle.com, andrei.eremeev@oracle.com, frank.yuan@oracle.com, sergei.pikalev@oracle.com, sibabrata.sahoo@oracle.com, tiantian.du@oracle.com, sha.jiang@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
package java.lang.module;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.io.UncheckedIOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.net.URI;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.util.Objects;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.Optional;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.util.function.Supplier;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import jdk.internal.module.Hasher.HashSupplier;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 * A reference to a module's content.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 * <p> A module reference contains the module's descriptor and its location, if
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
 * known.  It also has the ability to create a {@link ModuleReader} in order to
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
 * access the module's content, which may be inside the Java run-time system
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 * itself or in an artifact such as a modular JAR file.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 * @see ModuleFinder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
 * @see ModuleReader
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
 * @since 9
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
public final class ModuleReference {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private final ModuleDescriptor descriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    private final URI location;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private final Supplier<ModuleReader> readerSupplier;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    // the function that computes the hash of this module reference
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
    private final HashSupplier hasher;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    // cached hash string to avoid needing to compute it many times
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    private String cachedHash;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
     * Constructs a new instance of this class.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    ModuleReference(ModuleDescriptor descriptor,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
                    URI location,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
                    Supplier<ModuleReader> readerSupplier,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
                    HashSupplier hasher)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        this.descriptor = Objects.requireNonNull(descriptor);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        this.location = location;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        this.readerSupplier = Objects.requireNonNull(readerSupplier);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        this.hasher = hasher;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
     * Constructs a new instance of this class.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
     * <p> The {@code readSupplier} parameter is the supplier of the {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
     * ModuleReader} that may be used to read the module content. Its {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
     * Supplier#get() get()} method throws {@link UncheckedIOException} if an
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
     * I/O error occurs opening the module content. The {@code get()} method
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
     * throws {@link SecurityException} if opening the module is denied by the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
     * security manager.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
     * @param descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
     *        The module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
     * @param location
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
     *        The module location or {@code null} if not known
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
     * @param readerSupplier
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
     *        The {@code Supplier} of the {@code ModuleReader}
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    public ModuleReference(ModuleDescriptor descriptor,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
                           URI location,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
                           Supplier<ModuleReader> readerSupplier)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        this(descriptor, location, readerSupplier, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
     * Returns the module descriptor.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
     * @return The module descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
    public ModuleDescriptor descriptor() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
        return descriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
     * Returns the location of this module's content, if known.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
     * <p> This URI, when present, is used as the {@linkplain
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
     * java.security.CodeSource#getLocation location} value of a {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
     * java.security.CodeSource CodeSource} so that a module's classes can be
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
     * granted specific permissions when loaded by a {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
     * java.security.SecureClassLoader SecureClassLoader}.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
     * @return The location or an empty {@code Optional} if not known
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    public Optional<URI> location() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        return Optional.ofNullable(location);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
     * Opens the module content for reading.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
     * <p> This method opens the module content by invoking the {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
     * Supplier#get() get()} method of the {@code readSupplier} specified at
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
     * construction time. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
     * @return A {@code ModuleReader} to read the module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
     * @throws IOException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
     *         If an I/O error occurs
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
     * @throws SecurityException
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
     *         If denied by the security manager
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    public ModuleReader open() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
            return readerSupplier.get();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
        } catch (UncheckedIOException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
            throw e.getCause();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
     * Computes the hash of this module, returning it as a hex string.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
     * Returns {@code null} if the hash cannot be computed.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
     * @throws java.io.UncheckedIOException if an I/O error occurs
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    String computeHash(String algorithm) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        String result = cachedHash;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
        if (result != null)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
            return result;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        if (hasher == null)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
            return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        cachedHash = result = hasher.generate(algorithm);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        return result;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
    private int hash;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
     * Computes a hash code for this module reference.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
     * <p> The hash code is based upon the components of the reference, and
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
     * satisfies the general contract of the {@link Object#hashCode
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
     * Object.hashCode} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
     * @return The hash-code value for this module reference
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
    public int hashCode() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
        int hc = hash;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
        if (hc == 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
            hc = Objects.hash(descriptor, location, readerSupplier, hasher);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
            if (hc != 0) hash = hc;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        return hc;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
     * Tests this module reference for equality with the given object.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
     * <p> If the given object is not a {@code ModuleReference} then this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
     * method returns {@code false}. Two module references are equal if their
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
     * module descriptors are equal, their locations are equal or both unknown,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
     * and were created with equal supplier objects to access the module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
     * content. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
     * <p> This method satisfies the general contract of the {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
     * java.lang.Object#equals(Object) Object.equals} method. </p>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
     * @param   ob
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
     *          the object to which this object is to be compared
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
     * @return  {@code true} if, and only if, the given object is a module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
     *          reference that is equal to this module reference
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
    public boolean equals(Object ob) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        if (!(ob instanceof ModuleReference))
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
            return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
        ModuleReference that = (ModuleReference)ob;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        return Objects.equals(this.descriptor, that.descriptor)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
                && Objects.equals(this.location, that.location)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
                && Objects.equals(this.readerSupplier, that.readerSupplier)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
                && Objects.equals(this.hasher, that.hasher);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
     * Returns a string describing this module reference.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
     * @return A string describing this module reference
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
    public String toString() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        return ("[module " + descriptor().name()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
                + ", location=" + location + "]");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
}