langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Bits.java
author vromero
Tue, 09 Sep 2014 10:43:06 -0700
changeset 26537 026471c1a12b
parent 25874 83c19f00452c
child 29054 310b8028d7df
permissions -rw-r--r--
8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class Reviewed-by: mcimadamore, jjg, jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
22689
570f79791f52 8028267: sun.tools.javac.util.Bits contains a main-method with test code
alundblad
parents: 19941
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
14049
3207422a0f9b 7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents: 13844
diff changeset
    28
import java.util.Arrays;
3207422a0f9b 7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents: 13844
diff changeset
    29
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
/** A class for extensible, mutable bit sets.
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    32
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    33
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
public class Bits {
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    39
    //       ____________      reset    _________
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    40
    //      /  UNKNOWN   \   <-------- / UNINIT  \
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    41
    //      \____________/       |     \_________/
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    42
    //            |              |          |
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    43
    //            |assign        |          | any
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    44
    //            |        ___________      |
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    45
    //            ------> /  NORMAL   \ <----
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    46
    //                    \___________/     |
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    47
    //                            |         |
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    48
    //                            |         |
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    49
    //                            -----------
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    50
    //                               any
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
    51
    protected enum BitsState {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    52
        /*  A Bits instance is in UNKNOWN state if it has been explicitly reset.
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    53
         *  It is possible to get to this state from any other by calling the
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    54
         *  reset method. An instance in the UNKNOWN state can pass to the
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    55
         *  NORMAL state after being assigned another Bits instance.
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
    56
         *
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
    57
         *  Bits instances are final fields in Flow so the UNKNOWN state models
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
    58
         *  the null assignment.
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    59
         */
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    60
        UNKNOWN,
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    61
        /*  A Bits instance is in UNINIT when it is created with the default
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    62
         *  constructor but it isn't explicitly reset. The main objective of this
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    63
         *  internal state is to save some memory.
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    64
         */
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    65
        UNINIT,
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    66
        /*  The normal state is reached after creating a Bits instance from an
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    67
         *  existing one or after applying any operation to an instance on UNINIT
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    68
         *  or NORMAL state. From this state a bits instance can pass to the
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    69
         *  UNKNOWN state by calling the reset method.
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    70
         */
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    71
        NORMAL;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    72
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    73
        static BitsState getState(int[] someBits, boolean reset) {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    74
            if (reset) {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    75
                return UNKNOWN;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    76
            } else {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    77
                if (someBits != unassignedBits) {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    78
                    return NORMAL;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    79
                } else {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    80
                    return UNINIT;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    81
                }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    82
            }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    83
        }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    84
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
    85
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
26537
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    87
    public enum BitsOpKind {
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    88
        INIT,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    89
        CLEAR,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    90
        INCL_BIT,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    91
        EXCL_BIT,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    92
        ASSIGN,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    93
        AND_SET,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    94
        OR_SET,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    95
        DIFF_SET,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    96
        XOR_SET,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    97
        INCL_RANGE,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    98
        EXCL_RANGE,
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
    99
    }
