View Javadoc
1   /*
2    * Themis: Java Project Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.themis.lethe.analysis;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  /**
25   * A series of blank lines.
26   */
27  public class ThemisAnalysisBlank
28          implements ThemisAnalysisProcessed {
29      /**
30       * The in-line comments.
31       */
32      private static final String COMMENTS = "" + ThemisAnalysisChar.COMMENT + ThemisAnalysisChar.COMMENT;
33  
34      /**
35       * The blankLines.
36       */
37      private final List<ThemisAnalysisLine> theBlanks;
38  
39      /**
40       * Constructor.
41       *
42       * @param pParser the parser
43       * @param pLine   the initial blank line
44       * @throws OceanusException on error
45       */
46      ThemisAnalysisBlank(final ThemisAnalysisParser pParser,
47                          final ThemisAnalysisLine pLine) throws OceanusException {
48          /* Create the list of blank lines */
49          theBlanks = new ArrayList<>();
50          theBlanks.add(pLine);
51  
52          /* While there are further lines */
53          while (pParser.hasLines()) {
54              /* Access next line */
55              final ThemisAnalysisLine myLine = (ThemisAnalysisLine) pParser.peekNextLine();
56  
57              /* It it is also blank */
58              if (isBlank(myLine)) {
59                  /* Add the blank line and remove from input */
60                  theBlanks.add(myLine);
61                  pParser.popNextLine();
62  
63                  /* else break loop */
64              } else {
65                  break;
66              }
67          }
68      }
69  
70      @Override
71      public int getNumLines() {
72          return theBlanks.size();
73      }
74  
75      /**
76       * Is the line blank?
77       *
78       * @param pLine the line
79       * @return true/false
80       */
81      static boolean isBlank(final ThemisAnalysisLine pLine) {
82          return pLine.getLength() == 0 || pLine.startsWithSequence(COMMENTS);
83      }
84  }