1 package org.kuali.common.httplib.api.model; 2 3 import static org.kuali.common.jute.base.Precondition.checkNotBlank; 4 5 import org.apache.http.NameValuePair; 6 7 import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 8 9 @JsonDeserialize(builder = NameValue.Builder.class) 10 public final class NameValue implements NameValuePair { 11 12 private final String name; 13 private final String value; 14 15 private NameValue(Builder builder) { 16 this.name = builder.name; 17 this.value = builder.value; 18 } 19 20 public static NameValue build(String name, String value) { 21 return builder().withName(name).withValue(value).build(); 22 } 23 24 public static Builder builder() { 25 return new Builder(); 26 } 27 28 public static class Builder implements org.apache.commons.lang3.builder.Builder<NameValue> { 29 30 private String name; 31 private String value; 32 33 public Builder withName(String name) { 34 this.name = name; 35 return this; 36 } 37 38 public Builder withValue(String value) { 39 this.value = value; 40 return this; 41 } 42 43 @Override 44 public NameValue build() { 45 return validate(new NameValue(this)); 46 } 47 48 private static NameValue validate(NameValue instance) { 49 checkNotBlank(instance.name, "name"); 50 checkNotBlank(instance.value, "value"); 51 return instance; 52 } 53 } 54 55 @Override 56 public String getName() { 57 return name; 58 } 59 60 @Override 61 public String getValue() { 62 return value; 63 } 64 65 }