Skip to content

Commit

Permalink
yegor256#863 removed some nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyk committed Dec 22, 2018
1 parent 7a4efc7 commit 1e04fe7
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 55 deletions.
9 changes: 3 additions & 6 deletions src/main/java/org/takes/facets/auth/social/PsGoogle.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,9 @@ private static Identity parse(final JsonObject json) {
} else {
props.put(PsGoogle.PICTURE, image.getString("url", "#"));
}
if (json.containsKey(PsGoogle.DISPLAY_NAME)
&& json.get(PsGoogle.DISPLAY_NAME) != null) {
props.put(PsGoogle.NAME, json.getString(PsGoogle.DISPLAY_NAME));
} else {
props.put(PsGoogle.NAME, "unknown");
}
props.put(
PsGoogle.NAME, json.getString(PsGoogle.DISPLAY_NAME, "unknown")
);
return new Identity.Simple(
String.format("urn:google:%s", json.getString("id")), props
);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/takes/facets/fork/FkHitRefresh.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
*
* @since 0.9
* @see TkFork
* @todo #863:30min Continue removing nulls from the code base, there are still
* some places that use it and can be replaced with better code constructs.
*/
@EqualsAndHashCode
public final class FkHitRefresh implements Fork {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/takes/http/BkSafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public void accept(final Socket socket) {
try {
back.accept(socket);
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Throwable ex) {
assert ex != null;
} catch (final Throwable ignored) {
}
}
});
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/takes/http/FtBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ public void start(final Exit exit) throws IOException {
private void loop(final ServerSocket server) throws IOException {
try {
this.back.accept(server.accept());
} catch (final SocketTimeoutException ex) {
assert ex != null;
} catch (final SocketTimeoutException ignored) {
}
}

Expand Down
43 changes: 18 additions & 25 deletions src/main/java/org/takes/http/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ final class Options {
* @return TRUE if yes
*/
public boolean isDaemon() {
return this.map.get("daemon") != null;
return this.map.containsKey("daemon");
}

/**
Expand Down Expand Up @@ -131,44 +131,37 @@ public boolean hitRefresh() {
* @return Port number
*/
public long lifetime() {
final String value = this.map.get("lifetime");
final long msec;
if (value == null) {
msec = Long.MAX_VALUE;
} else {
msec = Long.parseLong(value);
}
return msec;
return Long.parseLong(
this.map.getOrDefault(
"lifetime", String.valueOf(Long.MAX_VALUE)
)
);
}

/**
* Get the threads.
* @return Threads
*/
public int threads() {
final String value = this.map.get("threads");
final int threads;
if (value == null) {
threads = Runtime.getRuntime().availableProcessors() << 2;
} else {
threads = Integer.parseInt(value);
}
return threads;
return Integer.parseInt(
this.map.getOrDefault(
"threads",
String.valueOf(Runtime.getRuntime().availableProcessors() << 2)
)
);
}

/**
* Get the max latency in milliseconds.
* @return Latency
*/
public long maxLatency() {
final String value = this.map.get("max-latency");
final long msec;
if (value == null) {
msec = Long.MAX_VALUE;
} else {
msec = Long.parseLong(value);
}
return msec;
return Long.parseLong(
this.map.getOrDefault(
"max-latency",
String.valueOf(Long.MAX_VALUE)
)
);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/takes/misc/Href.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,14 @@ public String bare() {
* @since 0.9
*/
public Iterable<String> param(final Object key) {
final List<String> values = this.params.get(key.toString());
final List<String> values = this.params.getOrDefault(
key.toString(),
Collections.emptyList()
);
final Iterable<String> iter;
if (values == null) {
if (values.isEmpty()) {
iter = new VerboseIterable<>(
Collections.<String>emptyList(),
Collections.emptyList(),
String.format(
"there are no URI params by name \"%s\" among %d others",
key, this.params.size()
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/takes/rq/RqHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ public Base(final Request req) {
@Override
public List<String> header(final CharSequence key)
throws IOException {
final List<String> values = this.map().get(
new EnglishLowerCase(key).string()
final List<String> values = this.map().getOrDefault(
new EnglishLowerCase(key).string(),
Collections.emptyList()
);
final List<String> list;
if (values == null) {
if (values.isEmpty()) {
list = new VerboseList<>(
Collections.<String>emptyList(),
Collections.emptyList(),
String.format(
// @checkstyle LineLengthCheck (1 line)
"there are no headers by name \"%s\" among %d others: %s",
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/takes/rq/form/RqFormBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ public RqFormBase(final Request request) {
@Override
public Iterable<String> param(final CharSequence key)
throws IOException {
final List<String> values =
this.map().get(new EnglishLowerCase(key.toString()).string());
final List<String> values = this.map().getOrDefault(
new EnglishLowerCase(key.toString()).string(),
Collections.emptyList()
);
final Iterable<String> iter;
if (values == null) {
if (values.isEmpty()) {
iter = new VerboseIterable<>(
Collections.<String>emptyList(),
Collections.emptyList(),
new Sprintf(
"there are no params \"%s\" among %d others: %s",
key, this.map().size(), this.map().keySet()
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/takes/rq/multipart/RqMtBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,14 @@ public RqMtBase(final Request req) throws IOException {

@Override
public Iterable<Request> part(final CharSequence name) {
final List<Request> values = this.map
.get(new EnglishLowerCase(name.toString()).string());
final List<Request> values = this.map.getOrDefault(
new EnglishLowerCase(name.toString()).string(),
Collections.emptyList()
);
final Iterable<Request> iter;
if (values == null) {
if (values.isEmpty()) {
iter = new VerboseIterable<>(
Collections.<Request>emptyList(),
Collections.emptyList(),
new Sprintf(
"there are no parts by name \"%s\" among %d others: %s",
name, this.map.size(), this.map.keySet()
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/takes/rs/RsWithStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ private static Iterable<String> head(final Response origin,
* @return Reason
*/
private static String best(final int code) {
String reason = RsWithStatus.REASONS.get(code);
if (reason == null) {
reason = "Unknown";
}
return reason;
return RsWithStatus.REASONS.getOrDefault(code, "Unknown");
}

/**
Expand Down

0 comments on commit 1e04fe7

Please sign in to comment.