1/*
2 * Copyright (C) 2012 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.ide.eclipse.gltrace.state;
18
19import com.google.common.base.Joiner;
20
21import java.util.List;
22
23public class GLObjectProperty extends GLAbstractAtomicProperty {
24    private final Object mDefaultValue;
25    private Object mCurrentValue;
26
27    private static final Joiner JOINER = Joiner.on(", ");   //$NON-NLS-1$
28
29    public GLObjectProperty(GLStateType type, Object defaultValue) {
30        super(type);
31
32        mDefaultValue = mCurrentValue = defaultValue;
33    }
34
35    @Override
36    public boolean isDefault() {
37        return mDefaultValue == mCurrentValue;
38    }
39
40    @Override
41    public void setValue(Object newValue) {
42        mCurrentValue = newValue;
43    }
44
45    @Override
46    public String getStringValue() {
47        if (mCurrentValue == null) {
48            return "null";
49        } else {
50            if (mCurrentValue instanceof List<?>) {
51                return "[" + JOINER.join((List<?>) mCurrentValue) + "]"; //$NON-NLS-1$ //$NON-NLS-2$
52            }
53            return mCurrentValue.toString();
54        }
55    }
56
57    @Override
58    public String toString() {
59        return getType() + "=" + getStringValue(); //$NON-NLS-1$
60    }
61
62    @Override
63    public Object getValue() {
64        return mCurrentValue;
65    }
66}
67