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 17 package com.android.dx.rop.cst; 18 19 /** 20 * Constants which are literal 64-bit values of some sort. 21 */ 22 public abstract class CstLiteral64 23 extends CstLiteralBits { 24 /** the value as {@code long} bits */ 25 private final long bits; 26 27 /** 28 * Constructs an instance. 29 * 30 * @param bits the value as {@code long} bits 31 */ CstLiteral64(long bits)32 /*package*/ CstLiteral64(long bits) { 33 this.bits = bits; 34 } 35 36 /** {@inheritDoc} */ 37 @Override equals(Object other)38 public final boolean equals(Object other) { 39 return (other != null) && 40 (getClass() == other.getClass()) && 41 bits == ((CstLiteral64) other).bits; 42 } 43 44 /** {@inheritDoc} */ 45 @Override hashCode()46 public final int hashCode() { 47 return (int) bits ^ (int) (bits >> 32); 48 } 49 50 /** {@inheritDoc} */ 51 @Override compareTo0(Constant other)52 protected int compareTo0(Constant other) { 53 long otherBits = ((CstLiteral64) 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 isCategory2()66 public final boolean isCategory2() { 67 return true; 68 } 69 70 /** {@inheritDoc} */ 71 @Override fitsInInt()72 public final boolean fitsInInt() { 73 return (int) bits == bits; 74 } 75 76 /** {@inheritDoc} */ 77 @Override getIntBits()78 public final int getIntBits() { 79 return (int) bits; 80 } 81 82 /** {@inheritDoc} */ 83 @Override getLongBits()84 public final long getLongBits() { 85 return bits; 86 } 87 } 88