jaulib v1.3.0
Jau Support Library (C++, Java, ..)
UnmountFlags.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24package org.jau.fs;
25
26/**
27 * Generic flag bit class for umount() `flags`
28 *
29 * See umount(2) for a detailed description.
30 *
31 * @see FileUtil#umount(long, int)
32 * @see FileUtil#umount(String, int)
33 */
34public class UnmountFlags {
35
36 public static interface Bit {
37 String name();
38 int value();
39 }
40 public static enum Bit0 implements Bit {
41 none ( 0 );
42
43 Bit0(final int v) { _value = v; }
44 private int _value;
45
46 @Override
47 public int value() { return _value; }
48 }
49 protected Bit[] bit_values() { return Bit0.values(); }
50
51 private int mask;
52
53 public int value() { return mask; }
54
55 protected UnmountFlags(final int v) {
56 mask = v;
57 }
58 public UnmountFlags() {
59 mask = 0;
60 }
61
62 public boolean isSet(final Bit bit) { return bit.value() == ( mask & bit.value() ); }
63
64 public UnmountFlags set(final Bit bit) { mask = mask | bit.value(); return this; }
65
66 @Override
67 public String toString() {
68 int count = 0;
69 final StringBuilder out = new StringBuilder();
70 for (final Bit dt : bit_values()) {
71 if( 0 != dt.value() && isSet(dt) ) {
72 if( 0 < count ) { out.append(", "); }
73 out.append(dt.name()); count++;
74 }
75 }
76 if( 1 < count ) {
77 out.insert(0, "[");
78 out.append("]");
79 }
80 return out.toString();
81 }
82
83 @Override
84 public boolean equals(final Object other) {
85 if (this == other) {
86 return true;
87 }
88 return (other instanceof UnmountFlags) &&
89 this.mask == ((UnmountFlags)other).mask;
90 }
91}
Generic flag bit class for umount() flags
boolean equals(final Object other)
boolean isSet(final Bit bit)