1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jgit.lib;
20
21 import org.eclipse.jgit.util.StringUtils;
22
23
24 class ConfigLine {
25
26 String prefix;
27
28
29 String section;
30
31
32 String subsection;
33
34
35 String name;
36
37
38 String value;
39
40
41 String suffix;
42
43
44 String includedFrom;
45
46 ConfigLine forValue(String newValue) {
47 final ConfigLine e = new ConfigLine();
48 e.prefix = prefix;
49 e.section = section;
50 e.subsection = subsection;
51 e.name = name;
52 e.value = newValue;
53 e.suffix = suffix;
54 e.includedFrom = includedFrom;
55 return e;
56 }
57
58 boolean match(final String aSection, final String aSubsection,
59 final String aKey) {
60 return eqIgnoreCase(section, aSection)
61 && eqSameCase(subsection, aSubsection)
62 && eqIgnoreCase(name, aKey);
63 }
64
65 boolean match(String aSection, String aSubsection) {
66 return eqIgnoreCase(section, aSection)
67 && eqSameCase(subsection, aSubsection);
68 }
69
70 private static boolean eqIgnoreCase(String a, String b) {
71 if (a == null && b == null)
72 return true;
73 if (a == null || b == null)
74 return false;
75 return StringUtils.equalsIgnoreCase(a, b);
76 }
77
78 private static boolean eqSameCase(String a, String b) {
79 if (a == null && b == null)
80 return true;
81 if (a == null || b == null)
82 return false;
83 return a.equals(b);
84 }
85
86
87 @SuppressWarnings("nls")
88 @Override
89 public String toString() {
90 if (section == null)
91 return "<empty>";
92 StringBuilder b = new StringBuilder(section);
93 if (subsection != null)
94 b.append(".").append(subsection);
95 if (name != null)
96 b.append(".").append(name);
97 if (value != null)
98 b.append("=").append(value);
99 return b.toString();
100 }
101 }