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

ferstl / depgraph-maven-plugin / #556

28 Dec 2023 11:01AM UTC coverage: 86.893% (-0.1%) from 87.004%
#556

push

ferstl
Update license headers

Signed-off-by: Stefan Ferstl <st.ferstl@gmail.com>

582 of 767 branches covered (0.0%)

1664 of 1915 relevant lines covered (86.89%)

0.87 hits per line

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

95.92
/src/main/java/com/github/ferstl/depgraph/dependency/dot/style/StyleKey.java
1
/*
2
 * Copyright (c) 2014 - 2024 the original author or authors.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.github.ferstl.depgraph.dependency.dot.style;
17

18
import java.util.Arrays;
19
import java.util.Objects;
20
import com.google.common.base.Joiner;
21
import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
22

23
public final class StyleKey {
24

25
  private static final int NUM_ELEMENTS = 7;
26

27
  private final String groupId;
28
  private final String artifactId;
29
  private final String scope;
30
  private final String type;
31
  private final String version;
32
  private final String classifier;
33
  private final String optional;
34

35

36
  private StyleKey(String[] parts) {
1✔
37
    if (parts.length > NUM_ELEMENTS) {
1✔
38
      throw new IllegalArgumentException("Too many parts. Expecting '<groupId>:<artifactId>:<version>:<scope>:<type>:<classifier>:<true|false>'");
1✔
39
    }
40

41
    String[] expanded = new String[NUM_ELEMENTS];
1✔
42
    Arrays.fill(expanded, "");
1✔
43

44
    for (int i = 0; i < parts.length; i++) {
1✔
45
      expanded[i] = defaultIfEmpty(parts[i], "");
1✔
46
    }
47

48
    this.groupId = expanded[0];
1✔
49
    this.artifactId = expanded[1];
1✔
50
    this.scope = expanded[2];
1✔
51
    this.type = expanded[3];
1✔
52
    this.version = expanded[4];
1✔
53
    this.classifier = expanded[5];
1✔
54
    this.optional = expanded[6];
1✔
55
  }
1✔
56

57
  public static StyleKey fromString(String keyString) {
58
    String[] parts = keyString.split(",");
1✔
59
    return new StyleKey(parts);
1✔
60
  }
61

62
  public static StyleKey create(String groupId, String artifactId, String scope, String type, String version, String classifier, Boolean isOptional) {
63
    return new StyleKey(new String[]{groupId, artifactId, scope, type, version, classifier, isOptional != null ? isOptional.toString() : null});
1✔
64
  }
65

66
  public boolean matches(StyleKey other) {
67
    return (wildcardMatch(this.groupId, other.groupId))
1✔
68
        && (wildcardMatch(this.artifactId, other.artifactId))
1!
69
        && (match(this.scope, other.scope))
1✔
70
        && (match(this.type, other.type))
1✔
71
        && (wildcardMatch(this.version, other.version))
1!
72
        && (wildcardMatch(this.classifier, other.classifier))
1✔
73
        && (match(this.optional, other.optional));
1✔
74

75
  }
76

77
  @Override
78
  public boolean equals(Object obj) {
79
    if (obj == this) {
1!
80
      return true;
×
81
    }
82

83
    if (!(obj instanceof StyleKey)) {
1!
84
      return false;
×
85
    }
86

87
    StyleKey other = (StyleKey) obj;
1✔
88

89
    return Objects.equals(this.groupId, other.groupId)
1✔
90
        && Objects.equals(this.artifactId, other.artifactId)
1✔
91
        && Objects.equals(this.scope, other.scope)
1✔
92
        && Objects.equals(this.type, other.type)
1✔
93
        && Objects.equals(this.version, other.version)
1✔
94
        && Objects.equals(this.classifier, other.classifier)
1✔
95
        && Objects.equals(this.optional, other.optional);
1✔
96
  }
97

98
  @Override
99
  public int hashCode() {
100
    return Objects.hash(this.groupId, this.artifactId, this.scope, this.type, this.version, this.classifier, this.optional);
1✔
101
  }
102

103
  @Override
104
  public String toString() {
105
    return Joiner.on(",").join(this.groupId, this.artifactId, this.scope, this.type, this.version, this.classifier, this.optional);
1✔
106
  }
107

108
  private static boolean wildcardMatch(String value1, String value2) {
109
    if (value1.indexOf('*') != -1) {
1✔
110
      int lastMatch = 0;
1✔
111

112
      for (String matchStr : value1.split("\\*")) {
1✔
113
        int indexOfMatch = value2.substring(lastMatch).indexOf(matchStr);
1✔
114
        lastMatch += indexOfMatch + matchStr.length();
1✔
115

116
        if (indexOfMatch == -1) {
1✔
117
          return false;
1✔
118
        }
119
      }
120

121
      return true;
1✔
122
    }
123

124
    return match(value1, value2);
1✔
125
  }
126

127
  private static boolean match(String value1, String value2) {
128
    return value1.isEmpty() || value1.equals(value2);
1✔
129
  }
130

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