Skip to content

Commit

Permalink
Automatic code change (#349)
Browse files Browse the repository at this point in the history
Some archaic constructs were replaced with more appropriate methods around string handling.

This PR does not introduce any semantic change.
  • Loading branch information
cstamas committed Oct 24, 2023
1 parent 7907f20 commit 12b1c2c
Show file tree
Hide file tree
Showing 31 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public String toString() {
buffer.append(getGroupId());
buffer.append(':').append(getArtifactId());
buffer.append(':').append(getExtension());
if (getClassifier().length() > 0) {
if (!getClassifier().isEmpty()) {
buffer.append(':').append(getClassifier());
}
buffer.append(':').append(getVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ public DefaultArtifactType(
boolean constitutesBuildPath,
boolean includesDependencies) {
this.id = requireNonNull(id, "type id cannot be null");
if (id.length() == 0) {
if (id.isEmpty()) {
throw new IllegalArgumentException("type id cannot be empty");
}
this.extension = emptify(extension);
this.classifier = emptify(classifier);
Map<String, String> props = new HashMap<>();
props.put(ArtifactProperties.TYPE, id);
props.put(ArtifactProperties.LANGUAGE, (language != null && language.length() > 0) ? language : "none");
props.put(ArtifactProperties.LANGUAGE, (language != null && !language.isEmpty()) ? language : "none");
props.put(ArtifactProperties.INCLUDES_DEPENDENCIES, Boolean.toString(includesDependencies));
props.put(ArtifactProperties.CONSTITUTES_BUILD_PATH, Boolean.toString(constitutesBuildPath));
properties = Collections.unmodifiableMap(props);
Expand All @@ -108,7 +108,7 @@ public DefaultArtifactType(
*/
public DefaultArtifactType(String id, String extension, String classifier, Map<String, String> properties) {
this.id = requireNonNull(id, "type id cannot be null");
if (id.length() == 0) {
if (id.isEmpty()) {
throw new IllegalArgumentException("type id cannot be empty");
}
this.extension = emptify(extension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static String toPath(List<? extends DependencyNode> path) {
buffer.append(artifact.getGroupId());
buffer.append(':').append(artifact.getArtifactId());
buffer.append(':').append(artifact.getExtension());
if (artifact.getClassifier().length() > 0) {
if (!artifact.getClassifier().isEmpty()) {
buffer.append(':').append(artifact.getClassifier());
}
buffer.append(':').append(node.getVersionConstraint());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public String toString() {
+ getArtifactId()
+ ':'
+ getExtension()
+ (getClassifier().length() > 0 ? ':' + getClassifier() : "");
+ (!getClassifier().isEmpty() ? ':' + getClassifier() : "");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ protected static Map<String, String> copyProperties(Map<String, String> properti
@Override
public String toString() {
StringBuilder buffer = new StringBuilder(128);
if (getGroupId().length() > 0) {
if (!getGroupId().isEmpty()) {
buffer.append(getGroupId());
}
if (getArtifactId().length() > 0) {
if (!getArtifactId().isEmpty()) {
buffer.append(':').append(getArtifactId());
}
if (getVersion().length() > 0) {
if (!getVersion().isEmpty()) {
buffer.append(':').append(getVersion());
}
buffer.append('/').append(getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public <T> T get(String key, Class<T> type) {
*/
public <T> T get(String key, Map<String, String> data, Class<T> type) {
requireNonNull(key, "authentication key cannot be null");
if (key.length() == 0) {
if (key.isEmpty()) {
throw new IllegalArgumentException("authentication key cannot be empty");
}

Expand Down Expand Up @@ -304,7 +304,7 @@ private <T> T convert(Object value, Class<T> type) {
*/
public void put(String key, Object value) {
requireNonNull(key, "authentication key cannot be null");
if (key.length() == 0) {
if (key.isEmpty()) {
throw new IllegalArgumentException("authentication key cannot be empty");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public String getPathForArtifact(Artifact artifact, boolean local) {
path.append(artifact.getVersion());
}

if (artifact.getClassifier().length() > 0) {
if (!artifact.getClassifier().isEmpty()) {
path.append('-').append(artifact.getClassifier());
}

if (artifact.getExtension().length() > 0) {
if (!artifact.getExtension().isEmpty()) {
path.append('.').append(artifact.getExtension());
}

Expand All @@ -71,13 +71,13 @@ public String getPathForMetadata(Metadata metadata, String repositoryKey) {

StringBuilder path = new StringBuilder(128);

if (metadata.getGroupId().length() > 0) {
if (!metadata.getGroupId().isEmpty()) {
path.append(metadata.getGroupId().replace('.', '/')).append('/');

if (metadata.getArtifactId().length() > 0) {
if (!metadata.getArtifactId().isEmpty()) {
path.append(metadata.getArtifactId()).append('/');

if (metadata.getVersion().length() > 0) {
if (!metadata.getVersion().isEmpty()) {
path.append(metadata.getVersion()).append('/');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public GetTask setChecksum(String algorithm, String value) {
if (checksums.isEmpty()) {
checksums = new HashMap<>();
}
if (value != null && value.length() > 0) {
if (value != null && !value.isEmpty()) {
checksums.put(algorithm, value);
} else {
checksums.remove(algorithm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private boolean isEOFMarker(String line) {
}

private static boolean isEmpty(String line) {
return line == null || line.length() == 0;
return line == null || line.isEmpty();
}

private static String cutComment(String line) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private Artifact relocation(List<String> list) {
}

private static boolean isEmpty(String line) {
return line == null || line.length() == 0;
return line == null || line.isEmpty();
}

private static String cutComment(String line) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ public NodeBuilder properties(Map<String, String> properties) {

public DependencyNode build() {
Dependency dependency = null;
if (artifactId != null && artifactId.length() > 0) {
if (artifactId != null && !artifactId.isEmpty()) {
Artifact artifact =
new DefaultArtifact(groupId, artifactId, classifier, ext, version, properties, (File) null);
dependency = new Dependency(artifact, scope, optional);
}
DefaultDependencyNode node = new DefaultDependencyNode(dependency);
if (artifactId != null && artifactId.length() > 0) {
if (artifactId != null && !artifactId.isEmpty()) {
try {
node.setVersion(versionScheme.parseVersion(version));
node.setVersionConstraint(versionScheme.parseVersionConstraint(range != null ? range : version));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ final class TestVersionRange implements VersionRange {
range, "Invalid version range " + range + ", bounds may not contain additional ','");
}

lowerBound = parsedLowerBound.length() > 0 ? new TestVersion(parsedLowerBound) : null;
upperBound = parsedUpperBound.length() > 0 ? new TestVersion(parsedUpperBound) : null;
lowerBound = !parsedLowerBound.isEmpty() ? new TestVersion(parsedLowerBound) : null;
upperBound = !parsedUpperBound.isEmpty() ? new TestVersion(parsedUpperBound) : null;

if (upperBound != null && lowerBound != null) {
if (upperBound.compareTo(lowerBound) < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public VersionConstraint parseVersionConstraint(final String constraint)

process = process.substring(index + 1).trim();

if (process.length() > 0 && process.startsWith(",")) {
if (process.startsWith(",")) {
process = process.substring(1).trim();
}
}

if (process.length() > 0 && !ranges.isEmpty()) {
if (!process.isEmpty() && !ranges.isEmpty()) {
throw new InvalidVersionSpecificationException(
constraint, "Invalid version range " + constraint + ", expected [ or ( but got " + process);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class ClasspathTransporter extends AbstractTransporter {
} else {
base = ssp;
}
if (base.length() > 0 && !base.endsWith("/")) {
if (!base.isEmpty() && !base.endsWith("/")) {
base += '/';
}
} catch (URISyntaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static String basedir(String url) {

String retValue = null;

if (protocol.length() > 0) {
if (!protocol.isEmpty()) {
retValue = url.substring(protocol.length() + 1);
} else {
retValue = url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class UriUtils {

public static URI resolve(URI base, URI ref) {
String path = ref.getRawPath();
if (path != null && path.length() > 0) {
if (path != null && !path.isEmpty()) {
path = base.getRawPath();
if (path == null || !path.endsWith("/")) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static String read(File checksumFile) throws IOException {
break;
}
line = line.trim();
if (line.length() > 0) {
if (!line.isEmpty()) {
checksum = line;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private static StringBuilder concat(String groupId, String artifactId, String ex
if (extension != null) {
buffer.append(extension);
}
if (classifier != null && classifier.length() > 0) {
if (classifier != null && !classifier.isEmpty()) {
buffer.append(SEP).append(classifier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class WorkerThreadFactory implements ThreadFactory {
public WorkerThreadFactory(String namePrefix) {
this.factory = Executors.defaultThreadFactory();
this.namePrefix =
((namePrefix != null && namePrefix.length() > 0) ? namePrefix : getCallerSimpleClassName() + '-')
((namePrefix != null && !namePrefix.isEmpty()) ? namePrefix : getCallerSimpleClassName() + '-')
+ POOL_INDEX.getAndIncrement()
+ '-';
threadIndex = new AtomicInteger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private boolean matches(final String token, final String pattern) {
boolean matches;

// support full wildcard and implied wildcard
if ("*".equals(pattern) || pattern.length() == 0) {
if ("*".equals(pattern) || pattern.isEmpty()) {
matches = true;
}
// support contains wildcard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static DependencyFilter classpathFilter(Collection<String> classpathTypes
String[] tokens = classpathType.split("[+,]");
for (String token : tokens) {
token = token.trim();
if (token.length() > 0) {
if (!token.isEmpty()) {
types.add(token);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ public DependencyManager deriveChildManager(DependencyCollectionContext context)
Object key = getKey(artifact);

String version = artifact.getVersion();
if (version.length() > 0 && !managedVersions.containsKey(key)) {
if (!version.isEmpty() && !managedVersions.containsKey(key)) {
if (managedVersions == this.managedVersions) {
managedVersions = new HashMap<>(this.managedVersions);
}
managedVersions.put(key, version);
}

String scope = managedDependency.getScope();
if (scope.length() > 0 && !managedScopes.containsKey(key)) {
if (!scope.isEmpty() && !managedScopes.containsKey(key)) {
if (managedScopes == this.managedScopes) {
managedScopes = new HashMap<>(this.managedScopes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ public DependencyManager deriveChildManager(final DependencyCollectionContext co
Object key = getKey(artifact);

String version = artifact.getVersion();
if (version.length() > 0 && !versions.containsKey(key)) {
if (!version.isEmpty() && !versions.containsKey(key)) {
if (versions == this.managedVersions) {
versions = new HashMap<>(this.managedVersions);
}
versions.put(key, version);
}

String scope = managedDependency.getScope();
if (scope.length() > 0 && !scopes.containsKey(key)) {
if (!scope.isEmpty() && !scopes.containsKey(key)) {
if (scopes == this.managedScopes) {
scopes = new HashMap<>(this.managedScopes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ public DependencyManager deriveChildManager(final DependencyCollectionContext co
Object key = getKey(artifact);

String version = artifact.getVersion();
if (version.length() > 0 && !versions.containsKey(key)) {
if (!version.isEmpty() && !versions.containsKey(key)) {
if (versions == managedVersions) {
versions = new HashMap<>(managedVersions);
}
versions.put(key, version);
}

String scope = managedDependency.getScope();
if (scope.length() > 0 && !scopes.containsKey(key)) {
if (!scope.isEmpty() && !scopes.containsKey(key)) {
if (scopes == this.managedScopes) {
scopes = new HashMap<>(this.managedScopes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class ComponentAuthentication implements Authentication {

ComponentAuthentication(String key, Object value) {
this.key = requireNonNull(key, "authentication key cannot be null");
if (key.length() == 0) {
if (key.isEmpty()) {
throw new IllegalArgumentException("authentication key cannot be empty");
}
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public RemoteRepository getMirror(RemoteRepository repository) {

builder.setBlocked(mirror.blocked);

if (mirror.type != null && mirror.type.length() > 0) {
if (mirror.type != null && !mirror.type.isEmpty()) {
builder.setContentType(mirror.type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class SecretAuthentication implements Authentication {

private SecretAuthentication(char[] value, String key) {
this.key = requireNonNull(key, "authentication key cannot be null");
if (key.length() == 0) {
if (key.isEmpty()) {
throw new IllegalArgumentException("authentication key cannot be empty");
}
this.secretHash = Arrays.hashCode(value) ^ KEYS[0].hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class StringAuthentication implements Authentication {

StringAuthentication(String key, String value) {
this.key = requireNonNull(key, "authentication key cannot be null");
if (key.length() == 0) {
if (key.isEmpty()) {
throw new IllegalArgumentException("authentication key cannot be empty");
}
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static final class Tokenizer {
private boolean terminatedByNumber;

Tokenizer(String version) {
this.version = (version.length() > 0) ? version : "0";
this.version = (!version.isEmpty()) ? version : "0";
this.versionLength = this.version.length();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ final class GenericVersionRange implements VersionRange {
range, "Invalid version range " + range + ", bounds may not contain additional ','");
}

lowerBound = parsedLowerBound.length() > 0 ? parse(parsedLowerBound) : null;
upperBound = parsedUpperBound.length() > 0 ? parse(parsedUpperBound) : null;
lowerBound = !parsedLowerBound.isEmpty() ? parse(parsedLowerBound) : null;
upperBound = !parsedUpperBound.isEmpty() ? parse(parsedUpperBound) : null;

if (upperBound != null && lowerBound != null) {
if (upperBound.compareTo(lowerBound) < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public GenericVersionConstraint parseVersionConstraint(final String constraint)
}
}

if (process.length() > 0 && !ranges.isEmpty()) {
if (!process.isEmpty() && !ranges.isEmpty()) {
throw new InvalidVersionSpecificationException(
constraint, "Invalid version range " + constraint + ", expected [ or ( but got " + process);
}
Expand Down

0 comments on commit 12b1c2c

Please sign in to comment.