/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. */
  24. package org.hudsonci.model.project.property;
  25. import hudson.util.DeepEquals;
  26. import hudson.util.DescribableList;
  27. import java.util.List;
  28. import org.apache.commons.collections.CollectionUtils;
  29. import org.hudsonci.api.model.ICascadingJob;
  30. /**
  31. * Property represents DescribableList object.
  32. * <p/>
  33. * Date: 10/3/11
  34. *
  35. * @author Nikita Levyankov
  36. */
  37. public class DescribableListProjectProperty extends BaseProjectProperty<DescribableList> {
  38. public DescribableListProjectProperty(ICascadingJob job) {
  39. super(job);
  40. }
  41. @Override
  42. public DescribableList getDefaultValue() {
  43. DescribableList result = new DescribableList(getJob());
  44. setOriginalValue(result, false);
  45. return result;
  46. }
  47. @Override
  48. public boolean allowOverrideValue(DescribableList cascadingValue, DescribableList candidateValue) {
  49. if (null == cascadingValue && null == candidateValue) {
  50. return false;
  51. }
  52. if (null != cascadingValue && null != candidateValue) {
  53. List cascadingList = cascadingValue.toList();
  54. List candidateList = candidateValue.toList();
  55. return !(CollectionUtils.isEqualCollection(cascadingList, candidateList) || DeepEquals.deepEquals(cascadingList, candidateList));
  56. }
  57. return true;
  58. }
  59. @Override
  60. protected boolean returnOriginalValue() {
  61. return isOverridden() || !getOriginalValue().isEmpty();
  62. }
  63. @Override
  64. public DescribableList getOriginalValue() {
  65. DescribableList result = super.getOriginalValue();
  66. return null != result ? result : getDefaultValue();
  67. }
  68. }