fbshipit-source-id: b6fc29740c6875d2e78953b8a7123890a67930f2 Co-authored-by: Sebastian McKenzie <sebmck@fb.com> Co-authored-by: John Knox <jknox@fb.com> Co-authored-by: Emil Sjölander <emilsj@fb.com> Co-authored-by: Pritesh Nandgaonkar <prit91@fb.com>
52 lines
1.4 KiB
Java
52 lines
1.4 KiB
Java
/*
|
|
* Copyright (c) 2018-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the LICENSE
|
|
* file in the root directory of this source tree.
|
|
*
|
|
*/
|
|
|
|
package com.facebook.sonar.plugins.inspector.descriptors.utils;
|
|
|
|
import static com.facebook.sonar.plugins.inspector.InspectorValue.Type.Enum;
|
|
|
|
import android.support.v4.util.SimpleArrayMap;
|
|
import com.facebook.sonar.plugins.inspector.InspectorValue;
|
|
|
|
public class EnumMapping {
|
|
private final SimpleArrayMap<String, Integer> mMapping = new SimpleArrayMap<>();
|
|
private final String mDefaultKey;
|
|
|
|
public EnumMapping(String defaultKey) {
|
|
mDefaultKey = defaultKey;
|
|
}
|
|
|
|
public void put(String s, int i) {
|
|
mMapping.put(s, i);
|
|
}
|
|
|
|
public InspectorValue get(final int i) {
|
|
return get(i, true);
|
|
}
|
|
|
|
public InspectorValue get(final int i, final boolean mutable) {
|
|
for (int ii = 0, count = mMapping.size(); ii < count; ii++) {
|
|
if (mMapping.valueAt(ii) == i) {
|
|
return mutable
|
|
? InspectorValue.mutable(Enum, mMapping.keyAt(ii))
|
|
: InspectorValue.immutable(Enum, mMapping.keyAt(ii));
|
|
}
|
|
}
|
|
return mutable
|
|
? InspectorValue.mutable(Enum, mDefaultKey)
|
|
: InspectorValue.immutable(Enum, mDefaultKey);
|
|
}
|
|
|
|
public int get(String s) {
|
|
if (mMapping.containsKey(s)) {
|
|
return mMapping.get(s);
|
|
}
|
|
return mMapping.get(mDefaultKey);
|
|
}
|
|
}
|