1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.support.renderingcontrol.lastchange;
17
18 import org.fourthline.cling.model.types.Datatype;
19 import org.fourthline.cling.model.types.InvalidValueException;
20 import org.fourthline.cling.model.types.UnsignedIntegerTwoBytes;
21 import org.fourthline.cling.model.types.UnsignedIntegerTwoBytesDatatype;
22 import org.fourthline.cling.support.lastchange.EventedValue;
23 import org.fourthline.cling.support.model.Channel;
24 import org.fourthline.cling.support.shared.AbstractMap;
25
26 import java.util.Map;
27
28
29
30
31 public class EventedValueChannelVolumeDB extends EventedValue<ChannelVolumeDB> {
32
33 public EventedValueChannelVolumeDB(ChannelVolumeDB value) {
34 super(value);
35 }
36
37 public EventedValueChannelVolumeDB(Map.Entry<String, String>[] attributes) {
38 super(attributes);
39 }
40
41 @Override
42 protected ChannelVolumeDB valueOf(Map.Entry<String, String>[] attributes) throws InvalidValueException {
43 Channel channel = null;
44 Integer volumeDB = null;
45 for (Map.Entry<String, String> attribute : attributes) {
46 if (attribute.getKey().equals("channel"))
47 channel = Channel.valueOf(attribute.getValue());
48 if (attribute.getKey().equals("val"))
49 volumeDB = (new UnsignedIntegerTwoBytesDatatype()
50 .valueOf(attribute.getValue()))
51 .getValue().intValue();
52 }
53 return channel != null && volumeDB != null ? new ChannelVolumeDB(channel, volumeDB) : null;
54 }
55
56 @Override
57 public Map.Entry<String, String>[] getAttributes() {
58 return new Map.Entry[]{
59 new AbstractMap.SimpleEntry<>(
60 "val",
61 new UnsignedIntegerTwoBytesDatatype().getString(
62 new UnsignedIntegerTwoBytes(getValue().getVolumeDB())
63 )
64 ),
65 new AbstractMap.SimpleEntry<>(
66 "channel",
67 getValue().getChannel().name()
68 )
69 };
70 }
71
72 @Override
73 public String toString() {
74 return getValue().toString();
75 }
76
77 @Override
78 protected Datatype getDatatype() {
79 return null;
80 }
81 }