Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/Denotation.java
40948 views
/*1* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.share;2425import java.util.*;2627/**28* Denotation implies a pair of algorithms for naming and29* indexing of some objects.30*31* <p>No matter what kind of objects, just make sure that:32* <ul>33* <li><tt>indexFor(nameFor(index))</tt> equals to <tt>index</tt>34* </li>35* <li><tt>nameFor(indexFor(name))</tt> is equivalent to <tt>name</tt>36* </li>37* </ul>38*39* <p>The notions of indeces equality and names equivalence40* are formalized by the methods <tt>equality()</tt> and41* <tt>equivalence()</tt> correspondingly.42*43* <p>For better understanding of Denotation, you may want to44* see the TreeNodesDenotation class as an implementation example.45*46* @see #equality(int[],int[])47* @see #equivalence(String,String)48* @see TreeNodesDenotation49*/50abstract public class Denotation {51/**52* Check if the <tt>name</tt> is legal, and return the53* numeric index for that object denoted by the given54* <tt>name</tt>.55*56* @throws IllegalArgumentException If the <tt>name</tt>57* is illegal.58*/59abstract public int[] indexFor(String name);6061/**62* Check if the <tt>index[]</tt> is legal, and return63* a symbolic name for the object denoted by the given64* <tt>index[]</tt>.65*66* @throws IllegalArgumentException If the <tt>index[]</tt>67* is illegal.68*/69abstract public String nameFor(int[] index);7071/**72* Re-call to <tt>nameFor(int[])</tt> with the 1-element73* array <tt>{i}</tt> as the <tt>index</tt> argument.74*75* @see #nameFor(int[])76*/77public String nameFor(int i) {78return nameFor(new int[] { i });79}8081/**82* Re-call to <tt>nameFor(int[])</tt> with the 2-elements83* array <tt>{i0,i1}</tt> as the <tt>index</tt> argument.84*85* @see #nameFor(int[])86*/87public String nameFor(int i0, int i1) {88return nameFor(new int[] {i0, i1});89}9091/**92* Re-call to <tt>nameFor(int[])</tt> with the 3-elements93* array <tt>{i0,i1,i2}</tt> as the <tt>index</tt> argument.94*95* @see #nameFor(int[])96*/97public String nameFor(int i0, int i1, int i2) {98return nameFor(new int[] {i0, i1, i2});99}100101/**102* Indeces equality means equality of objects they denote.103*104* <p>Indeces <tt>index1[]</tt> and <tt>index2[]</tt> are105* equal, if they are equal as <tt>int[]</tt> arrays. But,106* there is no index equal to <tt>null</tt>; particularly,107* <tt>null</tt> is not equal to itself.108*109* @see Arrays#equals(int[],int[])110*/111public boolean equality(int[] index1, int[] index2) {112if (index1 == null || index2 == null)113return false;114return Arrays.equals(index1,index2);115}116117/**118* Names equivalence means equality of objects they denote.119*120* <p>Strings <tt>name1</tt> and <tt>name2</tt> are equivalent,121* if correspondent indeces are equal. There is no <tt>name</tt>122* equivalent to <tt>null</tt>; particularly, <tt>null</tt> is123* not equivalent to itself.124*125* @see #equality(int[],int[])126*/127public boolean equivalence(String name1, String name2) {128if (name1 == null || name2 == null)129return false;130return equality(indexFor(name1),indexFor(name2));131}132133/**134* Dummy constructor.135*/136protected Denotation() {137}138}139140141