001/* 002 * ============================================================================ 003 * Copyright © 2002-2023 by Thomas Thrien. 004 * All Rights Reserved. 005 * ============================================================================ 006 * Licensed to the public under the agreements of the GNU Lesser General Public 007 * License, version 3.0 (the "License"). You may obtain a copy of the License at 008 * 009 * http://www.gnu.org/licenses/lgpl.html 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 014 * License for the specific language governing permissions and limitations 015 * under the License. 016 */ 017 018package org.tquadrat.foundation.testutil.impl; 019 020import static java.util.Objects.nonNull; 021import static org.apiguardian.api.API.Status.STABLE; 022import static org.tquadrat.foundation.testutil.TestUtils.requireNotEmptyArgument; 023 024import javax.lang.model.element.Name; 025 026import org.apiguardian.api.API; 027 028/** 029 * An implementation of 030 * {@link Name} 031 * for test purposes. 032 * 033 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 034 * @version $Id: NameTestImpl.java 1074 2023-10-02 12:05:06Z tquadrat $ 035 * @since 0.0.1 036 */ 037@API( status = STABLE, since = "0.0.1" ) 038public class NameTestImpl implements Name 039{ 040 /*------------*\ 041 ====** Attributes **======================================================= 042 \*------------*/ 043 /** 044 * The value. 045 */ 046 private final String m_Value; 047 048 /*--------------*\ 049 ====** Constructors **===================================================== 050 \*--------------*/ 051 /** 052 * Creates a new {@code NameTestImpl} instance. 053 * 054 * @param value The value. 055 */ 056 public NameTestImpl( final CharSequence value ) 057 { 058 m_Value = requireNotEmptyArgument( value, "value" ).toString().intern(); 059 } // NameTestImpl() 060 061 /*---------*\ 062 ====** Methods **========================================================== 063 \*---------*/ 064 /** 065 * {@inheritDoc} 066 */ 067 @Override 068 public final char charAt( final int index ) { return m_Value.charAt( index ); } 069 070 /** 071 * {@inheritDoc} 072 */ 073 @Override 074 public final boolean contentEquals( final CharSequence cs ) 075 { 076 final var retValue = nonNull( cs ) && cs.equals( m_Value ); 077 078 //---* Done *---------------------------------------------------------- 079 return retValue; 080 } // contentEquals() 081 082 /** 083 * {@inheritDoc} 084 */ 085 @Override 086 public final boolean equals( final Object obj ) 087 { 088 var retValue = this == obj; 089 if( !retValue && (obj instanceof final Name name ) ) 090 { 091 retValue = contentEquals( name ); 092 } 093 094 //---* Done *---------------------------------------------------------- 095 return retValue; 096 } // equals() 097 098 /** 099 * {@inheritDoc} 100 */ 101 @Override 102 public final int hashCode() { return m_Value.hashCode(); } 103 104 /** 105 * {@inheritDoc} 106 */ 107 @Override 108 public final int length() { return m_Value.length(); } 109 110 /** 111 * {@inheritDoc} 112 */ 113 @Override 114 public final CharSequence subSequence( final int start, final int end ) { return m_Value.subSequence( start, end ); } 115 116 /** 117 * {@inheritDoc} 118 */ 119 @Override 120 public final String toString() { return m_Value; } 121} 122// class NameTestImpl 123 124/* 125 * End of File 126 */