OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.mojo.system; |
| 6 |
| 7 /** |
| 8 * Base class for bit field used as flags. |
| 9 * |
| 10 * @param <F> the type of the flags. |
| 11 */ |
| 12 public abstract class Flags<F extends Flags<F>> { |
| 13 private int mFlags; |
| 14 |
| 15 /** |
| 16 * Dedicated constructor. |
| 17 * |
| 18 * @param flags initial value of the flag. |
| 19 */ |
| 20 protected Flags(int flags) { |
| 21 mFlags = flags; |
| 22 } |
| 23 |
| 24 /** |
| 25 * @return the computed flag. |
| 26 */ |
| 27 public int getFlags() { |
| 28 return mFlags; |
| 29 } |
| 30 |
| 31 /** |
| 32 * Change the given bit of this flag. |
| 33 * |
| 34 * @param value the new value of given bit. |
| 35 * @return this. |
| 36 */ |
| 37 protected F setFlag(int flag, boolean value) { |
| 38 if (value) { |
| 39 mFlags |= flag; |
| 40 } else { |
| 41 mFlags &= ~flag; |
| 42 } |
| 43 @SuppressWarnings("unchecked") |
| 44 F f = (F) this; |
| 45 return f; |
| 46 } |
| 47 |
| 48 } |
OLD | NEW |