026471c1a12b 8042347: javac, Gen.LVTAssignAnalyzer should be refactored, it shouldn't be a static class
vromero
parents: 25874
diff changeset
   100
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    private final static int wordlen = 32;
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    private final static int wordshift = 5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    private final static int wordmask = wordlen - 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   105
    public int[] bits = null;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   106
    // This field will store last version of bits after every change.
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   107
    private static final int[] unassignedBits = new int[0];
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   108
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   109
    protected BitsState currentState;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    /** Construct an initially empty set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    public Bits() {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   114
        this(false);
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   115
    }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   116
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   117
    public Bits(Bits someBits) {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   118
        this(someBits.dup().bits, BitsState.getState(someBits.bits, false));
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   119
    }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   120
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   121
    public Bits(boolean reset) {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   122
        this(unassignedBits, BitsState.getState(unassignedBits, reset));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /** Construct a set consisting initially of given bit vector.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   127
    protected Bits(int[] bits, BitsState initState) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        this.bits = bits;
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   129
        this.currentState = initState;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   130
        switch (initState) {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   131
            case UNKNOWN:
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   132
                this.bits = null;
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   133
                break;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   134
            case NORMAL:
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   135
                Assert.check(bits != unassignedBits);
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   136
                break;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   137
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   140
    protected void sizeTo(int len) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        if (bits.length < len) {
14049
3207422a0f9b 7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents: 13844
diff changeset
   142
            bits = Arrays.copyOf(bits, len);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    /** This set = {}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    public void clear() {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   149
        Assert.check(currentState != BitsState.UNKNOWN);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   150
        for (int i = 0; i < bits.length; i++) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   151
            bits[i] = 0;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   152
        }
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   153
        currentState = BitsState.NORMAL;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   154
    }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   155
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   156
    public void reset() {
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   157
        internalReset();
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   158
    }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   159
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   160
    protected void internalReset() {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   161
        bits = null;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   162
        currentState = BitsState.UNKNOWN;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   163
    }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   164
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   165
    public boolean isReset() {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   166
        return currentState == BitsState.UNKNOWN;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   167
    }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   168
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   169
    public Bits assign(Bits someBits) {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   170
        bits = someBits.dup().bits;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   171
        currentState = BitsState.NORMAL;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   172
        return this;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    /** Return a copy of this set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     */
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   177
    public Bits dup() {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   178
        Assert.check(currentState != BitsState.UNKNOWN);
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   179
        Bits tmp = new Bits();
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   180
        tmp.bits = dupBits();
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   181
        currentState = BitsState.NORMAL;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   182
        return tmp;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   185
    protected int[] dupBits() {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   186
        int [] result;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   187
        if (currentState != BitsState.NORMAL) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   188
            result = bits;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   189
        } else {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   190
            result = new int[bits.length];
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   191
            System.arraycopy(bits, 0, result, 0, bits.length);
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   192
        }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   193
        return result;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   194
    }
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   195
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    /** Include x in this set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    public void incl(int x) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   199
        Assert.check(currentState != BitsState.UNKNOWN);
25848
3bc09f4676a9 8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents: 22689
diff changeset
   200
        Assert.check(x >= 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        sizeTo((x >>> wordshift) + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        bits[x >>> wordshift] = bits[x >>> wordshift] |
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            (1 << (x & wordmask));
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   204
        currentState = BitsState.NORMAL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    /** Include [start..limit) in this set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    public void inclRange(int start, int limit) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   211
        Assert.check(currentState != BitsState.UNKNOWN);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        sizeTo((limit >>> wordshift) + 1);
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   213
        for (int x = start; x < limit; x++) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
            bits[x >>> wordshift] = bits[x >>> wordshift] |
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                (1 << (x & wordmask));
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   216
        }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   217
        currentState = BitsState.NORMAL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
7621
9f2901d1f92f 7003744: Compiler error concerning final variables
mcimadamore
parents: 5847
diff changeset
   220
    /** Exclude [start...end] from this set.
9f2901d1f92f 7003744: Compiler error concerning final variables
mcimadamore
parents: 5847
diff changeset
   221
     */
9f2901d1f92f 7003744: Compiler error concerning final variables
mcimadamore
parents: 5847
diff changeset
   222
    public void excludeFrom(int start) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   223
        Assert.check(currentState != BitsState.UNKNOWN);
7621
9f2901d1f92f 7003744: Compiler error concerning final variables
mcimadamore
parents: 5847
diff changeset
   224
        Bits temp = new Bits();
9f2901d1f92f 7003744: Compiler error concerning final variables
mcimadamore
parents: 5847
diff changeset
   225
        temp.sizeTo(bits.length);
9f2901d1f92f 7003744: Compiler error concerning final variables
mcimadamore
parents: 5847
diff changeset
   226
        temp.inclRange(0, start);
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   227
        internalAndSet(temp);
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   228
        currentState = BitsState.NORMAL;
7621
9f2901d1f92f 7003744: Compiler error concerning final variables
mcimadamore
parents: 5847
diff changeset
   229
    }
