001// --------------------------------------------------------------------------------
002// Copyright 2002-2024 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.Iterator;
021import java.util.List;
022
023public class BaseChoicesBean implements Serializable {
024    
025    List<String> labels;
026    List<String> values;
027    String defaultValue;
028    
029    private void init(List<String> labels, List<String> values, String defaultValue) {
030        this.labels = labels;
031        this.values = values;
032        this.defaultValue = defaultValue;
033    }
034    
035    /** Creates a new instance of BaseChoicesBean. */
036    protected BaseChoicesBean(List<String> labels, List<String> values, String defaultValue) {
037        init(labels, values, defaultValue);
038    }
039    
040    /** Creates a new instance of BaseChoicesBean. */
041    protected BaseChoicesBean() {
042        init(null, null, null);
043    }
044    
045    public List<String> getLabels() {
046        return labels;
047    }
048    
049    public void setLabels(List<String> labels) {
050        this.labels = labels;
051    }
052    
053    public List<String> getValues() {
054        return values;
055    }
056    
057    public void setValues(List<String> values) {
058        this.values = values;
059    }
060    
061    public String getDefaultValue() {
062        return defaultValue;
063    }
064    
065    public void setDefaultValue(String defaultValue) {
066        this.defaultValue = defaultValue;
067    }
068    
069    @Override
070    public String toString() {
071        StringBuilder result = new StringBuilder();
072        Iterator<String> valueIter = values.iterator();
073
074        labels.stream().map((label) -> {
075            result.append('"').append(label).append(",\" \"").append(valueIter.next()).append('"');
076            return label;
077        }).filter((_item) -> valueIter.hasNext()).forEach((_item) -> {
078            result.append("; ");
079        });
080
081        return result.toString();
082    }
083
084}