Home | History | Annotate | Download | only in state
      1 /*
      2  * Copyright (C) 2014 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.ide.eclipse.gltrace.state;
     18 
     19 /** Properties that hold a long value. */
     20 public class GLLongProperty extends GLAbstractAtomicProperty {
     21     private final Long mDefaultValue;
     22     private Long mCurrentValue;
     23     private final DisplayRadix mRadix;
     24 
     25     public GLLongProperty(GLStateType name, Long defaultValue, DisplayRadix radix) {
     26         super(name);
     27 
     28         mDefaultValue = mCurrentValue = defaultValue;
     29         mRadix = radix;
     30     }
     31 
     32     public GLLongProperty(GLStateType name, Long defaultValue) {
     33         this(name, defaultValue, DisplayRadix.DECIMAL);
     34     }
     35 
     36     @Override
     37     public boolean isDefault() {
     38         return mDefaultValue != null & mDefaultValue.equals(mCurrentValue);
     39     }
     40 
     41     public void setValue(Long newValue) {
     42         mCurrentValue = newValue;
     43     }
     44 
     45     @Override
     46     public String getStringValue() {
     47         if (mRadix == DisplayRadix.HEX) {
     48             return String.format("0x%08x", Long.valueOf(mCurrentValue));
     49         }
     50 
     51         return mCurrentValue.toString();
     52     }
     53 
     54     @Override
     55     public String toString() {
     56         return getType() + "=" + getStringValue(); //$NON-NLS-1$
     57     }
     58 
     59     @Override
     60     public void setValue(Object value) {
     61         if (value instanceof Long) {
     62             mCurrentValue = (Long) value;
     63         } else {
     64             throw new IllegalArgumentException("Attempt to set non-integer value for " //$NON-NLS-1$
     65                                     + getType());
     66         }
     67     }
     68 
     69     @Override
     70     public Object getValue() {
     71         return mCurrentValue;
     72     }
     73 }
     74