Skip to content

Commit

Permalink
rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke committed Oct 11, 2022
1 parent 3a6fe03 commit cdc0a4c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
20 changes: 10 additions & 10 deletions twitter4j-core/src/testv1/java/twitter4j/SearchAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SearchAPITest extends TwitterTestBase {
void testQuery() {
var format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Query query = Query.of("test")
.withUntil(format.format(LocalDateTime.now().minus(24,ChronoUnit.DAYS)));
.until(format.format(LocalDateTime.now().minus(24,ChronoUnit.DAYS)));
HttpParameter[] params = SearchResourceImpl.asHttpParameterArray(query);
assertTrue(findParameter(params, "q"));
assertTrue(findParameter(params, "until"));
Expand All @@ -61,7 +61,7 @@ void testSearch() throws Exception {
String queryStr = "test";
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String dateStr = format.format(LocalDateTime.now().minus(1,ChronoUnit.DAYS));
Query query = Query.of(queryStr).withUntil(dateStr);
Query query = Query.of(queryStr).until(dateStr);
QueryResult queryResult = twitter1.v1().search().search(query);
RateLimitStatus rateLimitStatus = queryResult.getRateLimitStatus();
assertTrue(-1 != queryResult.getSinceId(), "sinceId");
Expand Down Expand Up @@ -99,24 +99,24 @@ void testSearch() throws Exception {
assertEquals(queryStr, queryResult.getQuery());
assertTrue(0 < queryResult.getTweets().size());
query = Query.of("starbucks")
.withGeoCode(new GeoLocation(47.6094651, -122.3411666), 10, Query.KILOMETERS);
.geoCode(new GeoLocation(47.6094651, -122.3411666), 10, Query.KILOMETERS);
queryResult = twitter1.v1().search().search(query);
assertTrue(0 < queryResult.getTweets().size());

query = Query.of("from:tsuda").withSinceId(1671199128);
query = Query.of("from:tsuda").sinceId(1671199128);
queryResult = twitter1.v1().search().search(query);
assertTrue(0 < queryResult.getTweets().size());
assertEquals(4171231, queryResult.getTweets().get(0).getUser().getId());
assertTrue(queryResult.hasNext());
assertNotNull(queryResult.nextQuery());

query = Query.of("\\u5e30%u5e30 <%}& foobar").withCount(100);
query = Query.of("\\u5e30%u5e30 <%}& foobar").count(100);
twitter1.v1().search().search(query);
}

@Test
void testEasyPaging() throws Exception {
Query query = Query.of("from:twit4j doesnothit").withResultType(Query.POPULAR);
Query query = Query.of("from:twit4j doesnothit").resultType(Query.POPULAR);
QueryResult result = twitter1.v1().search().search(query);
assertFalse(result.hasNext());

Expand All @@ -134,10 +134,10 @@ void testEasyPaging2() throws Exception {

String lang = "en";
Query query = Query.of("twitter")
.withLang(lang)
.withResultType(Query.ResultType.recent)
.withSince("2017-01-01")
.withUntil(until);
.lang(lang)
.resultType(Query.ResultType.recent)
.since("2017-01-01")
.until(until);
assertEquals(lang, query.lang);
QueryResult qr = twitter1.v1().search().search(query);
Query nextQuery = qr.nextQuery();
Expand Down
12 changes: 6 additions & 6 deletions twitter4j-core/src/v1/java/twitter4j/QueryResultJSONImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ static Query createWithNextPageQuery(@NotNull String nextPageQuery) {

Query query = Query.of(params.getOrDefault("q", ""));
if (params.containsKey("lang")) {
query = query.withLang(params.get("lang"));
query = query.lang(params.get("lang"));
}
if (params.containsKey("locale")) {
query = query.withLocale(params.get("locale"));
query = query.locale(params.get("locale"));
}
if (params.containsKey("max_id")) {
query = query.withMaxId(Long.parseLong(params.get("max_id")));
query = query.maxId(Long.parseLong(params.get("max_id")));
}
if (params.containsKey("count")) {
query = query.withCount(Integer.parseInt(params.get("count")));
query = query.count(Integer.parseInt(params.get("count")));
}
if (params.containsKey("geocode")) {
String[] parts = params.get("geocode").split(",");
Expand All @@ -115,7 +115,7 @@ static Query createWithNextPageQuery(@NotNull String nextPageQuery) {
if (radiusstr.endsWith(value.name())) {
radius = Double.parseDouble(radiusstr.substring(0, radiusstr.length() - 2));
unit = value;
query = query.withGeoCode(new GeoLocation(latitude, longitude), radius, unit);
query = query.geoCode(new GeoLocation(latitude, longitude), radius, unit);
break;
}
if (unit == null) {
Expand All @@ -126,7 +126,7 @@ static Query createWithNextPageQuery(@NotNull String nextPageQuery) {
Query.ResultType resultType;
if (params.containsKey("result_type")) {
resultType = Query.ResultType.valueOf(params.get("result_type"));
query = query.withResultType(resultType);
query = query.resultType(resultType);
}
return query;
}
Expand Down
18 changes: 9 additions & 9 deletions twitter4j-core/src/v1/java/twitter4j/v1/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public final class Query implements java.io.Serializable {
* @return new Query instance
*/
@NotNull
public Query withLang(@NotNull String lang) {
public Query lang(@NotNull String lang) {
return new Query(query, lang, locale, maxId, count, since, sinceId, geocode, until, resultType, nextPageQuery);
}

Expand All @@ -103,7 +103,7 @@ public Query withLang(@NotNull String lang) {
* @return new Query instance
*/
@NotNull
public Query withLocale(@NotNull String locale) {
public Query locale(@NotNull String locale) {
return new Query(query, lang, locale, maxId, count, since, sinceId, geocode, until, resultType, nextPageQuery);
}

Expand All @@ -115,7 +115,7 @@ public Query withLocale(@NotNull String locale) {
*/

@NotNull
public Query withMaxId(long maxId) {
public Query maxId(long maxId) {
return new Query(query, lang, locale, maxId, count, since, sinceId, geocode, until, resultType, nextPageQuery);
}

Expand All @@ -127,7 +127,7 @@ public Query withMaxId(long maxId) {
*/

@NotNull
public Query withCount(int count) {
public Query count(int count) {
return new Query(query, lang, locale, maxId, count, since, sinceId, geocode, until, resultType, nextPageQuery);
}

Expand All @@ -139,7 +139,7 @@ public Query withCount(int count) {
*/

@NotNull
public Query withSince(@NotNull String since) {
public Query since(@NotNull String since) {
return new Query(query, lang, locale, maxId, count, since, sinceId, geocode, null, resultType, nextPageQuery);
}

Expand All @@ -151,7 +151,7 @@ public Query withSince(@NotNull String since) {
*/

@NotNull
public Query withSinceId(long sinceId) {
public Query sinceId(long sinceId) {
return new Query(query, lang, locale, maxId, count, since, sinceId, geocode, until, resultType, nextPageQuery);
}

Expand All @@ -165,7 +165,7 @@ public Query withSinceId(long sinceId) {
*/

@NotNull
public Query withGeoCode(@NotNull GeoLocation location, double radius
public Query geoCode(@NotNull GeoLocation location, double radius
, Unit unit) {
String geocode = location.latitude + "," + location.longitude + "," + radius + unit.name();
return new Query(query, lang, locale, maxId, count, since, sinceId, geocode, until, resultType, nextPageQuery);
Expand All @@ -179,7 +179,7 @@ public Query withGeoCode(@NotNull GeoLocation location, double radius
*/

@NotNull
public Query withUntil(@NotNull String until) {
public Query until(@NotNull String until) {
return new Query(query, lang, locale, maxId, count, since, sinceId, geocode, until, resultType, nextPageQuery);
}

Expand All @@ -190,7 +190,7 @@ public Query withUntil(@NotNull String until) {
* @return new Query instance
*/
@NotNull
public Query withResultType(@NotNull ResultType resultType) {
public Query resultType(@NotNull ResultType resultType) {
return new Query(query, lang, locale, maxId, count, since, sinceId, geocode, until, resultType, nextPageQuery);
}

Expand Down

0 comments on commit cdc0a4c

Please sign in to comment.