| | |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.Map; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | |
| | |
| | | */ |
| | | public static enum Enum { |
| | | //@Checkstyle:off |
| | | /** @see ResultCode#UNDEFINED */ |
| | | UNDEFINED, |
| | | /** @see ResultCode#SUCCESS */ |
| | | SUCCESS, |
| | | /** @see ResultCode#OPERATIONS_ERROR */ |
| | |
| | | //@Checkstyle:on |
| | | } |
| | | |
| | | private static final ResultCode[] ELEMENTS = new ResultCode[16655]; |
| | | private static final Map<Integer, ResultCode> ELEMENTS = new LinkedHashMap<Integer, ResultCode>(); |
| | | |
| | | private static final List<ResultCode> IMMUTABLE_ELEMENTS = Collections.unmodifiableList(Arrays |
| | | .asList(ELEMENTS)); |
| | | private static final List<ResultCode> IMMUTABLE_ELEMENTS = Collections.unmodifiableList(new ArrayList<ResultCode>( |
| | | ELEMENTS.values())); |
| | | |
| | | /** |
| | | * The result code that should only be used if the actual result code has |
| | | * not yet been determined. |
| | | * <p> |
| | | * Despite not being a standard result code, it is an implementation of the |
| | | * null object design pattern for this type. |
| | | */ |
| | | public static final ResultCode UNDEFINED = registerErrorResultCode(-1, |
| | | INFO_RESULT_UNDEFINED.get(), Enum.UNDEFINED); |
| | | |
| | | /** |
| | | * The result code that indicates that the operation completed successfully. |
| | |
| | | * @return The result code. |
| | | */ |
| | | public static ResultCode valueOf(final int intValue) { |
| | | ResultCode result = null; |
| | | if (0 <= intValue && intValue < ELEMENTS.length) { |
| | | result = ELEMENTS[intValue]; |
| | | } |
| | | ResultCode result = ELEMENTS.get(intValue); |
| | | if (result == null) { |
| | | result = new ResultCode( |
| | | intValue, LocalizableMessage.raw("unknown(" + intValue + ")"), true, Enum.UNKNOWN); |
| | |
| | | private static ResultCode registerErrorResultCode(final int intValue, |
| | | final LocalizableMessage name, final Enum resultCodeEnum) { |
| | | final ResultCode t = new ResultCode(intValue, name, true, resultCodeEnum); |
| | | ELEMENTS[intValue] = t; |
| | | ELEMENTS.put(intValue, t); |
| | | return t; |
| | | } |
| | | |
| | |
| | | private static ResultCode registerSuccessResultCode(final int intValue, |
| | | final LocalizableMessage name, final Enum resultCodeEnum) { |
| | | final ResultCode t = new ResultCode(intValue, name, false, resultCodeEnum); |
| | | ELEMENTS[intValue] = t; |
| | | ELEMENTS.put(intValue, t); |
| | | return t; |
| | | } |
| | | |