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.model;
17  
18  import org.fourthline.cling.model.ModelUtil;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  /**
24   *
25   */
26  public enum RecordQualityMode {
27  
28      EP("0:EP"),
29      LP("1:LP"),
30      SP("2:SP"),
31      BASIC("0:BASIC"),
32      MEDIUM("1:MEDIUM"),
33      HIGH("2:HIGH"),
34      NOT_IMPLEMENTED("NOT_IMPLEMENTED");
35  
36      private String protocolString;
37  
38      RecordQualityMode(String protocolString) {
39          this.protocolString = protocolString;
40      }
41  
42      @Override
43      public String toString() {
44          return protocolString;
45      }
46  
47      public static RecordQualityMode valueOrExceptionOf(String s) throws IllegalArgumentException {
48          for (RecordQualityMode recordQualityMode : values()) {
49              if (recordQualityMode.protocolString.equals(s)) {
50                  return recordQualityMode;
51              }
52          }
53          throw new IllegalArgumentException("Invalid record quality mode string: " + s);
54      }
55  
56      public static RecordQualityMode[] valueOfCommaSeparatedList(String s) {
57          String[] strings = ModelUtil.fromCommaSeparatedList(s);
58          if (strings == null) return new RecordQualityMode[0];
59          List<RecordQualityMode> result = new ArrayList<>();
60          for (String rqm : strings) {
61              for (RecordQualityMode recordQualityMode : values()) {
62                  if (recordQualityMode.protocolString.equals(rqm)) {
63                      result.add(recordQualityMode);
64                  }
65              }
66          }
67          return result.toArray(new RecordQualityMode[result.size()]);
68      }
69  }