1 /* 2 * Copyright (C) 2011-2014 eXo Platform SAS. 3 * 4 * This file is part of eXo Acceptance Webapp. 5 * 6 * eXo Acceptance Webapp is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as 8 * published by the Free Software Foundation; either version 3 of 9 * the License, or (at your option) any later version. 10 * 11 * eXo Acceptance Webapp software is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with eXo Acceptance Webapp; if not, write to the Free 18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 19 * 02110-1301 USA, or see <http://www.gnu.org/licenses/>. 20 */ 21 package org.exoplatform.acceptance.model.vcs; 22 23 import com.fasterxml.jackson.annotation.JsonCreator; 24 import com.fasterxml.jackson.annotation.JsonProperty; 25 import com.google.common.base.Function; 26 import com.google.common.base.Objects; 27 import com.google.common.base.Predicate; 28 import com.google.common.collect.Ordering; 29 import javax.validation.constraints.NotNull; 30 31 /** 32 * <p>VCSRef class.</p> 33 * 34 * @author Arnaud Héritier ( aheritier@exoplatform.com ) 35 * @since 2.0.0 36 */ 37 public class VCSRef { 38 39 /** 40 * Constant <code>IS_TAG</code> 41 */ 42 public static final Predicate<VCSRef> IS_TAG = new Predicate<VCSRef>() { 43 @Override 44 // TODO : Juzu throws a NPE in live mode when using @Nullable annotation 45 //public boolean apply(@Nullable VCSRef input) { 46 public boolean apply(VCSRef input) { 47 return null != input && null != input.getType() && Type.TAG.equals(input.getType()); 48 } 49 }; 50 /** 51 * Constant <code>IS_BRANCH</code> 52 */ 53 public static final Predicate<VCSRef> IS_BRANCH = new Predicate<VCSRef>() { 54 @Override 55 // TODO : Juzu throws a NPE in live mode when using @Nullable annotation 56 //public boolean apply(@Nullable VCSRef input) { 57 public boolean apply(VCSRef input) { 58 return null != input && null != input.getType() && Type.BRANCH.equals(input.getType()); 59 } 60 }; 61 /** 62 * Constant <code>SORT_BY_NAME</code> 63 */ 64 public static final Ordering<VCSRef> SORT_BY_NAME = Ordering.natural().nullsFirst().onResultOf(new Function<VCSRef, String>() { 65 public String apply(VCSRef ref) { 66 return ref.getName(); 67 } 68 }); 69 @NotNull 70 private String name; 71 @NotNull 72 private String id; 73 /** 74 * The type of reference 75 */ 76 @NotNull 77 private Type type; 78 79 /** 80 * <p>Constructor for VCSRef.</p> 81 * 82 * @param type a {@link org.exoplatform.acceptance.model.vcs.VCSRef.Type} object. 83 * @param name a {@link java.lang.String} object. 84 * @param id a {@link java.lang.String} object. 85 */ 86 @JsonCreator 87 public VCSRef(@NotNull @JsonProperty("type") Type type, 88 @NotNull @JsonProperty("name") String name, 89 @NotNull @JsonProperty("id") String id) { 90 this.type = type; 91 this.name = name; 92 this.id = id; 93 } 94 95 /** 96 * <p>Getter for the field <code>name</code>.</p> 97 * 98 * @return a {@link java.lang.String} object. 99 */ 100 public String getName() { 101 return name; 102 } 103 104 /** 105 * <p>Setter for the field <code>name</code>.</p> 106 * 107 * @param name a {@link java.lang.String} object. 108 */ 109 public void setName(String name) { 110 this.name = name; 111 } 112 113 /** 114 * <p>Getter for the field <code>id</code>.</p> 115 * 116 * @return a {@link java.lang.String} object. 117 */ 118 public String getId() { 119 return id; 120 } 121 122 /** 123 * <p>Setter for the field <code>id</code>.</p> 124 * 125 * @param id a {@link java.lang.String} object. 126 */ 127 public void setId(String id) { 128 this.id = id; 129 } 130 131 /** 132 * <p>Getter for the field <code>type</code>.</p> 133 * 134 * @return a {@link org.exoplatform.acceptance.model.vcs.VCSRef.Type} object. 135 */ 136 public Type getType() { 137 return type; 138 } 139 140 /** 141 * <p>Setter for the field <code>type</code>.</p> 142 * 143 * @param type a {@link org.exoplatform.acceptance.model.vcs.VCSRef.Type} object. 144 */ 145 public void setType(Type type) { 146 this.type = type; 147 } 148 149 /** 150 * {@inheritDoc} 151 */ 152 @Override 153 public String toString() { 154 return Objects.toStringHelper(this) 155 .add("type", type) 156 .add("name", name) 157 .add("id", id) 158 .toString(); 159 } 160 161 /** 162 * VCS Ref types 163 */ 164 public enum Type { 165 TAG, BRANCH 166 } 167 }