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.binding.staging;
17  
18  import org.fourthline.cling.model.meta.StateVariable;
19  import org.fourthline.cling.model.meta.StateVariableAllowedValueRange;
20  import org.fourthline.cling.model.meta.StateVariableEventDetails;
21  import org.fourthline.cling.model.meta.StateVariableTypeDetails;
22  import org.fourthline.cling.model.types.Datatype;
23  
24  import java.util.List;
25  
26  /**
27   * @author Christian Bauer
28   */
29  public class MutableStateVariable {
30  
31      public String name;
32      public Datatype dataType;
33      public String defaultValue;
34      public List<String> allowedValues;
35      public MutableAllowedValueRange allowedValueRange;
36      public StateVariableEventDetails eventDetails;
37  
38      public StateVariable build() {
39          return new StateVariable(
40                  name,
41                  new StateVariableTypeDetails(
42                          dataType,
43                          defaultValue,
44                          allowedValues == null || allowedValues.size() == 0
45                                  ? null
46                                  : allowedValues.toArray(new String[allowedValues.size()]),
47                          allowedValueRange == null
48                                  ? null :
49                                  new StateVariableAllowedValueRange(
50                                          allowedValueRange.minimum,
51                                          allowedValueRange.maximum,
52                                          allowedValueRange.step
53                                  )
54                  ),
55                  eventDetails
56          );
57      }
58  }