001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.tools.template_engine; 003 004import java.util.Objects; 005 006/** 007 * {@link TemplateEntry} representing a static string. 008 * <p> 009 * When compiling the template result, the given string will simply be inserted at the current position. 010 */ 011public class StaticText implements TemplateEntry { 012 013 private final String staticText; 014 015 /** 016 * Create a new {@code StaticText}. 017 * @param staticText the text to insert verbatim 018 */ 019 public StaticText(String staticText) { 020 this.staticText = staticText; 021 } 022 023 @Override 024 public void appendText(StringBuilder result, TemplateEngineDataProvider dataProvider) { 025 result.append(staticText); 026 } 027 028 @Override 029 public boolean isValid(TemplateEngineDataProvider dataProvider) { 030 return true; 031 } 032 033 @Override 034 public String toString() { 035 return staticText; 036 } 037 038 @Override 039 public int hashCode() { 040 return Objects.hash(staticText); 041 } 042 043 @Override 044 public boolean equals(Object obj) { 045 if (this == obj) 046 return true; 047 if (obj == null || getClass() != obj.getClass()) 048 return false; 049 StaticText other = (StaticText) obj; 050 if (staticText == null) { 051 if (other.staticText != null) 052 return false; 053 } else if (!staticText.equals(other.staticText)) 054 return false; 055 return true; 056 } 057}