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