View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.support.renderingcontrol.lastchange;
17  
18  import org.fourthline.cling.model.types.BooleanDatatype;
19  import org.fourthline.cling.model.types.Datatype;
20  import org.fourthline.cling.model.types.InvalidValueException;
21  import org.fourthline.cling.support.lastchange.EventedValue;
22  import org.fourthline.cling.support.model.Channel;
23  import org.fourthline.cling.support.shared.AbstractMap;
24  
25  import java.util.Map;
26  
27  /**
28   * @author Christian Bauer
29   */
30  public class EventedValueChannelMute extends EventedValue<ChannelMute> {
31  
32      public EventedValueChannelMute(ChannelMute value) {
33          super(value);
34      }
35  
36      public EventedValueChannelMute(Map.Entry<String, String>[] attributes) {
37          super(attributes);
38      }
39  
40      @Override
41      protected ChannelMute valueOf(Map.Entry<String, String>[] attributes) throws InvalidValueException {
42          Channel channel = null;
43          Boolean mute = null;
44          for (Map.Entry<String, String> attribute : attributes) {
45              if (attribute.getKey().equals("channel"))
46                  channel = Channel.valueOf(attribute.getValue());
47              if (attribute.getKey().equals("val"))
48                  mute = new BooleanDatatype().valueOf(attribute.getValue());
49          }
50          return channel != null && mute != null ? new ChannelMute(channel, mute) : null;
51      }
52  
53      @Override
54      public Map.Entry<String, String>[] getAttributes() {
55          return new Map.Entry[]{
56                  new AbstractMap.SimpleEntry<>(
57                          "val",
58                          new BooleanDatatype().getString(getValue().getMute())
59                  ),
60                  new AbstractMap.SimpleEntry<>(
61                          "channel",
62                          getValue().getChannel().name()
63                  )
64          };
65      }
66  
67      @Override
68      public String toString() {
69          return getValue().toString();
70      }
71  
72      @Override
73      protected Datatype getDatatype() {
74          return null; // Not needed
75      }
76  }