| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.sdk.internal.protocolparser; | 5 package org.chromium.sdk.internal.protocolparser; |
| 6 | 6 |
| 7 import java.util.EnumSet; |
| 7 import java.util.Set; | 8 import java.util.Set; |
| 8 | 9 |
| 9 /** | 10 /** |
| 10 * Implementation of {@link JsonValueCondition} for enum-typed values. | 11 * Implementation of {@link JsonValueCondition} for enum-typed values. |
| 11 * User is supposed to subclass it and specify allowed enum constants in constru
ctor. | 12 * User is supposed to subclass it and specify allowed enum constants in constru
ctor. |
| 12 * @param <T> type of value | 13 * @param <T> type of value |
| 13 */ | 14 */ |
| 14 public abstract class EnumValueCondition<T extends Enum<T>> implements JsonValue
Condition<T> { | 15 public abstract class EnumValueCondition<T extends Enum<T>> implements JsonValue
Condition<T> { |
| 15 private final Set<T> allowedValues; | 16 private final Set<T> allowedValues; |
| 16 protected EnumValueCondition(Set<T> allowedValues) { | 17 protected EnumValueCondition(Set<T> allowedValues) { |
| 17 this.allowedValues = allowedValues; | 18 this.allowedValues = allowedValues; |
| 18 } | 19 } |
| 20 protected EnumValueCondition(T singleAllowedValues) { |
| 21 this.allowedValues = EnumSet.<T>of(singleAllowedValues); |
| 22 } |
| 19 | 23 |
| 20 public boolean conforms(T value) { | 24 public boolean conforms(T value) { |
| 21 return allowedValues.contains(value); | 25 return allowedValues.contains(value); |
| 22 } | 26 } |
| 23 | 27 |
| 24 public static String decorateEnumConstantName(String enumValue) { | 28 public static String decorateEnumConstantName(String enumValue) { |
| 25 return enumValue.toUpperCase().replace("-", "_"); | 29 return enumValue.toUpperCase().replace("-", "_"); |
| 26 } | 30 } |
| 27 } | 31 } |
| OLD | NEW |