1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.dx.rop.cst; 18 19/** 20 * Constants which are literal 32-bit values of some sort. 21 */ 22public abstract class CstLiteral32 23 extends CstLiteralBits { 24 /** the value as {@code int} bits */ 25 private final int bits; 26 27 /** 28 * Constructs an instance. 29 * 30 * @param bits the value as {@code int} bits 31 */ 32 /*package*/ CstLiteral32(int bits) { 33 this.bits = bits; 34 } 35 36 /** {@inheritDoc} */ 37 @Override 38 public final boolean equals(Object other) { 39 return (other != null) && 40 (getClass() == other.getClass()) && 41 bits == ((CstLiteral32) other).bits; 42 } 43 44 /** {@inheritDoc} */ 45 @Override 46 public final int hashCode() { 47 return bits; 48 } 49 50 /** {@inheritDoc} */ 51 @Override 52 protected int compareTo0(Constant other) { 53 int otherBits = ((CstLiteral32) other).bits; 54 55 if (bits < otherBits) { 56 return -1; 57 } else if (bits > otherBits) { 58 return 1; 59 } else { 60 return 0; 61 } 62 } 63 64 /** {@inheritDoc} */ 65 @Override 66 public final boolean isCategory2() { 67 return false; 68 } 69 70 /** {@inheritDoc} */ 71 @Override 72 public final boolean fitsInInt() { 73 return true; 74 } 75 76 /** {@inheritDoc} */ 77 @Override 78 public final int getIntBits() { 79 return bits; 80 } 81 82 /** {@inheritDoc} */ 83 @Override 84 public final long getLongBits() { 85 return (long) bits; 86 } 87} 88