001 002package com.commercetools.api.models.error; 003 004import java.util.*; 005 006import javax.annotation.Nullable; 007 008import io.vrap.rmf.base.client.Builder; 009import io.vrap.rmf.base.client.utils.Generated; 010 011/** 012 * ExtensionErrorBuilder 013 * <hr> 014 * Example to create an instance using the builder pattern 015 * <div class=code-example> 016 * <pre><code class='java'> 017 * ExtensionError extensionError = ExtensionError.builder() 018 * .code("{code}") 019 * .message("{message}") 020 * .extensionId("{extensionId}") 021 * .build() 022 * </code></pre> 023 * </div> 024 */ 025@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 026public class ExtensionErrorBuilder implements Builder<ExtensionError> { 027 028 private String code; 029 030 private String message; 031 032 private String extensionId; 033 034 @Nullable 035 private String extensionKey; 036 037 private Map<String, java.lang.Object> values = new HashMap<>(); 038 039 /** 040 * <p>Error code caused by the Extension. For example, <code>InvalidField</code>.</p> 041 * @param code value to be set 042 * @return Builder 043 */ 044 045 public ExtensionErrorBuilder code(final String code) { 046 this.code = code; 047 return this; 048 } 049 050 /** 051 * <p>Plain text description of the error.</p> 052 * @param message value to be set 053 * @return Builder 054 */ 055 056 public ExtensionErrorBuilder message(final String message) { 057 this.message = message; 058 return this; 059 } 060 061 /** 062 * <p>Unique identifier of the Extension.</p> 063 * @param extensionId value to be set 064 * @return Builder 065 */ 066 067 public ExtensionErrorBuilder extensionId(final String extensionId) { 068 this.extensionId = extensionId; 069 return this; 070 } 071 072 /** 073 * <p>User-defined unique identifier of the Extension.</p> 074 * @param extensionKey value to be set 075 * @return Builder 076 */ 077 078 public ExtensionErrorBuilder extensionKey(@Nullable final String extensionKey) { 079 this.extensionKey = extensionKey; 080 return this; 081 } 082 083 /** 084 * <p>Error-specific additional fields.</p> 085 * @param values properties to be set 086 * @return Builder 087 */ 088 089 public ExtensionErrorBuilder values(final Map<String, java.lang.Object> values) { 090 this.values = values; 091 return this; 092 } 093 094 /** 095 * <p>Error-specific additional fields.</p> 096 * @param key property name 097 * @param value property value 098 * @return Builder 099 */ 100 101 public ExtensionErrorBuilder addValue(final String key, final java.lang.Object value) { 102 if (this.values == null) { 103 values = new HashMap<>(); 104 } 105 values.put(key, value); 106 return this; 107 } 108 109 /** 110 * <p>Error code caused by the Extension. For example, <code>InvalidField</code>.</p> 111 * @return code 112 */ 113 114 public String getCode() { 115 return this.code; 116 } 117 118 /** 119 * <p>Plain text description of the error.</p> 120 * @return message 121 */ 122 123 public String getMessage() { 124 return this.message; 125 } 126 127 /** 128 * <p>Unique identifier of the Extension.</p> 129 * @return extensionId 130 */ 131 132 public String getExtensionId() { 133 return this.extensionId; 134 } 135 136 /** 137 * <p>User-defined unique identifier of the Extension.</p> 138 * @return extensionKey 139 */ 140 141 @Nullable 142 public String getExtensionKey() { 143 return this.extensionKey; 144 } 145 146 /** 147 * <p>Error-specific additional fields.</p> 148 * @return pattern properties 149 */ 150 151 public Map<String, java.lang.Object> getValues() { 152 return this.values; 153 } 154 155 /** 156 * builds ExtensionError with checking for non-null required values 157 * @return ExtensionError 158 */ 159 public ExtensionError build() { 160 Objects.requireNonNull(code, ExtensionError.class + ": code is missing"); 161 Objects.requireNonNull(message, ExtensionError.class + ": message is missing"); 162 Objects.requireNonNull(extensionId, ExtensionError.class + ": extensionId is missing"); 163 return new ExtensionErrorImpl(code, message, extensionId, extensionKey, values); 164 } 165 166 /** 167 * builds ExtensionError without checking for non-null required values 168 * @return ExtensionError 169 */ 170 public ExtensionError buildUnchecked() { 171 return new ExtensionErrorImpl(code, message, extensionId, extensionKey, values); 172 } 173 174 /** 175 * factory method for an instance of ExtensionErrorBuilder 176 * @return builder 177 */ 178 public static ExtensionErrorBuilder of() { 179 return new ExtensionErrorBuilder(); 180 } 181 182 /** 183 * create builder for ExtensionError instance 184 * @param template instance with prefilled values for the builder 185 * @return builder 186 */ 187 public static ExtensionErrorBuilder of(final ExtensionError template) { 188 ExtensionErrorBuilder builder = new ExtensionErrorBuilder(); 189 builder.code = template.getCode(); 190 builder.message = template.getMessage(); 191 builder.extensionId = template.getExtensionId(); 192 builder.extensionKey = template.getExtensionKey(); 193 builder.values = template.values(); 194 return builder; 195 } 196 197}