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

wurstscript / WurstScript / 187

pending completion
187

push

circleci

Update pjass to detect functions with too many parameters

17138 of 27007 relevant lines covered (63.46%)

0.63 hits per line

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

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/datastructures/ImmutableTree.java
1
package de.peeeq.datastructures;
2

3
import com.google.common.base.Preconditions;
4
import com.google.common.collect.ImmutableList;
5
import com.google.common.collect.ImmutableList.Builder;
6
import org.eclipse.jdt.annotation.Nullable;
7

8
import java.util.Collections;
9
import java.util.Iterator;
10

11
public class ImmutableTree<T> implements Iterable<ImmutableTree<T>> {
12

13
    // invariant: children == null <--> elem != null
14
    private final @Nullable ImmutableList<ImmutableTree<T>> children;
15
    private final @Nullable T elem;
16

17
    private ImmutableTree(@Nullable ImmutableList<ImmutableTree<T>> children, @Nullable T elem) {
×
18
        Preconditions.checkArgument((children == null) != (elem == null));
×
19
        this.children = children;
×
20
        this.elem = elem;
×
21
    }
×
22

23
    public static <T> ImmutableTree<T> node(ImmutableList<ImmutableTree<T>> children) {
24
        return new ImmutableTree<>(children, null);
×
25
    }
26

27
    public static <T> ImmutableTree<T> leaf(T t) {
28
        return new ImmutableTree<>(null, t);
×
29
    }
30

31
    public int size() {
32
        ImmutableList<ImmutableTree<T>> ch = children;
×
33
        if (ch == null) {
×
34
            return 1;
×
35
        } else {
36
            int size = 0;
×
37
            for (ImmutableTree<T> c : ch) {
×
38
                size += c.size();
×
39
            }
×
40
            return size;
×
41
        }
42
    }
43

44

45
    @Override
46
    public Iterator<ImmutableTree<T>> iterator() {
47
        final ImmutableList<ImmutableTree<T>> children2 = children;
×
48
        if (children2 != null) {
×
49
            return children2.iterator();
×
50
        } else {
51
            return Collections.<ImmutableTree<T>>emptyList().iterator();
×
52
        }
53
    }
54

55
    public ImmutableList<T> allValues() {
56
        Builder<T> b = ImmutableList.builder();
×
57
        addValues(b);
×
58
        return b.build();
×
59
    }
60

61
    private void addValues(Builder<@Nullable T> b) {
62
        ImmutableList<ImmutableTree<T>> ch = children;
×
63
        if (ch == null) {
×
64
            b.add(elem);
×
65
        } else {
66
            for (ImmutableTree<T> c : ch) {
×
67
                c.addValues(b);
×
68
            }
×
69
        }
70
    }
×
71

72
    public static <T> ImmutableTree<T> empty() {
73
        return node(ImmutableList.<ImmutableTree<T>>of());
×
74
    }
75

76
    @Override
77
    public int hashCode() {
78
        final int prime = 31;
×
79
        int result = 1;
×
80
        ImmutableList<ImmutableTree<T>> c = children;
×
81
        @Nullable T e = elem;
×
82
        result = prime * result + ((c == null) ? 0 : c.hashCode());
×
83
        result = prime * result + ((e == null) ? 0 : e.hashCode());
×
84
        return result;
×
85
    }
86

87
    @Override
88
    public boolean equals(@Nullable Object obj) {
89
        if (this == obj)
×
90
            return true;
×
91
        if (obj == null)
×
92
            return false;
×
93
        if (getClass() != obj.getClass())
×
94
            return false;
×
95
        ImmutableTree<?> other = (ImmutableTree<?>) obj;
×
96
        ImmutableList<ImmutableTree<T>> c = children;
×
97
        if (c == null) {
×
98
            if (other.children != null)
×
99
                return false;
×
100
        } else if (!c.equals(other.children))
×
101
            return false;
×
102
        @Nullable T e = elem;
×
103
        if (e == null) {
×
104
            if (other.elem != null)
×
105
                return false;
×
106
        } else if (!e.equals(other.elem))
×
107
            return false;
×
108
        return true;
×
109
    }
110

111
    @Override
112
    public String toString() {
113
        StringBuilder sb = new StringBuilder();
×
114
        ImmutableList<ImmutableTree<T>> c = children;
×
115
        if (c == null) {
×
116
            sb.append("[");
×
117
            sb.append(elem);
×
118
            sb.append("]");
×
119
        } else {
120
            sb.append("[");
×
121
            boolean first = true;
×
122
            for (ImmutableTree<T> t : c) {
×
123
                if (!first) {
×
124
                    sb.append(", ");
×
125
                }
126
                sb.append(t);
×
127
                first = false;
×
128
            }
×
129
            sb.append("]");
×
130
        }
131
        return sb.toString();
×
132
    }
133

134
    public T getOnlyEment() {
135
        ImmutableList<ImmutableTree<T>> ch = children;
×
136
        @Nullable T el = elem;
×
137
        if (el != null) {
×
138
            return el;
×
139
        } else if (ch != null && !ch.isEmpty()) {
×
140
            return ch.get(0).getOnlyEment();
×
141
        }
142
        throw new RuntimeException("There are " + size() + " elements in this tree.");
×
143
    }
144

145
    public boolean isLeaf() {
146
        return children == null;
×
147
    }
148

149

150
}
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