001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016
017package com.echothree.view.common;
018
019import java.io.Serializable;
020import java.util.List;
021
022public class BaseChoicesBean implements Serializable {
023    
024    List<String> labels;
025    List<String> values;
026    String defaultValue;
027    
028    private void init(List<String> labels, List<String> values, String defaultValue) {
029        this.labels = labels;
030        this.values = values;
031        this.defaultValue = defaultValue;
032    }
033    
034    /** Creates a new instance of BaseChoicesBean. */
035    protected BaseChoicesBean(List<String> labels, List<String> values, String defaultValue) {
036        init(labels, values, defaultValue);
037    }
038    
039    /** Creates a new instance of BaseChoicesBean. */
040    protected BaseChoicesBean() {
041        init(null, null, null);
042    }
043    
044    public List<String> getLabels() {
045        return labels;
046    }
047    
048    public void setLabels(List<String> labels) {
049        this.labels = labels;
050    }
051    
052    public List<String> getValues() {
053        return values;
054    }
055    
056    public void setValues(List<String> values) {
057        this.values = values;
058    }
059    
060    public String getDefaultValue() {
061        return defaultValue;
062    }
063    
064    public void setDefaultValue(String defaultValue) {
065        this.defaultValue = defaultValue;
066    }
067    
068    @Override
069    public String toString() {
070        var result = new StringBuilder();
071        var valueIter = values.iterator();
072
073        labels.stream().map((label) -> {
074            result.append('"').append(label).append(",\" \"").append(valueIter.next()).append('"');
075            return label;
076        }).filter((_item) -> valueIter.hasNext()).forEach((_item) -> {
077            result.append("; ");
078        });
079
080        return result.toString();
081    }
082
083}