View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.panels;
20  
21  import java.io.Serializable;
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.List;
25  import java.util.stream.Collectors;
26  
27  public class ConfParam implements Serializable {
28  
29      private static final long serialVersionUID = -9162995157523535429L;
30  
31      private String schema;
32  
33      private final List<Serializable> values = new ArrayList<>();
34  
35      private boolean multivalue;
36  
37      public String getSchema() {
38          return schema;
39      }
40  
41      public void setSchema(final String schema) {
42          this.schema = schema;
43      }
44  
45      public List<Serializable> getValues() {
46          return values;
47      }
48  
49      public Object valueAsObject() {
50          return multivalue
51                  ? values
52                  : values.isEmpty()
53                  ? null
54                  : values.get(0);
55      }
56  
57      public void setValues(final Object value) {
58          this.values.clear();
59          if (value instanceof Collection) {
60              this.values.addAll(((Collection<?>) value).stream().
61                      filter(Serializable.class::isInstance).
62                      map(Serializable.class::cast).
63                      collect(Collectors.toList()));
64              this.multivalue = true;
65          } else {
66              this.values.add((Serializable) value);
67              this.multivalue = false;
68          }
69      }
70  
71      public void setMultivalue(final boolean multivalue) {
72          this.multivalue = multivalue;
73      }
74  
75      public boolean isMultivalue() {
76          return multivalue;
77      }
78  
79      public boolean isInstance(final Class<?> clazz) {
80          return !values.isEmpty() && clazz.isInstance(values.get(0));
81      }
82  
83      @Override
84      public String toString() {
85          return "ConfParam{"
86                  + "schema=" + schema
87                  + ", values=" + values
88                  + ", multivalue=" + multivalue
89                  + '}';
90      }
91  }