sk0x50 commented on code in PR #904: URL: https://github.com/apache/ignite-3/pull/904#discussion_r909677881
########## modules/core/src/main/java/org/apache/ignite/lang/ErrorGroup.java: ########## @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.lang; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; + +/** + * This class represents a concept of error group. Error group defines a collection of errors that belong to a single semantic component. + * Each group can be identified by a name and an integer number that both must be unique across all error groups. + */ +public class ErrorGroup { + /** List of all registered error groups. */ + private static final List<ErrorGroup> registeredGroups = new ArrayList<>(); + + /** Group name. */ + private final String groupName; + + /** Group code. */ + private final int groupCode; + + /** Contains error codes for this error group. */ + private final Set<Integer> codes = new HashSet<>(); + + /** + * Creates a new error group with the specified name and corresponding code. + * + * @param groupName Group name. + * @param groupCode Group code. + */ + private ErrorGroup(String groupName, int groupCode) { + this.groupName = groupName; + this.groupCode = groupCode; + } + + /** + * Returns a name of this group. + * + * @return Group name. + */ + public String name() { + return groupName; + } + + /** + * Returns a code of this group. + * + * @return Group code. + */ + public int code() { + return groupCode; + } + + /** + * Registers a new error code within this error group. + * + * @param errorCode Error code to be registered. + * @return Full error code which includes group code and specific error code. + * @throws IllegalArgumentException If the given {@code errorCode} is already registered + * or {@code errorCode} is greater than 0xFFFF or less than or equal to 0. + */ + public int registerErrorCode(int errorCode) { + if (errorCode < 0 || errorCode > 0xFFFF) { + throw new IllegalArgumentException("Error code should be greater than 0 and less than or equal to 0xFFFF"); Review Comment: Yep, you are right. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
