<commit_before>/**
 * Copyright (C) 2012 Ness Computing, Inc.
 *
 * Licensed 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 com.nesscomputing.uuid;

import java.util.UUID;

public class NessUUID {
    private NessUUID() {}

    private static final byte[] CHAR_MAP = new byte[Character.MAX_VALUE];

    static {
        for (int i = 0; i < Character.MAX_VALUE; i++) {
            CHAR_MAP[i] = -1;
        }
        initCharMap('a', 'f', 10);
        initCharMap('A', 'F', 10);
        initCharMap('0', '9', 0);
    }

    public static UUID fromString(String str) {
        if (str.length() != 36 ||
            str.charAt(8) != '-' ||
            str.charAt(13) != '-' ||<commit_msg>Added javadoc to explain the reasoning behind writing an alternative to UUID.fromString<commit_after>/**
 * Copyright (C) 2012 Ness Computing, Inc.
 *
 * Licensed 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 com.nesscomputing.uuid;

import java.util.UUID;


/**
 * A class that provides an alternate implementation of {@link
 * java.util.UUID#fromString(String)}.
 *
 * <p> The version in the JDK uses {@link java.lang.String#split(String)}
 * which does not compile the regular expression that is used for splitting
 * the UUID string and results in the allocation of multiple strings in a
 * string array. We decided to write {@link NessUUID} when we ran into
 * performance issues with the garbage produced by {@link
 * java.util.UUID#fromString(String)}.
 *
 */
public class NessUUID {
    private NessUUID() {}

    private static final byte[] CHAR_MAP = new byte[Character.MAX_VALUE];

    static {
        for (int i = 0; i < Character.MAX_VALUE; i++) {
            CHAR_MAP[i] = -1;
        }
        initCharMap('a', 'f', 10);
        initCharMap('A', 'F', 10);
        initCharMap('0', '9', 0);
    }

    public static UUID fromString(String str) {
        if (str.length() != 36 ||
            str.charAt(8) != '-' ||
            str.charAt(13) != '-' ||
{'fraction_non_alphanumeric': 0.11279972982100642, 'fraction_numerical': 0.01485984464707869, 'mean_word_length': 3.0189959294436908, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7091', 'n_tokens_mistral': 873, 'n_tokens_neox': 837, 'n_words': 336}