Skip to content

Commit

Permalink
Changed while loop to enhanced for loop in ContainersListElement.java…
Browse files Browse the repository at this point in the history
… and Removed the if statement and replace with ternary statement in ContainerDetails.java

Signed-off-by: M. <[email protected]>
Co-Authored-By: Rohan Kumar <[email protected]>
  • Loading branch information
mdxabu and rohanKanojia committed Feb 21, 2024
1 parent e8c5826 commit dafb924
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
17 changes: 5 additions & 12 deletions src/main/java/io/fabric8/maven/docker/model/ContainerDetails.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package io.fabric8.maven.docker.model;

import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import java.time.Instant;
import java.util.*;


public class ContainerDetails implements Container {

Expand Down Expand Up @@ -77,10 +72,8 @@ public Map<String, String> getLabels() {
public String getName() {
String name = json.get(NAME).getAsString();

if (name.startsWith(SLASH)) {
name = name.substring(1);
}
return name;
return name.startsWith(SLASH) ? name.substring(1) :
name;

Check warning on line 76 in src/main/java/io/fabric8/maven/docker/model/ContainerDetails.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/fabric8/maven/docker/model/ContainerDetails.java#L76

Added line #L76 was not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.fabric8.maven.docker.model;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

public class ContainersListElement implements Container {

static final String CREATED = "Created";
Expand Down Expand Up @@ -133,9 +132,7 @@ private Map<String, String> mapLabels(JsonObject labels) {
int length = labels.size();
Map<String, String> mapped = new HashMap<>(length);

Iterator<String> iterator = labels.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
for (String key : labels.keySet()) {
mapped.put(key, labels.get(key).getAsString());
}

Expand Down

0 comments on commit dafb924

Please sign in to comment.