Home | History | Annotate | Download | only in description
      1 /*
      2  * Copyright (C) 2007-2010 Jlio Vilmar Gesser.
      3  * Copyright (C) 2011, 2013-2016 The JavaParser Team.
      4  *
      5  * This file is part of JavaParser.
      6  *
      7  * JavaParser can be used either under the terms of
      8  * a) the GNU Lesser General Public License as published by
      9  *     the Free Software Foundation, either version 3 of the License, or
     10  *     (at your option) any later version.
     11  * b) the terms of the Apache License
     12  *
     13  * You should have received a copy of both licenses in LICENCE.LGPL and
     14  * LICENCE.APACHE. Please refer to those files for details.
     15  *
     16  * JavaParser is distributed in the hope that it will be useful,
     17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19  * GNU Lesser General Public License for more details.
     20  */
     21 
     22 package com.github.javaparser.javadoc.description;
     23 
     24 /**
     25  * A piece of text inside a Javadoc description.
     26  * <p>
     27  * For example in <code>A class totally unrelated to {@link String}, I swear!</code> we would have two snippets: one
     28  * before and one after the inline tag (<code>{@link String}</code>).
     29  */
     30 public class JavadocSnippet implements JavadocDescriptionElement {
     31     private String text;
     32 
     33     public JavadocSnippet(String text) {
     34         if (text == null) {
     35             throw new NullPointerException();
     36         }
     37         this.text = text;
     38     }
     39 
     40     @Override
     41     public String toText() {
     42         return this.text;
     43     }
     44 
     45     @Override
     46     public boolean equals(Object o) {
     47         if (this == o) return true;
     48         if (o == null || getClass() != o.getClass()) return false;
     49 
     50         JavadocSnippet that = (JavadocSnippet) o;
     51 
     52         return text.equals(that.text);
     53 
     54     }
     55 
     56     @Override
     57     public int hashCode() {
     58         return text.hashCode();
     59     }
     60 
     61     @Override
     62     public String toString() {
     63         return "JavadocSnippet{" +
     64                 "text='" + text + '\'' +
     65                 '}';
     66     }
     67 }
     68