001/* 002 * ============================================================================ 003 * Copyright © 2002-2026 by Thomas Thrien. 004 * All Rights Reserved. 005 * ============================================================================ 006 * 007 * Licensed to the public under the agreements of the GNU Lesser General Public 008 * License, version 3.0 (the "License"). You may obtain a copy of the License at 009 * 010 * http://www.gnu.org/licenses/lgpl.html 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 014 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 015 * License for the specific language governing permissions and limitations 016 * under the License. 017 */ 018 019package org.tquadrat.foundation.perflog.internal; 020 021import static java.lang.Integer.signum; 022import static org.apiguardian.api.API.Status.INTERNAL; 023import static org.tquadrat.foundation.lang.Objects.requireNonNullArgument; 024import static org.tquadrat.foundation.lang.Objects.requireNotBlankArgument; 025 026import org.apiguardian.api.API; 027import org.tquadrat.foundation.annotation.ClassVersion; 028import org.tquadrat.foundation.lang.GenericStringConverter; 029import org.tquadrat.foundation.lang.StringConverter; 030import org.tquadrat.foundation.perflog.PerformanceSectionName; 031 032/** 033 * <p>{@summary The implementation of 034 * {@link PerformanceSectionName}.}</p> 035 * 036 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 037 * @version $Id: PerformanceSectionNameImpl.java 1211 2026-05-01 15:24:10Z tquadrat $ 038 * @since 0.25.0 039 * 040 * @UMLGraph.link 041 */ 042@ClassVersion( sourceVersion = "$Id: PerformanceSectionNameImpl.java 1211 2026-05-01 15:24:10Z tquadrat $" ) 043@API( status = INTERNAL, since = "0.25.0" ) 044public final class PerformanceSectionNameImpl implements PerformanceSectionName 045{ 046 /*------------*\ 047 ====** Attributes **======================================================= 048 \*------------*/ 049 /** 050 * The internal value for the performance section name. 051 */ 052 private final String m_Value; 053 054 /*------------------------*\ 055 ====** Static Initialisations **=========================================== 056 \*------------------------*/ 057 /** 058 * The 059 * {@link StringConverter} 060 * for this class. 061 */ 062 private static final StringConverter<PerformanceSectionNameImpl> STRING_CONVERTER; 063 064 static 065 { 066 STRING_CONVERTER = new GenericStringConverter<>( PerformanceSectionNameImpl::new ); 067 } 068 069 /*--------------*\ 070 ====** Constructors **===================================================== 071 \*--------------*/ 072 /** 073 * Creates a new instance of {@code PerformanceSectionNameImpl}. 074 * 075 * @param value The value for the name. 076 */ 077 public PerformanceSectionNameImpl( final String value ) 078 { 079 m_Value = requireNotBlankArgument( value, "value" ); 080 } // PerformanceSectionNameImpl() 081 082 /** 083 * <p>{@summary Creates a new instance of 084 * {@code PerformanceSectionNameImpl}.}</p> 085 * <p>This constructor was introduced solely to simplify the 086 * implementation for the 087 * {@linkplain #STRING_CONVERTER string converter} 088 * provided by this class. Internally, it calls 089 * {@link #PerformanceSectionNameImpl(String)}.</p> 090 * 091 * @param value The value for the name. 092 * 093 * @see #getStringConverter() 094 * @see GenericStringConverter 095 */ 096 private PerformanceSectionNameImpl( final CharSequence value ) 097 { 098 this( requireNonNullArgument( value, "value" ).toString() ); 099 } // PerformanceSectionNameImpl() 100 101 /*---------*\ 102 ====** Methods **========================================================== 103 \*---------*/ 104 /** 105 * {@inheritDoc} 106 */ 107 @Override 108 public final int compareTo( final PerformanceSectionName o ) 109 { 110 final var retValue = signum( toString().compareTo( requireNonNullArgument( o, "o" ).toString() ) ); 111 112 //---* Done *---------------------------------------------------------- 113 return retValue; 114 } // compareTo() 115 116 /** 117 * {@inheritDoc} 118 */ 119 @Override 120 public final boolean equals( final Object o ) 121 { 122 var retValue = this == o; 123 if( !retValue && o instanceof final PerformanceSectionNameImpl other ) 124 { 125 retValue = m_Value.equals( other.m_Value ); 126 } 127 128 //---* Done *---------------------------------------------------------- 129 return retValue; 130 } // equals() 131 132 /** 133 * Returns the 134 * {@link StringConverter} 135 * for instances of this class. 136 * 137 * @param <T> The type that is handled by the returned 138 * {@link StringConverter} 139 * instance. 140 * @return The {@code StringConverter}. 141 */ 142 public static <T extends PerformanceSectionName> StringConverter<T> getStringConverter() 143 { 144 //noinspection unchecked 145 return (StringConverter<T>) STRING_CONVERTER; 146 } // getStringConverter() 147 148 /** 149 * {@inheritDoc} 150 */ 151 @Override 152 public final int hashCode() { return m_Value.hashCode(); } 153 154 /** 155 * {@inheritDoc} 156 */ 157 @Override 158 public final String toString() { return m_Value; } 159} 160// class PerformanceSectionNameImpl 161 162/* 163 * End of File 164 */