001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.schematic.document;
017
018import org.modeshape.schematic.annotation.Immutable;
019
020@Immutable
021public final class MaxKey {
022
023    /**
024     * The largest UTF-8 character that will fit into 2 bytes is U+07FF. Therefore, if we make a string that contains a (non
025     * UTF-8) unicode character larger than this, that string should always be treated as larger than all UTF-8 strings.
026     */
027    private static final String MAX_KEY_VALUE = new String(new char[] {'\u07FF' + 1});
028
029    protected static final MaxKey INSTANCE = new MaxKey();
030
031    public static final MaxKey getInstance() {
032        return INSTANCE;
033    }
034
035    private MaxKey() {
036        // prevent instantiation
037    }
038
039    @Override
040    public int hashCode() {
041        return MAX_KEY_VALUE.hashCode();
042    }
043
044    @Override
045    public boolean equals( Object obj ) {
046        return obj == this || obj instanceof MaxKey;
047    }
048
049    @Override
050    public String toString() {
051        return "MaxKey";
052    }
053
054    /**
055     * There should only be on instance of this (though there may be others due to serialization).
056     */
057    @Override
058    protected final Object clone() {
059        return INSTANCE;
060    }
061}