• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / j8xu / 16

02 May 2024 01:02PM UTC coverage: 93.082%. First build
16

push

circleci

adamretter
[feature] Initial version of a String implementation of the XML Builder API

142 of 153 new or added lines in 9 files covered. (92.81%)

148 of 159 relevant lines covered (93.08%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/src/main/java/com/evolvedbinary/j8xu/builder/impl/string/StringContext.java
1
/*
2
 * Copyright © 2024, Evolved Binary Ltd. <tech@evolvedbinary.com>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *     * Redistributions of source code must retain the above copyright
8
 *       notice, this list of conditions and the following disclaimer.
9
 *     * Redistributions in binary form must reproduce the above copyright
10
 *       notice, this list of conditions and the following disclaimer in the
11
 *       documentation and/or other materials provided with the distribution.
12
 *     * Neither the name of the <organization> nor the
13
 *       names of its contributors may be used to endorse or promote products
14
 *       derived from this software without specific prior written permission.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
package com.evolvedbinary.j8xu.builder.impl.string;
28

29
import javax.annotation.Nullable;
30
import java.util.ArrayDeque;
31
import java.util.Deque;
32

33
class StringContext {
34
  private final Deque<StringXmlElementNamespace> inScopeNamespaces = new ArrayDeque<>();
1✔
35
  private int treeDepth = 0;
1✔
36
  private int mixedContentTreeDepth = -1;
1✔
37
  @Nullable private final String indent;
38

39
  StringContext(@Nullable final String indent) {
1✔
40
    this.indent = indent;
1✔
41
  }
1✔
42

43
  /**
44
   * Determine if a prefix is in scope.
45
   *
46
   * @param prefix the prefix to test.
47
   * @param namespace the namespace associated with the prefix
48
   *
49
   * @return true if the prefix is in scope, false otherwise.
50
   */
51
  boolean isPrefixInScope(final String prefix, final String namespace) {
52
      for (final StringXmlElementNamespace inScopeNamespace : inScopeNamespaces) {
1✔
53
        if (prefix.equals(inScopeNamespace.prefix)) {
1✔
54
          return namespace.equals(inScopeNamespace.namespace);
1✔
55
        }
NEW
56
      }
×
57
      return false;
1✔
58
  }
59

60
  /**
61
   * Determine if a namespace is in scope.
62
   *
63
   * @param namespace the namespace to test.
64
   *
65
   * @return true if the namespace is in scope, false otherwise.
66
   */
67
  boolean isNamespaceInScope(final String namespace) {
68
    for (final StringXmlElementNamespace inScopeNamespace : inScopeNamespaces) {
1✔
69
      if (namespace.equals(inScopeNamespace.namespace)) {
1✔
70
        return true;
1✔
71
      }
NEW
72
    }
×
73
    return false;
1✔
74
  }
75

76
  void pushNamespace(final StringXmlElementNamespace namespace) {
77
    inScopeNamespaces.push(namespace);
1✔
78
  }
1✔
79

80
  void popNamespace() {
81
    inScopeNamespaces.pop();
1✔
82
  }
1✔
83

84
  boolean indent() {
85
    return indent != null;
1✔
86
  }
87

88
  String getIndent() {
89
    return indent;
1✔
90
  }
91

92
  int getTreeDepth() {
93
    return treeDepth;
1✔
94
  }
95

96
  void incrementTreeDepth() {
97
    treeDepth++;
1✔
98
  }
1✔
99

100
  void decrementTreeDepth() {
101
    treeDepth--;
1✔
102
  }
1✔
103

104
  void markMixedContentTreeDepth() {
105
    if (this.mixedContentTreeDepth == -1) {
1✔
106
      this.mixedContentTreeDepth = this.treeDepth;
1✔
107
    }
108
  }
1✔
109

110
  boolean inMixedContext() {
111
    return this.mixedContentTreeDepth != -1 && this.treeDepth >= this.mixedContentTreeDepth;
1✔
112
  }
113

114
  void resetMixedContentTreeDepth() {
115
    if (this.mixedContentTreeDepth == this.treeDepth) {
1✔
116
      this.mixedContentTreeDepth = -1;
1✔
117
    }
118
  }
1✔
119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc