Skip to content

Commit

Permalink
[SHRINKRES-321] Replacing size() == 0/length() == 0 with isEmpty()
Browse files Browse the repository at this point in the history
  • Loading branch information
petrberan committed Mar 4, 2024
1 parent c34f590 commit b6dd790
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static PackagingType of(String typeName) throws IllegalArgumentException
*/
public static PackagingType fromCache(String typeName) throws IllegalArgumentException {

if (typeName == null || typeName.length() == 0) {
if (typeName == null || typeName.isEmpty()) {
throw new IllegalArgumentException("Packaging type must not be null nor empty.");
}
// return from cache if available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String toString() {
*/
public static ScopeType fromScopeType(String scopeName) throws IllegalArgumentException {

if (scopeName == null || scopeName.length() == 0) {
if (scopeName == null || scopeName.isEmpty()) {
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, "Empty scope was replaced with default {0}", COMPILE.value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ public final String getVersion() {
public final String toCanonicalForm() {

final StringBuilder sb = new StringBuilder(super.toCanonicalForm());
if (version == null || version.length() == 0) {
if (version == null || version.isEmpty()) {
return sb.toString();
}
if (classifier != null && classifier.length() > 0 && packaging != null) {
if (classifier != null && !classifier.isEmpty() && packaging != null) {
sb.append(SEPARATOR_COORDINATE).append(packaging.getId()).append(SEPARATOR_COORDINATE)
.append(classifier).append(SEPARATOR_COORDINATE).append(version);
}
if ((classifier == null || classifier.length() == 0) && packaging != null) {
if ((classifier == null || classifier.isEmpty()) && packaging != null) {
sb.append(SEPARATOR_COORDINATE).append(packaging.getId()).append(SEPARATOR_COORDINATE).append(version);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private MavenCoordinates() {
*/
public static MavenCoordinate createCoordinate(final String canonicalForm) throws IllegalArgumentException,
CoordinateParseException {
if (canonicalForm == null || canonicalForm.length() == 0) {
if (canonicalForm == null || canonicalForm.isEmpty()) {
throw new IllegalArgumentException("canonical form is required");
}
final MavenCoordinateParser parser = MavenCoordinateParser.parse(canonicalForm);
Expand All @@ -71,10 +71,10 @@ public static MavenCoordinate createCoordinate(final String canonicalForm) throw
*/
public static MavenCoordinate createCoordinate(final String groupId, final String artifactId, final String version,
final PackagingType packaging, final String classifier) throws IllegalArgumentException {
if (groupId == null || groupId.length() == 0) {
if (groupId == null || groupId.isEmpty()) {
throw new IllegalArgumentException("groupId is required");
}
if (artifactId == null || artifactId.length() == 0) {
if (artifactId == null || artifactId.isEmpty()) {
throw new IllegalArgumentException("artifactId is required");
}
final MavenCoordinateImpl coordinate = new MavenCoordinateImpl(groupId, artifactId, version, packaging,
Expand Down Expand Up @@ -143,12 +143,12 @@ static MavenCoordinateParser parse(final String coordinates) throws CoordinatePa
parser.version = position3;
break;
case 3:
parser.type = (position3 == null || position3.length() == 0) ? PackagingType.JAR
parser.type = (position3 == null || position3.isEmpty()) ? PackagingType.JAR
: toPackagingType(position3);
parser.version = position4;
break;
default:
parser.type = (position3 == null || position3.length() == 0) ? PackagingType.JAR
parser.type = (position3 == null || position3.isEmpty()) ? PackagingType.JAR
: toPackagingType(position3);
parser.classifier = position4;
parser.version = position5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private MavenDependencies() {
public static MavenDependency createDependency(final String canonicalForm, final ScopeType scope,
final boolean optional, final MavenDependencyExclusion... exclusions) throws IllegalArgumentException,
CoordinateParseException {
if (canonicalForm == null || canonicalForm.length() == 0) {
if (canonicalForm == null || canonicalForm.isEmpty()) {
throw new IllegalArgumentException("canonical form is required");
}
final MavenCoordinate delegate = MavenCoordinates.createCoordinate(canonicalForm);
Expand Down Expand Up @@ -134,7 +134,7 @@ private static MavenDependency newInstance(final MavenCoordinate coordinate, fin
*/
public static MavenDependencyExclusion createExclusion(final String canonicalForm) throws IllegalArgumentException,
CoordinateParseException {
if (canonicalForm == null || canonicalForm.length() == 0) {
if (canonicalForm == null || canonicalForm.isEmpty()) {
throw new IllegalArgumentException("canonical form is required");
}
final StringTokenizer tokenizer = new StringTokenizer(canonicalForm,
Expand Down Expand Up @@ -167,10 +167,10 @@ public static MavenDependencyExclusion createExclusion(final String canonicalFor
*/
public static MavenDependencyExclusion createExclusion(final String groupId, final String artifactId)
throws IllegalArgumentException {
if (groupId == null || groupId.length() == 0) {
if (groupId == null || groupId.isEmpty()) {
throw new IllegalArgumentException("groupId must be specified");
}
if (artifactId == null || artifactId.length() == 0) {
if (artifactId == null || artifactId.isEmpty()) {
throw new IllegalArgumentException("groupId must be specified");
}
final MavenDependencyExclusion exclusion = new MavenDependencyExclusionImpl(groupId, artifactId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class MavenGABaseImpl implements MavenGABase {
MavenGABaseImpl(final String groupId, final String artifactId) {

// Precondition checks
assert groupId != null && groupId.length() > 0 : "groupId is required";
assert artifactId != null && artifactId.length() > 0 : "artifactId is required";
assert groupId != null && !groupId.isEmpty() : "groupId is required";
assert artifactId != null && !artifactId.isEmpty() : "artifactId is required";

// Set properties
this.groupId = groupId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean accepts(final MavenDependency dependency, final List<MavenDepende
}

if (rejectTransitives) {
if (dependencyAncestors != null && dependencyAncestors.size() != 0) {
if (dependencyAncestors != null && !dependencyAncestors.isEmpty()) {
return dependencyAncestors.get(0).equals(dependency);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public Map<String, String> getAdditionalCompilerArgs() {
Map<String, String> compilerArgumentsAsMap = new HashMap<String, String>(additionalCompilerArguments.size()
+ additionalCompilerArgs.size() + 1);

if (additionalCompilerArgument.length() > 0) {
if (!additionalCompilerArgument.isEmpty()) {
compilerArgumentsAsMap.put(additionalCompilerArgument, null);
}
if (additionalCompilerArguments.size() > 0) {
if (!additionalCompilerArguments.isEmpty()) {
compilerArgumentsAsMap.putAll(additionalCompilerArguments);
}
if (additionalCompilerArgs.size() > 0) {
if (!additionalCompilerArgs.isEmpty()) {
for (String value : additionalCompilerArgs) {
compilerArgumentsAsMap.put(value, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ConfigurationUtils {
static String valueAsString(Map<String, Object> map, Key key, String defaultValue) {
Validate.notNullOrEmpty(key.key, "Key for plugin configuration must be set");
if (map.containsKey(key.key)) {
return map.get(key.key).toString().length() == 0 ? defaultValue : map.get(key.key).toString();
return map.get(key.key).toString().isEmpty() ? defaultValue : map.get(key.key).toString();
}
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ ManifestBuilder loadFile() throws MavenImporterException {
}

ManifestBuilder addManifestEntries() {
if (getManifestEntries().size() > 0) {
if (!getManifestEntries().isEmpty()) {
for (Map.Entry<String, String> entry : getManifestEntries().entrySet()) {
addMainAttribute(entry.getKey(), entry.getValue());
}
Expand All @@ -228,7 +228,7 @@ ManifestBuilder addManifestEntries() {
}

ManifestBuilder addManifestSections() {
if (getManifestSections().size() > 0) {
if (!getManifestSections().isEmpty()) {
for (Map.Entry<String, Map<String, String>> entry : getManifestSections().entrySet()) {
for (Map.Entry<String, String> attrs : entry.getValue().entrySet()) {
addSectionAttribute(entry.getKey(), attrs.getKey(), attrs.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void stateNotNull(final Object obj, final String message) throws I
* @throws IllegalArgumentException Thrown if {@code collection} is {@code null} or empty
*/
public static void notEmpty(final Collection<?> collection, final String message) throws IllegalArgumentException {
if (collection == null || collection.size() == 0) {
if (collection == null || collection.isEmpty()) {
throw new IllegalArgumentException(message);
}
}
Expand All @@ -78,7 +78,7 @@ public static void notEmpty(final Collection<?> collection, final String message
* @return {@code true} if specified String is null or empty, {@code false} otherwise
*/
public static boolean isNullOrEmpty(final String string) {
return (string == null || string.length() == 0);
return (string == null || string.isEmpty());
}

/**
Expand All @@ -89,7 +89,7 @@ public static boolean isNullOrEmpty(final String string) {
* @return {@code true} if specified String is null or empty, {@code false} otherwise
*/
public static boolean isNullOrEmptyOrQuestionMark(final String string) {
return (string == null || string.length() == 0 || "?".equals(string));
return (string == null || string.isEmpty() || "?".equals(string));
}

/**
Expand All @@ -100,7 +100,7 @@ public static boolean isNullOrEmptyOrQuestionMark(final String string) {
* @throws IllegalArgumentException Thrown if string is null
*/
public static void notNullOrEmpty(final String string, final String message) throws IllegalArgumentException {
if (string == null || string.length() == 0) {
if (string == null || string.isEmpty()) {
throw new IllegalArgumentException(message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected MavenArtifactInfoImpl(final Artifact artifact, final ScopeType scopeTy
final List<DependencyNode> children, boolean optional) {

final PackagingType packaging = PackagingType.of(artifact.getProperty(ArtifactProperties.TYPE, artifact.getExtension()));
final String classifier = artifact.getClassifier().length() == 0 ? packaging.getClassifier() : artifact.getClassifier();
final String classifier = artifact.getClassifier().isEmpty() ? packaging.getClassifier() : artifact.getClassifier();

this.mavenCoordinate = MavenCoordinates.createCoordinate(artifact.getGroupId(), artifact.getArtifactId(),
artifact.getBaseVersion(), packaging, classifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private RESOLVESTAGETYPE addDependencies(final String... coordinates) throws Coo
throw new IllegalArgumentException("At least one coordinate must be specified");
}
for (final String coordinate : coordinates) {
if (coordinate == null || coordinate.length() == 0) {
if (coordinate == null || coordinate.isEmpty()) {
throw new IllegalArgumentException("null dependency not permitted");
}
final MavenDependency dependency = this.resolveDependency(coordinate);
Expand All @@ -178,7 +178,7 @@ private RESOLVESTAGETYPE addDependencies(final String... coordinates) throws Coo
}

private MavenDependency resolveDependency(final String coordinate) {
assert coordinate != null && coordinate.length() > 0 : "Coordinate is required";
assert coordinate != null && !coordinate.isEmpty() : "Coordinate is required";
final MavenCoordinate newCoordinate = MavenCoordinates.createCoordinate(coordinate);
final MavenDependency declared = MavenDependencies.createDependency(newCoordinate, null, false);
final MavenDependency resolved = this.resolveDependency(declared);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ private SettingsBuildingRequest getDefaultSettingsBuildingRequest() {
request.setGlobalSettingsFile(new File(DEFAULT_GLOBAL_SETTINGS_PATH));
request.setUserSettingsFile(new File(DEFAULT_USER_SETTINGS_PATH));
// set alternate files
if (altUserSettings != null && altUserSettings.length() > 0) {
if (altUserSettings != null && !altUserSettings.isEmpty()) {
request.setUserSettingsFile(new File(altUserSettings));
}

if (altGlobalSettings != null && altGlobalSettings.length() > 0) {
if (altGlobalSettings != null && !altGlobalSettings.isEmpty()) {
request.setGlobalSettingsFile(new File(altGlobalSettings));
}

Expand All @@ -221,15 +221,15 @@ private Settings decryptPasswords(Settings settings) {
String altSecuritySettings = SecurityActions.getProperty(ALT_SECURITY_SETTINGS_XML_LOCATION);

// set alternate file
if (altSecuritySettings != null && altSecuritySettings.length() > 0) {
if (altSecuritySettings != null && !altSecuritySettings.isEmpty()) {
securitySettings = new File(altSecuritySettings);
}

SettingsDecrypter decrypter = new MavenSettingsDecrypter(securitySettings);
SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(settings);
SettingsDecryptionResult result = decrypter.decrypt(request);

if (result.getProblems().size() > 0) {
if (!result.getProblems().isEmpty()) {
StringBuilder sb = new StringBuilder("Found ").append(result.getProblems().size())
.append(" problems while trying to decrypt settings configuration.");

Expand All @@ -251,13 +251,13 @@ private Settings decryptPasswords(Settings settings) {
private Settings enrichWithLocalRepository(Settings settings) {

// set default value if not set at all
if (settings.getLocalRepository() == null || settings.getLocalRepository().length() == 0) {
if (settings.getLocalRepository() == null || settings.getLocalRepository().isEmpty()) {
settings.setLocalRepository(DEFAULT_REPOSITORY_PATH);
}

// override any value with system property based location
String altLocalRepository = SecurityActions.getProperty(ALT_LOCAL_REPOSITORY_LOCATION);
if (altLocalRepository != null && altLocalRepository.length() > 0) {
if (altLocalRepository != null && !altLocalRepository.isEmpty()) {
settings.setLocalRepository(altLocalRepository);
}
return settings;
Expand All @@ -267,7 +267,7 @@ private Settings enrichWithLocalRepository(Settings settings) {
private Settings enrichWithOfflineMode(Settings settings) {

String goOffline = SecurityActions.getProperty(ALT_MAVEN_OFFLINE);
if (goOffline != null && goOffline.length() > 0) {
if (goOffline != null && !goOffline.isEmpty()) {
settings.setOffline(Boolean.valueOf(goOffline));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ public static String toCanonicalForm(final Artifact artifact) {

final PackagingType packaging = PackagingType
.of(artifact.getProperty(ArtifactProperties.TYPE, artifact.getExtension()));
final String classifier = artifact.getClassifier().length() == 0 ? packaging.getClassifier() : artifact.getClassifier();
final String classifier = artifact.getClassifier().isEmpty() ? packaging.getClassifier() : artifact.getClassifier();

sb.append(packaging.getId()).append(":");
if (classifier.length() != 0) {
if (!classifier.isEmpty()) {
sb.append(classifier).append(":");
}
sb.append(artifact.getVersion());
Expand All @@ -120,7 +120,7 @@ public static MavenDependency fromDependency(final Dependency dependency) {

final PackagingType packaging = PackagingType
.of(artifact.getProperty(ArtifactProperties.TYPE, artifact.getExtension()));
final String classifier = artifact.getClassifier().length() == 0 ? packaging.getClassifier() : artifact.getClassifier();
final String classifier = artifact.getClassifier().isEmpty() ? packaging.getClassifier() : artifact.getClassifier();

final MavenCoordinate coordinate = MavenCoordinates.createCoordinate(artifact.getGroupId(),
artifact.getArtifactId(), artifact.getVersion(), packaging, classifier);
Expand Down Expand Up @@ -166,7 +166,7 @@ public static MavenDependency fromDependency(org.apache.maven.model.Dependency d
stereotype = new DefaultArtifactType(dependency.getType());
}

boolean system = dependency.getSystemPath() != null && dependency.getSystemPath().length() > 0;
boolean system = dependency.getSystemPath() != null && !dependency.getSystemPath().isEmpty();

Map<String, String> props = null;
if (system) {
Expand All @@ -183,7 +183,7 @@ public static MavenDependency fromDependency(org.apache.maven.model.Dependency d

final PackagingType packaging = PackagingType
.of(artifact.getProperty(ArtifactProperties.TYPE, artifact.getExtension()));
final String classifier = artifact.getClassifier().length() == 0 ? packaging.getClassifier() : artifact.getClassifier();
final String classifier = artifact.getClassifier().isEmpty() ? packaging.getClassifier() : artifact.getClassifier();

final MavenCoordinate coordinate = MavenCoordinates.createCoordinate(artifact.getGroupId(),
artifact.getArtifactId(), artifact.getVersion(), packaging, classifier);
Expand Down Expand Up @@ -264,8 +264,8 @@ public static Exclusion asExclusion(MavenDependencyExclusion coordinates) {
String group = coordinates.getGroupId();
String artifact = coordinates.getArtifactId();

group = (group == null || group.length() == 0) ? "*" : group;
artifact = (artifact == null || artifact.length() == 0) ? "*" : artifact;
group = (group == null || group.isEmpty()) ? "*" : group;
artifact = (artifact == null || artifact.isEmpty()) ? "*" : artifact;

return new Exclusion(group, artifact, "*", "*");
}
Expand Down
Loading

0 comments on commit b6dd790

Please sign in to comment.