Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toString() to PlaceRequest. #284

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ public int hashCode() {
return 11 * (nameToken.hashCode() + (params == null ? 0 : params.hashCode()));
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't decide if StringBuilder is overkill. Seems like String concatenation is enough. What do you think @christiangoudreau?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is overkill, the only place where the Compiler isn't smart enough to do replace concatenation with string builders is within loops.

builder.append("PlaceRequest(nameToken=");
builder.append(nameToken);
builder.append(", params=");
builder.append(params);
builder.append(")");
return builder.toString();
}

/**
* Checks if this place request has the same name token as the one passed in.
*
Expand All @@ -179,7 +190,7 @@ public boolean hasSameNameToken(PlaceRequest other) {
return nameToken.equals(other.nameToken);
}

/**
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong format

* Checks if this place request matches the name token passed.
*
* @param nameToken The name token to match.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,17 @@ public void shouldBuildRequestWithParameterMap() {
assertEquals("value2", request.getParameter("name2", ""));
assertEquals("value3", request.getParameter("name3", ""));
}

@Test
public void testToString() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra bonus, nice :)

// when
PlaceRequest request = new PlaceRequest.Builder().nameToken("nameToken").with("name1", "value1")
.with("name2", "value2").build();

// then
assertNotNull(request);
assertNotNull(request.toString());
assertEquals("PlaceRequest(nameToken=nameToken, params={name1=value1, name2=value2})",
request.toString());
}
}