Skip to content

Commit

Permalink
Use isEmpty instead of length (#1420)
Browse files Browse the repository at this point in the history
Signed-off-by: crazyhzm <[email protected]>
  • Loading branch information
CrazyHZM authored Feb 28, 2024
1 parent cf438ca commit 83949a7
Show file tree
Hide file tree
Showing 28 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public static VersionRange createFromVersionSpec(String spec) throws InvalidVers
}
}

if (process.length() > 0) {
if (restrictions.size() > 0) {
if (!process.isEmpty()) {
if (!restrictions.isEmpty()) {
throw new InvalidVersionSpecificationException(
"Only fully-qualified sets allowed in multiple set scenario: " + spec);
} else {
Expand Down Expand Up @@ -180,11 +180,11 @@ private static Restriction parseRestriction(String spec) throws InvalidVersionSp
String upperBound = process.substring(index + 1).trim();

ArtifactVersion lowerVersion = null;
if (lowerBound.length() > 0) {
if (!lowerBound.isEmpty()) {
lowerVersion = new DefaultArtifactVersion(lowerBound);
}
ArtifactVersion upperVersion = null;
if (upperBound.length() > 0) {
if (!upperBound.isEmpty()) {
upperVersion = new DefaultArtifactVersion(upperBound);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ static class ArtifactMetadataAdapter implements ArtifactMetadata {
}

public boolean storedInArtifactVersionDirectory() {
return metadata.getVersion().length() > 0;
return !metadata.getVersion().isEmpty();
}

public boolean storedInGroupDirectory() {
return metadata.getArtifactId().length() <= 0;
return metadata.getArtifactId().isEmpty();
}

public String getGroupId() {
Expand All @@ -199,7 +199,7 @@ public String getBaseVersion() {
}

private String nullify(String str) {
return (str == null || str.length() <= 0) ? null : str;
return (str == null || str.isEmpty()) ? null : str;
}

public Object getKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String pathOf(Artifact artifact) {
}

if (artifactHandler.getExtension() != null
&& artifactHandler.getExtension().length() > 0) {
&& !artifactHandler.getExtension().isEmpty()) {
path.append(GROUP_SEPARATOR).append(artifactHandler.getExtension());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public String unalignFromBaseDirectory(String path, File basedir) {
path = chopLeadingFileSeparator(path.substring(base.length()));
}

if (path.length() <= 0) {
if (path.isEmpty()) {
path = ".";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MavenArtifact implements ArtifactTransferResource {
MavenArtifact(String repositoryUrl, Resource resource) {
if (repositoryUrl == null) {
this.repositoryUrl = "";
} else if (!repositoryUrl.endsWith("/") && repositoryUrl.length() > 0) {
} else if (!repositoryUrl.endsWith("/") && !repositoryUrl.isEmpty()) {
this.repositoryUrl = repositoryUrl + '/';
} else {
this.repositoryUrl = repositoryUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public String getPathForLocalArtifact(Artifact artifact) {

path.append(artifact.getArtifactId()).append('-').append(artifact.getVersion());

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

Expand Down Expand Up @@ -84,13 +84,13 @@ String getRepositoryKey(RemoteRepository repository, String context) {
private String getPath(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 @@ -66,7 +66,7 @@
public class RepositoryUtils {

private static String nullify(String string) {
return (string == null || string.length() <= 0) ? null : string;
return (string == null || string.isEmpty()) ? null : string;
}

private static org.apache.maven.artifact.Artifact toArtifact(Dependency dependency) {
Expand Down Expand Up @@ -207,7 +207,7 @@ public static String getLayout(ArtifactRepository repo) {
String className = repo.getLayout().getClass().getSimpleName();
if (className.endsWith("RepositoryLayout")) {
String layout = className.substring(0, className.length() - "RepositoryLayout".length());
if (layout.length() > 0) {
if (!layout.isEmpty()) {
layout = Character.toLowerCase(layout.charAt(0)) + layout.substring(1);
return layout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public String pathOf(Artifact artifact) {
}

if (artifactHandler.getExtension() != null
&& artifactHandler.getExtension().length() > 0) {
&& !artifactHandler.getExtension().isEmpty()) {
path.append(GROUP_SEPARATOR).append(artifactHandler.getExtension());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected Object fromExpression(
String value = configuration.getValue();
try {
Object result = null;
if (null != value && value.length() > 0) {
if (null != value && !value.isEmpty()) {
if (evaluator instanceof TypeAwareExpressionEvaluator) {
result = ((TypeAwareExpressionEvaluator) evaluator).evaluate(value, type);
} else {
Expand All @@ -48,7 +48,7 @@ protected Object fromExpression(
}
if (null == result && configuration.getChildCount() == 0) {
value = configuration.getAttribute("default-value");
if (null != value && value.length() > 0) {
if (null != value && !value.isEmpty()) {
if (evaluator instanceof TypeAwareExpressionEvaluator) {
result = ((TypeAwareExpressionEvaluator) evaluator).evaluate(value, type);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private List<String> parseStrings(XmlNode dom) {
String string = child.getValue();
if (string != null) {
string = string.trim();
if (string.length() > 0) {
if (!string.isEmpty()) {
strings.add(string);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public DependencyManagement getDependencyManagement() {
private void addPath(List<String> paths, String path) {
if (path != null) {
path = path.trim();
if (path.length() > 0) {
if (!path.isEmpty()) {
File file = new File(path);
if (file.isAbsolute()) {
path = file.getAbsolutePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public String getPathForLocalArtifact(Artifact artifact) {

path.append(artifact.getArtifactId()).append('-').append(artifact.getVersion());

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

Expand Down Expand Up @@ -84,13 +84,13 @@ String getRepositoryKey(RemoteRepository repository, String context) {
private String getPath(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 @@ -116,7 +116,7 @@ private String path(Artifact artifact) {

path.append(artifact.getArtifactId()).append('-').append(artifact.getVersion());

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DefaultRuntimeInformationTest {
void testGetMavenVersion() {
String mavenVersion = rtInfo.getMavenVersion();
assertNotNull(mavenVersion);
assertTrue(mavenVersion.length() > 0);
assertTrue(!mavenVersion.isEmpty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ private org.apache.maven.api.model.Model doReadFileModel(
throw problems.newModelBuildingException();
} catch (IOException e) {
String msg = e.getMessage();
if (msg == null || msg.length() <= 0) {
if (msg == null || msg.isEmpty()) {
// NOTE: There's java.nio.charset.MalformedInputException and sun.io.MalformedInputException
if (e.getClass().getName().endsWith("MalformedInputException")) {
msg = "Some input bytes do not match the file encoding.";
Expand Down Expand Up @@ -1560,7 +1560,7 @@ private ModelSource2 getParentPomFile(Model childModel, Source source) {

String parentPath = childModel.getParent().getRelativePath();

if (parentPath == null || parentPath.length() <= 0) {
if (parentPath == null || parentPath.isEmpty()) {
return null;
}

Expand Down Expand Up @@ -1605,7 +1605,7 @@ private ModelData readParentExternally(
}
buffer.append(": ").append(e.getMessage());
if (childModel.getProjectDirectoryPath() != null) {
if (parent.getRelativePath() == null || parent.getRelativePath().length() <= 0) {
if (parent.getRelativePath() == null || parent.getRelativePath().isEmpty()) {
buffer.append(" and 'parent.relativePath' points at no local POM");
} else {
buffer.append(" and 'parent.relativePath' points at wrong local POM");
Expand Down Expand Up @@ -1710,21 +1710,21 @@ private DependencyManagement loadDependencyManagement(
String artifactId = dependency.getArtifactId();
String version = dependency.getVersion();

if (groupId == null || groupId.length() <= 0) {
if (groupId == null || groupId.isEmpty()) {
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
.setMessage("'dependencyManagement.dependencies.dependency.groupId' for "
+ dependency.getManagementKey() + " is missing.")
.setLocation(dependency.getLocation("")));
return null;
}
if (artifactId == null || artifactId.length() <= 0) {
if (artifactId == null || artifactId.isEmpty()) {
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
.setMessage("'dependencyManagement.dependencies.dependency.artifactId' for "
+ dependency.getManagementKey() + " is missing.")
.setLocation(dependency.getLocation("")));
return null;
}
if (version == null || version.length() <= 0) {
if (version == null || version.isEmpty()) {
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
.setMessage("'dependencyManagement.dependencies.dependency.version' for "
+ dependency.getManagementKey() + " is missing.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static String toMessage(String modelId, List<ModelProblem> problems) {
writer.print(problems.size());
writer.print((problems.size() == 1) ? " problem was " : " problems were ");
writer.print("encountered while building the effective model");
if (modelId != null && modelId.length() > 0) {
if (modelId != null && !modelId.isEmpty()) {
writer.print(" for ");
writer.print(modelId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ static String toId(org.apache.maven.api.model.Model model) {
static String toId(String groupId, String artifactId, String version) {
StringBuilder buffer = new StringBuilder(128);

buffer.append((groupId != null && groupId.length() > 0) ? groupId : "[unknown-group-id]");
buffer.append((groupId != null && !groupId.isEmpty()) ? groupId : "[unknown-group-id]");
buffer.append(':');
buffer.append((artifactId != null && artifactId.length() > 0) ? artifactId : "[unknown-artifact-id]");
buffer.append((artifactId != null && !artifactId.isEmpty()) ? artifactId : "[unknown-artifact-id]");
buffer.append(':');
buffer.append((version != null && version.length() > 0) ? version : "[unknown-version]");
buffer.append((version != null && !version.isEmpty()) ? version : "[unknown-version]");

return buffer.toString();
}
Expand All @@ -127,7 +127,7 @@ public static String formatLocation(ModelProblem problem, String projectId) {
if (!problem.getModelId().equals(projectId)) {
buffer.append(problem.getModelId());

if (problem.getSource().length() > 0) {
if (!problem.getSource().isEmpty()) {
if (buffer.length() > 0) {
buffer.append(", ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private String appendPath(String parentUrl, String childPath, String pathAdjustm
}

private void concatPath(StringBuilder url, String path) {
if (path.length() > 0) {
if (!path.isEmpty()) {
boolean initialUrlEndsWithSlash = url.charAt(url.length() - 1) == '/';
boolean pathStartsWithSlash = path.charAt(0) == '/';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Object getValue(String expression) {

if (value != null && expression.startsWith(bannedPrefix)) {
String msg = "The expression ${" + expression + "} is deprecated.";
if (newPrefix != null && newPrefix.length() > 0) {
if (newPrefix != null && !newPrefix.isEmpty()) {
msg += " Please use ${" + newPrefix + expression.substring(bannedPrefix.length()) + "} instead.";
}
problems.add(new ModelProblemCollectorRequest(Severity.WARNING, Version.V20).setMessage(msg));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void write(OutputStream output, Map<String, Object> options, Model model)
Objects.requireNonNull(model, "model cannot be null");

String encoding = model.getModelEncoding();
if (encoding == null || encoding.length() <= 0) {
if (encoding == null || encoding.isEmpty()) {
encoding = "UTF-8";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean isActive(Profile profile, ProfileActivationContext context, Model

String version = context.getSystemProperties().get("java.version");

if (version == null || version.length() <= 0) {
if (version == null || version.isEmpty()) {
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
.setMessage("Failed to determine Java version for profile " + profile.getId())
.setLocation(activation.getLocation("jdk")));
Expand Down Expand Up @@ -110,7 +110,7 @@ private static boolean isInRange(String value, List<RangeValue> range) {
}

private static int getRelationOrder(String value, RangeValue rangeValue, boolean isLeft) {
if (rangeValue.value.length() <= 0) {
if (rangeValue.value.isEmpty()) {
return isLeft ? 1 : -1;
}

Expand Down Expand Up @@ -159,7 +159,7 @@ private static List<RangeValue> getRange(String range) {
ranges.add(new RangeValue(token.replace("]", ""), true));
} else if (token.endsWith(")")) {
ranges.add(new RangeValue(token.replace(")", ""), false));
} else if (token.length() <= 0) {
} else if (token.isEmpty()) {
ranges.add(new RangeValue("", false));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public boolean isActive(Profile profile, ProfileActivationContext context, Model
name = name.substring(1);
}

if (name == null || name.length() <= 0) {
if (name == null || name.isEmpty()) {
problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
.setMessage("The property name is required to activate the profile " + profile.getId())
.setLocation(property.getLocation("")));
Expand Down
Loading

0 comments on commit 83949a7

Please sign in to comment.