9f2901d1f92f 7003744: Compiler error concerning final variables
mcimadamore
parents: 5847
diff changeset
   230
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    /** Exclude x from this set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    public void excl(int x) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   234
        Assert.check(currentState != BitsState.UNKNOWN);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   235
        Assert.check(x >= 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        sizeTo((x >>> wordshift) + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        bits[x >>> wordshift] = bits[x >>> wordshift] &
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            ~(1 << (x & wordmask));
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   239
        currentState = BitsState.NORMAL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    /** Is x an element of this set?
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    public boolean isMember(int x) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   245
        Assert.check(currentState != BitsState.UNKNOWN);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            0 <= x && x < (bits.length << wordshift) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
            (bits[x >>> wordshift] & (1 << (x & wordmask))) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 8032
diff changeset
   251
    /** {@literal this set = this set & xs}.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    public Bits andSet(Bits xs) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   254
        Assert.check(currentState != BitsState.UNKNOWN);
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   255
        internalAndSet(xs);
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   256
        currentState = BitsState.NORMAL;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   257
        return this;
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   258
    }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   259
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   260
    protected void internalAndSet(Bits xs) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   261
        Assert.check(currentState != BitsState.UNKNOWN);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        sizeTo(xs.bits.length);
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   263
        for (int i = 0; i < xs.bits.length; i++) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
            bits[i] = bits[i] & xs.bits[i];
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   265
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
    /** this set = this set | xs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    public Bits orSet(Bits xs) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   271
        Assert.check(currentState != BitsState.UNKNOWN);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        sizeTo(xs.bits.length);
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   273
        for (int i = 0; i < xs.bits.length; i++) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
            bits[i] = bits[i] | xs.bits[i];
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   275
        }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   276
        currentState = BitsState.NORMAL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    /** this set = this set \ xs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    public Bits diffSet(Bits xs) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   283
        Assert.check(currentState != BitsState.UNKNOWN);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        for (int i = 0; i < bits.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
            if (i < xs.bits.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                bits[i] = bits[i] & ~xs.bits[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        }
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   289
        currentState = BitsState.NORMAL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
    /** this set = this set ^ xs.
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    public Bits xorSet(Bits xs) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   296
        Assert.check(currentState != BitsState.UNKNOWN);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        sizeTo(xs.bits.length);
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   298
        for (int i = 0; i < xs.bits.length; i++) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
            bits[i] = bits[i] ^ xs.bits[i];
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   300
        }
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   301
        currentState = BitsState.NORMAL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
    /** Count trailing zero bits in an int. Algorithm from "Hacker's
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     *  Delight" by Henry S. Warren Jr. (figure 5-13)
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    private static int trailingZeroBits(int x) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   309
        Assert.check(wordlen == 32);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   310
        if (x == 0) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   311
            return 32;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   312
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        int n = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        if ((x & 0xffff) == 0) { n += 16; x >>>= 16; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        if ((x & 0x00ff) == 0) { n +=  8; x >>>=  8; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        if ((x & 0x000f) == 0) { n +=  4; x >>>=  4; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        if ((x & 0x0003) == 0) { n +=  2; x >>>=  2; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        return n - (x&1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 8032
diff changeset
   321
    /** Return the index of the least bit position &ge; x that is set.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     *  If none are set, returns -1.  This provides a nice way to iterate
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     *  over the members of a bit set:
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 8032
diff changeset
   324
     *  <pre>{@code
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     *  for (int i = bits.nextBit(0); i>=0; i = bits.nextBit(i+1)) ...
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 8032
diff changeset
   326
     *  }</pre>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
    public int nextBit(int x) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   329
        Assert.check(currentState != BitsState.UNKNOWN);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        int windex = x >>> wordshift;
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   331
        if (windex >= bits.length) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   332
            return -1;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   333
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        int word = bits[windex] & ~((1 << (x & wordmask))-1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        while (true) {
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   336
            if (word != 0) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                return (windex << wordshift) + trailingZeroBits(word);
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   338
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            windex++;
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   340
            if (windex >= bits.length) {
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   341
                return -1;
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   342
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
            word = bits[windex];
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
    /** a string representation of this set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
     */
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   349
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
    public String toString() {
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   351
        if (bits != null && bits.length > 0) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   352
            char[] digits = new char[bits.length * wordlen];
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   353
            for (int i = 0; i < bits.length * wordlen; i++) {
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   354
                digits[i] = isMember(i) ? '1' : '0';
19941
8b91e8eb2d20 7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents: 17282
diff changeset
   355
            }
17282
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   356
            return new String(digits);
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   357
        } else {
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   358
            return "[]";
c6964ad7df63 8008562: javac, a refactoring to Bits is necessary in order to provide a change history
vromero
parents: 14049
diff changeset
   359
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
}