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.model.types;
17  
18  import org.fourthline.cling.model.ModelUtil;
19  
20  import java.util.Arrays;
21  
22  /**
23   * An arbitrary list of comma-separated elements, representing DLNA capabilities (whatever that is).
24   *
25   * @author Christian Bauer
26   */
27  public class DLNACaps {
28  
29      final String[] caps;
30  
31      public DLNACaps(String[] caps) {
32          this.caps = caps;
33      }
34  
35      public String[] getCaps() {
36          return caps;
37      }
38  
39      static public DLNACaps valueOf(String s) throws InvalidValueException {
40          if (s == null || s.length() == 0) return new DLNACaps(new String[0]);
41          String[] caps = s.split(",");
42          String[] trimmed = new String[caps.length];
43          for (int i = 0; i < caps.length; i++) {
44              trimmed[i] = caps[i].trim();
45          }
46          return new DLNACaps(trimmed);
47      }
48  
49      @Override
50      public boolean equals(Object o) {
51          if (this == o) return true;
52          if (o == null || getClass() != o.getClass()) return false;
53  
54          DLNACaps dlnaCaps = (DLNACaps) o;
55  
56          if (!Arrays.equals(caps, dlnaCaps.caps)) return false;
57  
58          return true;
59      }
60  
61      @Override
62      public int hashCode() {
63          return Arrays.hashCode(caps);
64      }
65  
66      @Override
67      public String toString() {
68          return ModelUtil.toCommaSeparatedList(getCaps());
69      }
70  }