PageRenderTime 20ms CodeModel.GetById 15ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/hudson-core/src/main/java/org/hudsonci/model/project/property/DescribableListProjectProperty.java

http://github.com/hudson/hudson
Java | 75 lines | 38 code | 7 blank | 30 comment | 11 complexity | dba01db7f4135f80543556a0f408c667 MD5 | raw file
 1/*
 2 * The MIT License
 3 *
 4 * Copyright (c) 2011, Oracle Corporation, Nikita Levyankov
 5 *
 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
 7 * of this software and associated documentation files (the "Software"), to deal
 8 * in the Software without restriction, including without limitation the rights
 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24package org.hudsonci.model.project.property;
25
26import hudson.util.DeepEquals;
27import hudson.util.DescribableList;
28import java.util.List;
29import org.apache.commons.collections.CollectionUtils;
30import org.hudsonci.api.model.ICascadingJob;
31
32/**
33 * Property represents DescribableList object.
34 * <p/>
35 * Date: 10/3/11
36 *
37 * @author Nikita Levyankov
38 */
39public class DescribableListProjectProperty extends BaseProjectProperty<DescribableList> {
40    public DescribableListProjectProperty(ICascadingJob job) {
41        super(job);
42    }
43
44    @Override
45    public DescribableList getDefaultValue() {
46        DescribableList result = new DescribableList(getJob());
47        setOriginalValue(result, false);
48        return result;
49    }
50
51    @Override
52    public boolean allowOverrideValue(DescribableList cascadingValue, DescribableList candidateValue) {
53        if (null == cascadingValue && null == candidateValue) {
54            return false;
55        }
56        if (null != cascadingValue && null != candidateValue) {
57            List cascadingList = cascadingValue.toList();
58            List candidateList = candidateValue.toList();
59            return !(CollectionUtils.isEqualCollection(cascadingList, candidateList) || DeepEquals.deepEquals(cascadingList, candidateList));
60
61        }
62        return true;
63    }
64
65    @Override
66    protected boolean returnOriginalValue() {
67        return isOverridden() || !getOriginalValue().isEmpty();
68    }
69
70    @Override
71    public DescribableList getOriginalValue() {
72        DescribableList result = super.getOriginalValue();
73        return null != result ? result : getDefaultValue();
74    }
75}