1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.fourthline.cling.support.model.dlna;
16
17 import java.util.EnumSet;
18 import java.util.Locale;
19
20
21
22
23 public class DLNAOperationsAttribute extends DLNAAttribute<EnumSet<DLNAOperations>> {
24
25 public DLNAOperationsAttribute() {
26 setValue(EnumSet.of(DLNAOperations.NONE));
27 }
28
29 public DLNAOperationsAttribute(DLNAOperations... op) {
30 if (op != null && op.length > 0) {
31 DLNAOperations first = op[0];
32 if (op.length > 1) {
33 System.arraycopy(op, 1, op, 0, op.length - 1);
34 setValue(EnumSet.of(first, op));
35 } else {
36 setValue(EnumSet.of(first));
37 }
38 }
39 }
40
41 public void setString(String s, String cf) throws InvalidDLNAProtocolAttributeException {
42 EnumSet<DLNAOperations> value = EnumSet.noneOf(DLNAOperations.class);
43 try {
44 int parseInt = Integer.parseInt(s, 16);
45 for (DLNAOperations op : DLNAOperations.values()) {
46 int code = op.getCode() & parseInt;
47 if (op != DLNAOperations.NONE && (op.getCode() == code)) {
48 value.add(op);
49 }
50 }
51 } catch (NumberFormatException numberFormatException) {
52 }
53
54 if (value.isEmpty())
55 throw new InvalidDLNAProtocolAttributeException("Can't parse DLNA operations integer from: " + s);
56
57 setValue(value);
58 }
59
60 public String getString() {
61 int code = DLNAOperations.NONE.getCode();
62 for (DLNAOperations op : getValue()) {
63 code |= op.getCode();
64 }
65 return String.format(Locale.ROOT, "%02x", code);
66 }
67 }