Merge pull request elastic/elasticsearch#653 from jasontedor/ints-be-gone

Remove use of com.google.common.primitives.Ints

Original commit: elastic/x-pack-elasticsearch@35a7b4a6ec
This commit is contained in:
Jason Tedor 2015-09-18 09:45:50 -04:00
commit 3ecc12963b
23 changed files with 145 additions and 78 deletions

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.activedirectory; package org.elasticsearch.shield.authc.activedirectory;
import com.google.common.primitives.Ints;
import com.unboundid.ldap.sdk.*; import com.unboundid.ldap.sdk.*;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
@ -38,7 +37,7 @@ public class ActiveDirectoryGroupsResolver implements GroupsResolver {
logger.debug("group SID to DN search filter: [{}]", groupSearchFilter); logger.debug("group SID to DN search filter: [{}]", groupSearchFilter);
SearchRequest searchRequest = new SearchRequest(baseDn, scope.scope(), groupSearchFilter, Strings.EMPTY_ARRAY); SearchRequest searchRequest = new SearchRequest(baseDn, scope.scope(), groupSearchFilter, Strings.EMPTY_ARRAY);
searchRequest.setTimeLimitSeconds(Ints.checkedCast(timeout.seconds())); searchRequest.setTimeLimitSeconds(Math.toIntExact(timeout.seconds()));
SearchResult results; SearchResult results;
try { try {
results = search(connection, searchRequest, logger); results = search(connection, searchRequest, logger);
@ -59,7 +58,7 @@ public class ActiveDirectoryGroupsResolver implements GroupsResolver {
static Filter buildGroupQuery(LDAPInterface connection, String userDn, TimeValue timeout, ESLogger logger) { static Filter buildGroupQuery(LDAPInterface connection, String userDn, TimeValue timeout, ESLogger logger) {
try { try {
SearchRequest request = new SearchRequest(userDn, SearchScope.BASE, OBJECT_CLASS_PRESENCE_FILTER, "tokenGroups"); SearchRequest request = new SearchRequest(userDn, SearchScope.BASE, OBJECT_CLASS_PRESENCE_FILTER, "tokenGroups");
request.setTimeLimitSeconds(Ints.checkedCast(timeout.seconds())); request.setTimeLimitSeconds(Math.toIntExact(timeout.seconds()));
SearchResultEntry entry = searchForEntry(connection, request, logger); SearchResultEntry entry = searchForEntry(connection, request, logger);
Attribute attribute = entry.getAttribute("tokenGroups"); Attribute attribute = entry.getAttribute("tokenGroups");
byte[][] tokenGroupSIDBytes = attribute.getValueByteArrays(); byte[][] tokenGroupSIDBytes = attribute.getValueByteArrays();

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.activedirectory; package org.elasticsearch.shield.authc.activedirectory;
import com.google.common.primitives.Ints;
import com.unboundid.ldap.sdk.*; import com.unboundid.ldap.sdk.*;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -107,7 +106,7 @@ public class ActiveDirectorySessionFactory extends SessionFactory {
try { try {
connection.bind(userPrincipal, new String(password.internalChars())); connection.bind(userPrincipal, new String(password.internalChars()));
SearchRequest searchRequest = new SearchRequest(userSearchDN, userSearchScope.scope(), createFilter(userSearchFilter, userName), Strings.EMPTY_ARRAY); SearchRequest searchRequest = new SearchRequest(userSearchDN, userSearchScope.scope(), createFilter(userSearchFilter, userName), Strings.EMPTY_ARRAY);
searchRequest.setTimeLimitSeconds(Ints.checkedCast(timeout.seconds())); searchRequest.setTimeLimitSeconds(Math.toIntExact(timeout.seconds()));
SearchResult results = search(connection, searchRequest, logger); SearchResult results = search(connection, searchRequest, logger);
int numResults = results.getEntryCount(); int numResults = results.getEntryCount();
if (numResults > 1) { if (numResults > 1) {

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.ldap; package org.elasticsearch.shield.authc.ldap;
import com.google.common.primitives.Ints;
import com.unboundid.ldap.sdk.*; import com.unboundid.ldap.sdk.*;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
@ -170,7 +169,7 @@ public class LdapUserSearchSessionFactory extends SessionFactory {
private String findUserDN(String user) throws Exception { private String findUserDN(String user) throws Exception {
SearchRequest request = new SearchRequest(userSearchBaseDn, scope.scope(), createEqualityFilter(userAttribute, encodeValue(user)), Strings.EMPTY_ARRAY); SearchRequest request = new SearchRequest(userSearchBaseDn, scope.scope(), createEqualityFilter(userAttribute, encodeValue(user)), Strings.EMPTY_ARRAY);
request.setTimeLimitSeconds(Ints.checkedCast(timeout.seconds())); request.setTimeLimitSeconds(Math.toIntExact(timeout.seconds()));
LDAPConnectionPool connectionPool = connectionPool(); LDAPConnectionPool connectionPool = connectionPool();
SearchResultEntry entry = searchForEntry(connectionPool, request, logger); SearchResultEntry entry = searchForEntry(connectionPool, request, logger);
if (entry == null) { if (entry == null) {

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.ldap; package org.elasticsearch.shield.authc.ldap;
import com.google.common.primitives.Ints;
import com.unboundid.ldap.sdk.*; import com.unboundid.ldap.sdk.*;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
@ -51,7 +50,7 @@ class SearchGroupsResolver implements GroupsResolver {
String userId = userAttribute != null ? readUserAttribute(connection, userDn, timeout, logger) : userDn; String userId = userAttribute != null ? readUserAttribute(connection, userDn, timeout, logger) : userDn;
try { try {
SearchRequest searchRequest = new SearchRequest(baseDn, scope.scope(), createFilter(filter, userId), Strings.EMPTY_ARRAY); SearchRequest searchRequest = new SearchRequest(baseDn, scope.scope(), createFilter(filter, userId), Strings.EMPTY_ARRAY);
searchRequest.setTimeLimitSeconds(Ints.checkedCast(timeout.seconds())); searchRequest.setTimeLimitSeconds(Math.toIntExact(timeout.seconds()));
SearchResult results = search(connection, searchRequest, logger); SearchResult results = search(connection, searchRequest, logger);
for (SearchResultEntry entry : results.getSearchEntries()) { for (SearchResultEntry entry : results.getSearchEntries()) {
groups.add(entry.getDN()); groups.add(entry.getDN());
@ -66,7 +65,7 @@ class SearchGroupsResolver implements GroupsResolver {
String readUserAttribute(LDAPInterface connection, String userDn, TimeValue timeout, ESLogger logger) { String readUserAttribute(LDAPInterface connection, String userDn, TimeValue timeout, ESLogger logger) {
try { try {
SearchRequest request = new SearchRequest(userDn, SearchScope.BASE, OBJECT_CLASS_PRESENCE_FILTER, userAttribute); SearchRequest request = new SearchRequest(userDn, SearchScope.BASE, OBJECT_CLASS_PRESENCE_FILTER, userAttribute);
request.setTimeLimitSeconds(Ints.checkedCast(timeout.seconds())); request.setTimeLimitSeconds(Math.toIntExact(timeout.seconds()));
SearchResultEntry results = searchForEntry(connection, request, logger); SearchResultEntry results = searchForEntry(connection, request, logger);
Attribute attribute = results.getAttribute(userAttribute); Attribute attribute = results.getAttribute(userAttribute);
if (attribute == null) { if (attribute == null) {

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.ldap; package org.elasticsearch.shield.authc.ldap;
import com.google.common.primitives.Ints;
import com.unboundid.ldap.sdk.*; import com.unboundid.ldap.sdk.*;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
@ -39,7 +38,7 @@ class UserAttributeGroupsResolver implements GroupsResolver {
public List<String> resolve(LDAPInterface connection, String userDn, TimeValue timeout, ESLogger logger) { public List<String> resolve(LDAPInterface connection, String userDn, TimeValue timeout, ESLogger logger) {
try { try {
SearchRequest request = new SearchRequest(userDn, SearchScope.BASE, OBJECT_CLASS_PRESENCE_FILTER, attribute); SearchRequest request = new SearchRequest(userDn, SearchScope.BASE, OBJECT_CLASS_PRESENCE_FILTER, attribute);
request.setTimeLimitSeconds(Ints.checkedCast(timeout.seconds())); request.setTimeLimitSeconds(Math.toIntExact(timeout.seconds()));
SearchResultEntry result = searchForEntry(connection, request, logger); SearchResultEntry result = searchForEntry(connection, request, logger);
Attribute attributeReturned = result.getAttribute(attribute); Attribute attributeReturned = result.getAttribute(attribute);
if (attributeReturned == null) { if (attributeReturned == null) {

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.ldap.support; package org.elasticsearch.shield.authc.ldap.support;
import com.google.common.primitives.Ints;
import com.unboundid.ldap.sdk.LDAPConnectionOptions; import com.unboundid.ldap.sdk.LDAPConnectionOptions;
import com.unboundid.ldap.sdk.LDAPException; import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPURL; import com.unboundid.ldap.sdk.LDAPURL;
@ -94,7 +93,7 @@ public abstract class SessionFactory {
protected static LDAPConnectionOptions connectionOptions(Settings settings) { protected static LDAPConnectionOptions connectionOptions(Settings settings) {
LDAPConnectionOptions options = new LDAPConnectionOptions(); LDAPConnectionOptions options = new LDAPConnectionOptions();
options.setConnectTimeoutMillis(Ints.checkedCast(settings.getAsTime(TIMEOUT_TCP_CONNECTION_SETTING, TIMEOUT_DEFAULT).millis())); options.setConnectTimeoutMillis(Math.toIntExact(settings.getAsTime(TIMEOUT_TCP_CONNECTION_SETTING, TIMEOUT_DEFAULT).millis()));
options.setFollowReferrals(settings.getAsBoolean(FOLLOW_REFERRALS_SETTING, true)); options.setFollowReferrals(settings.getAsBoolean(FOLLOW_REFERRALS_SETTING, true));
options.setResponseTimeoutMillis(settings.getAsTime(TIMEOUT_TCP_READ_SETTING, TIMEOUT_DEFAULT).millis()); options.setResponseTimeoutMillis(settings.getAsTime(TIMEOUT_TCP_READ_SETTING, TIMEOUT_DEFAULT).millis());
options.setAutoReconnect(true); options.setAutoReconnect(true);

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.ssl; package org.elasticsearch.shield.ssl;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
@ -207,7 +206,7 @@ public abstract class AbstractSSLService extends AbstractComponent {
SSLContext sslContext = SSLContext.getInstance(sslProtocol); SSLContext sslContext = SSLContext.getInstance(sslProtocol);
sslContext.init(keyManagers, trustManagers, null); sslContext.init(keyManagers, trustManagers, null);
sslContext.getServerSessionContext().setSessionCacheSize(sessionCacheSize); sslContext.getServerSessionContext().setSessionCacheSize(sessionCacheSize);
sslContext.getServerSessionContext().setSessionTimeout(Ints.checkedCast(sessionCacheTimeout.seconds())); sslContext.getServerSessionContext().setSessionTimeout(Math.toIntExact(sessionCacheTimeout.seconds()));
return sslContext; return sslContext;
} catch (Exception e) { } catch (Exception e) {
throw new ElasticsearchException("failed to initialize the SSLContext", e); throw new ElasticsearchException("failed to initialize the SSLContext", e);

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.activedirectory; package org.elasticsearch.shield.authc.activedirectory;
import com.google.common.primitives.Ints;
import com.unboundid.ldap.sdk.Filter; import com.unboundid.ldap.sdk.Filter;
import com.unboundid.ldap.sdk.LDAPConnection; import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPConnectionOptions; import com.unboundid.ldap.sdk.LDAPConnectionOptions;
@ -51,7 +50,7 @@ public class ActiveDirectoryGroupsResolverTests extends ESTestCase {
options.setFollowReferrals(true); options.setFollowReferrals(true);
options.setAutoReconnect(true); options.setAutoReconnect(true);
options.setAllowConcurrentSocketFactoryUse(true); options.setAllowConcurrentSocketFactoryUse(true);
options.setConnectTimeoutMillis(Ints.checkedCast(SessionFactory.TIMEOUT_DEFAULT.millis())); options.setConnectTimeoutMillis(Math.toIntExact(SessionFactory.TIMEOUT_DEFAULT.millis()));
options.setResponseTimeoutMillis(SessionFactory.TIMEOUT_DEFAULT.millis()); options.setResponseTimeoutMillis(SessionFactory.TIMEOUT_DEFAULT.millis());
ldapConnection = new LDAPConnection(clientSSLService.sslSocketFactory(), options, ldapurl.getHost(), ldapurl.getPort(), BRUCE_BANNER_DN, ActiveDirectorySessionFactoryTests.PASSWORD); ldapConnection = new LDAPConnection(clientSSLService.sslSocketFactory(), options, ldapurl.getHost(), ldapurl.getPort(), BRUCE_BANNER_DN, ActiveDirectorySessionFactoryTests.PASSWORD);
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.ldap; package org.elasticsearch.shield.authc.ldap;
import com.google.common.primitives.Ints;
import com.unboundid.ldap.sdk.LDAPConnection; import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPConnectionOptions; import com.unboundid.ldap.sdk.LDAPConnectionOptions;
import com.unboundid.ldap.sdk.LDAPURL; import com.unboundid.ldap.sdk.LDAPURL;
@ -51,7 +50,7 @@ public class SearchGroupsResolverTests extends ESTestCase {
options.setFollowReferrals(true); options.setFollowReferrals(true);
options.setAutoReconnect(true); options.setAutoReconnect(true);
options.setAllowConcurrentSocketFactoryUse(true); options.setAllowConcurrentSocketFactoryUse(true);
options.setConnectTimeoutMillis(Ints.checkedCast(SessionFactory.TIMEOUT_DEFAULT.millis())); options.setConnectTimeoutMillis(Math.toIntExact(SessionFactory.TIMEOUT_DEFAULT.millis()));
options.setResponseTimeoutMillis(SessionFactory.TIMEOUT_DEFAULT.millis()); options.setResponseTimeoutMillis(SessionFactory.TIMEOUT_DEFAULT.millis());
ldapConnection = new LDAPConnection(clientSSLService.sslSocketFactory(), options, ldapurl.getHost(), ldapurl.getPort(), BRUCE_BANNER_DN, OpenLdapTests.PASSWORD); ldapConnection = new LDAPConnection(clientSSLService.sslSocketFactory(), options, ldapurl.getHost(), ldapurl.getPort(), BRUCE_BANNER_DN, OpenLdapTests.PASSWORD);
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.ldap; package org.elasticsearch.shield.authc.ldap;
import com.google.common.primitives.Ints;
import com.unboundid.ldap.sdk.LDAPConnection; import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPConnectionOptions; import com.unboundid.ldap.sdk.LDAPConnectionOptions;
import com.unboundid.ldap.sdk.LDAPURL; import com.unboundid.ldap.sdk.LDAPURL;
@ -49,7 +48,7 @@ public class UserAttributeGroupsResolverTests extends ESTestCase {
options.setFollowReferrals(true); options.setFollowReferrals(true);
options.setAutoReconnect(true); options.setAutoReconnect(true);
options.setAllowConcurrentSocketFactoryUse(true); options.setAllowConcurrentSocketFactoryUse(true);
options.setConnectTimeoutMillis(Ints.checkedCast(SessionFactory.TIMEOUT_DEFAULT.millis())); options.setConnectTimeoutMillis(Math.toIntExact(SessionFactory.TIMEOUT_DEFAULT.millis()));
options.setResponseTimeoutMillis(SessionFactory.TIMEOUT_DEFAULT.millis()); options.setResponseTimeoutMillis(SessionFactory.TIMEOUT_DEFAULT.millis());
ldapConnection = new LDAPConnection(clientSSLService.sslSocketFactory(), options, ldapurl.getHost(), ldapurl.getPort(), BRUCE_BANNER_DN, ActiveDirectorySessionFactoryTests.PASSWORD); ldapConnection = new LDAPConnection(clientSSLService.sslSocketFactory(), options, ldapurl.getHost(), ldapurl.getPort(), BRUCE_BANNER_DN, ActiveDirectorySessionFactoryTests.PASSWORD);
} }

View File

@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.watcher.support;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
public class Integers {
private Integers() {
}
public static Iterable<Integer> asIterable(int[] values) {
Objects.requireNonNull(values);
return () -> new Iterator<Integer>() {
private int position = 0;
@Override
public boolean hasNext() {
return position < values.length;
}
@Override
public Integer next() {
if (position < values.length) {
return values[position++];
} else {
throw new NoSuchElementException("position: " + position + ", length: " + values.length);
}
}
};
}
public static boolean contains(int[] values, final int value) {
return Arrays.stream(values).anyMatch(v -> v == value);
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.watcher.support;
import java.util.Objects;
public class Strings {
private Strings() {
}
public static String join(String delimiter, int... values) {
Objects.requireNonNull(delimiter);
Objects.requireNonNull(values);
if (values.length == 0) {
return "";
}
StringBuilder sb = new StringBuilder(4 * values.length);
sb.append(values[0]);
for (int i = 1; i < values.length; i++) {
sb.append(delimiter).append(values[i]);
}
return sb.toString();
}
}

View File

@ -5,10 +5,10 @@
*/ */
package org.elasticsearch.watcher.trigger.schedule; package org.elasticsearch.watcher.trigger.schedule;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.trigger.schedule.support.DayTimes; import org.elasticsearch.watcher.trigger.schedule.support.DayTimes;
@ -128,7 +128,7 @@ public class HourlySchedule extends CronnableSchedule {
} }
} }
return minutes.isEmpty() ? new HourlySchedule() : new HourlySchedule(Ints.toArray(minutes)); return minutes.isEmpty() ? new HourlySchedule() : new HourlySchedule(CollectionUtils.toArray(minutes));
} }
} }
@ -148,7 +148,7 @@ public class HourlySchedule extends CronnableSchedule {
} }
public HourlySchedule build() { public HourlySchedule build() {
return minutes.isEmpty() ? new HourlySchedule() : new HourlySchedule(Ints.toArray(minutes)); return minutes.isEmpty() ? new HourlySchedule() : new HourlySchedule(CollectionUtils.toArray(minutes));
} }
} }
} }

View File

@ -5,9 +5,9 @@
*/ */
package org.elasticsearch.watcher.trigger.schedule.support; package org.elasticsearch.watcher.trigger.schedule.support;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -17,6 +17,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.elasticsearch.watcher.support.Exceptions.illegalArgument; import static org.elasticsearch.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.watcher.support.Strings.join;
/** /**
* *
@ -124,8 +125,8 @@ public class DayTimes implements Times {
} }
public String cron() { public String cron() {
String hrs = Ints.join(",", hour); String hrs = join(",", hour);
String mins = Ints.join(",", minute); String mins = join(",", minute);
return "0 " + mins + " " + hrs + " * * ?"; return "0 " + mins + " " + hrs + " * * ?";
} }
@ -225,7 +226,7 @@ public class DayTimes implements Times {
if (minutes.isEmpty()) { if (minutes.isEmpty()) {
minutes.add(0); minutes.add(0);
} }
return new DayTimes(Ints.toArray(hours), Ints.toArray(minutes)); return new DayTimes(CollectionUtils.toArray(hours), CollectionUtils.toArray(minutes));
} }
public static int parseHourValue(XContentParser parser, XContentParser.Token token) throws IOException, ElasticsearchParseException { public static int parseHourValue(XContentParser parser, XContentParser.Token token) throws IOException, ElasticsearchParseException {

View File

@ -6,10 +6,10 @@
package org.elasticsearch.watcher.trigger.schedule.support; package org.elasticsearch.watcher.trigger.schedule.support;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -20,6 +20,7 @@ import java.util.Locale;
import java.util.Set; import java.util.Set;
import static org.elasticsearch.watcher.support.Exceptions.illegalArgument; import static org.elasticsearch.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.watcher.support.Strings.join;
/** /**
* *
@ -68,9 +69,9 @@ public class MonthTimes implements Times {
public Set<String> crons() { public Set<String> crons() {
Set<String> crons = new HashSet<>(); Set<String> crons = new HashSet<>();
for (DayTimes times : this.times) { for (DayTimes times : this.times) {
String hrsStr = Ints.join(",", times.hour); String hrsStr = join(",", times.hour);
String minsStr = Ints.join(",", times.minute); String minsStr = join(",", times.minute);
String daysStr = Ints.join(",", this.days); String daysStr = join(",", this.days);
daysStr = daysStr.replace("32", "L"); daysStr = daysStr.replace("32", "L");
crons.add("0 " + minsStr + " " + hrsStr + " " + daysStr + " * ?"); crons.add("0 " + minsStr + " " + hrsStr + " " + daysStr + " * ?");
} }
@ -103,7 +104,7 @@ public class MonthTimes implements Times {
return String.format( return String.format(
Locale.ROOT, Locale.ROOT,
"days [%s], times [%s]", "days [%s], times [%s]",
Ints.join(",", days), join(",", days),
Strings.arrayToCommaDelimitedString(times) Strings.arrayToCommaDelimitedString(times)
); );
} }
@ -185,7 +186,7 @@ public class MonthTimes implements Times {
} }
} }
} }
int[] days = daysSet.isEmpty() ? DEFAULT_DAYS : Ints.toArray(daysSet); int[] days = daysSet.isEmpty() ? DEFAULT_DAYS : CollectionUtils.toArray(daysSet);
DayTimes[] times = timesSet.isEmpty() ? new DayTimes[] { new DayTimes(0, 0) } : timesSet.toArray(new DayTimes[timesSet.size()]); DayTimes[] times = timesSet.isEmpty() ? new DayTimes[] { new DayTimes(0, 0) } : timesSet.toArray(new DayTimes[timesSet.size()]);
return new MonthTimes(days, times); return new MonthTimes(days, times);
} }
@ -220,7 +221,7 @@ public class MonthTimes implements Times {
} }
public Builder on(int... days) { public Builder on(int... days) {
this.days.addAll(Ints.asList(days)); Arrays.stream(days).forEach(this.days::add);
return this; return this;
} }
@ -245,7 +246,7 @@ public class MonthTimes implements Times {
} }
public MonthTimes build() { public MonthTimes build() {
return new MonthTimes(Ints.toArray(days), times.toArray(new DayTimes[times.size()])); return new MonthTimes(CollectionUtils.toArray(days), times.toArray(new DayTimes[times.size()]));
} }
} }
} }

View File

@ -6,7 +6,6 @@
package org.elasticsearch.watcher.trigger.schedule.support; package org.elasticsearch.watcher.trigger.schedule.support;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -15,6 +14,8 @@ import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import static org.elasticsearch.watcher.support.Strings.join;
/** /**
* *
*/ */
@ -54,8 +55,8 @@ public class WeekTimes implements Times {
public Set<String> crons() { public Set<String> crons() {
Set<String> crons = new HashSet<>(); Set<String> crons = new HashSet<>();
for (DayTimes times : this.times) { for (DayTimes times : this.times) {
String hrsStr = Ints.join(",", times.hour); String hrsStr = join(",", times.hour);
String minsStr = Ints.join(",", times.minute); String minsStr = join(",", times.minute);
String daysStr = DayOfWeek.cronPart(this.days); String daysStr = DayOfWeek.cronPart(this.days);
crons.add("0 " + minsStr + " " + hrsStr + " ? * " + daysStr); crons.add("0 " + minsStr + " " + hrsStr + " ? * " + daysStr);
} }

View File

@ -6,10 +6,10 @@
package org.elasticsearch.watcher.trigger.schedule.support; package org.elasticsearch.watcher.trigger.schedule.support;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.*; import java.util.*;
import static org.elasticsearch.watcher.support.Exceptions.illegalArgument; import static org.elasticsearch.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.watcher.support.Strings.join;
/** /**
* *
@ -69,9 +70,9 @@ public class YearTimes implements Times {
public Set<String> crons() { public Set<String> crons() {
Set<String> crons = new HashSet<>(); Set<String> crons = new HashSet<>();
for (DayTimes times : this.times) { for (DayTimes times : this.times) {
String hrsStr = Ints.join(",", times.hour); String hrsStr = join(",", times.hour);
String minsStr = Ints.join(",", times.minute); String minsStr = join(",", times.minute);
String daysStr = Ints.join(",", this.days); String daysStr = join(",", this.days);
daysStr = daysStr.replace("32", "L"); daysStr = daysStr.replace("32", "L");
String monthsStr = Strings.collectionToCommaDelimitedString(months); String monthsStr = Strings.collectionToCommaDelimitedString(months);
String expression = "0 " + minsStr + " " + hrsStr + " " + daysStr + " " + monthsStr + " ?"; String expression = "0 " + minsStr + " " + hrsStr + " " + daysStr + " " + monthsStr + " ?";
@ -109,7 +110,7 @@ public class YearTimes implements Times {
Locale.ROOT, Locale.ROOT,
"months [%s], days [%s], times [%s]", "months [%s], days [%s], times [%s]",
Strings.collectionToCommaDelimitedString(months), Strings.collectionToCommaDelimitedString(months),
Ints.join(",", days), join(",", days),
Strings.arrayToCommaDelimitedString(times) Strings.arrayToCommaDelimitedString(times)
); );
} }
@ -181,7 +182,7 @@ public class YearTimes implements Times {
} }
} }
EnumSet<Month> months = monthsSet.isEmpty() ? DEFAULT_MONTHS : EnumSet.copyOf(monthsSet); EnumSet<Month> months = monthsSet.isEmpty() ? DEFAULT_MONTHS : EnumSet.copyOf(monthsSet);
int[] days = daysSet.isEmpty() ? DEFAULT_DAYS : Ints.toArray(daysSet); int[] days = daysSet.isEmpty() ? DEFAULT_DAYS : CollectionUtils.toArray(daysSet);
DayTimes[] times = timesSet.isEmpty() ? new DayTimes[] { new DayTimes(0, 0) } : timesSet.toArray(new DayTimes[timesSet.size()]); DayTimes[] times = timesSet.isEmpty() ? new DayTimes[] { new DayTimes(0, 0) } : timesSet.toArray(new DayTimes[timesSet.size()]);
return new YearTimes(months, days, times); return new YearTimes(months, days, times);
} }
@ -211,7 +212,7 @@ public class YearTimes implements Times {
} }
public Builder on(int... days) { public Builder on(int... days) {
this.days.addAll(Ints.asList(days)); Arrays.stream(days).forEach(this.days::add);
return this; return this;
} }
@ -236,7 +237,7 @@ public class YearTimes implements Times {
} }
public YearTimes build() { public YearTimes build() {
return new YearTimes(EnumSet.copyOf(months), Ints.toArray(days), times.toArray(new DayTimes[times.size()])); return new YearTimes(EnumSet.copyOf(months), CollectionUtils.toArray(days), times.toArray(new DayTimes[times.size()]));
} }
} }
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.watcher.trigger.schedule; package org.elasticsearch.watcher.trigger.schedule;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -15,6 +14,7 @@ import org.elasticsearch.watcher.trigger.schedule.support.DayTimes;
import org.junit.Test; import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.watcher.support.Strings.join;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
/** /**
@ -36,7 +36,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
DailySchedule schedule = new DailySchedule(time); DailySchedule schedule = new DailySchedule(time);
String[] crons = expressions(schedule); String[] crons = expressions(schedule);
assertThat(crons, arrayWithSize(1)); assertThat(crons, arrayWithSize(1));
assertThat(crons, arrayContaining("0 " + Ints.join(",", time.minute()) + " " + Ints.join(",", time.hour()) + " * * ?")); assertThat(crons, arrayContaining("0 " + join(",", time.minute()) + " " + join(",", time.hour()) + " * * ?"));
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
@ -53,7 +53,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
String[] crons = expressions(schedule); String[] crons = expressions(schedule);
assertThat(crons, arrayWithSize(times.length)); assertThat(crons, arrayWithSize(times.length));
for (DayTimes time : times) { for (DayTimes time : times) {
assertThat(crons, hasItemInArray("0 " + Ints.join(",", time.minute()) + " " + Ints.join(",", time.hour()) + " * * ?")); assertThat(crons, hasItemInArray("0 " + join(",", time.minute()) + " " + join(",", time.hour()) + " * * ?"));
} }
} }

View File

@ -5,17 +5,20 @@
*/ */
package org.elasticsearch.watcher.trigger.schedule; package org.elasticsearch.watcher.trigger.schedule;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.watcher.support.Strings;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.watcher.support.Integers.asIterable;
import static org.elasticsearch.watcher.support.Integers.contains;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
/** /**
@ -48,7 +51,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
@Test @Test
public void test_MultipleMinutes() throws Exception { public void test_MultipleMinutes() throws Exception {
int[] minutes = validMinutes(); int[] minutes = validMinutes();
String minutesStr = Ints.join(",", minutes); String minutesStr = Strings.join(",", minutes);
HourlySchedule schedule = new HourlySchedule(minutes); HourlySchedule schedule = new HourlySchedule(minutes);
String[] crons = expressions(schedule); String[] crons = expressions(schedule);
assertThat(crons, arrayWithSize(1)); assertThat(crons, arrayWithSize(1));
@ -134,7 +137,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
int[] minutes = validMinutes(); int[] minutes = validMinutes();
XContentBuilder builder = jsonBuilder() XContentBuilder builder = jsonBuilder()
.startObject() .startObject()
.field("minute", Ints.asList(minutes)) .field("minute", asIterable(minutes))
.endObject(); .endObject();
BytesReference bytes = builder.bytes(); BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes); XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
@ -143,7 +146,8 @@ public class HourlyScheduleTests extends ScheduleTestCase {
assertThat(schedule, notNullValue()); assertThat(schedule, notNullValue());
assertThat(schedule.minutes().length, is(minutes.length)); assertThat(schedule.minutes().length, is(minutes.length));
for (int i = 0; i < minutes.length; i++) { for (int i = 0; i < minutes.length; i++) {
assertThat(Ints.contains(schedule.minutes(), minutes[i]), is(true)); final int minute = minutes[i];
assertThat(contains(schedule.minutes(), minutes[i]), is(true));
} }
} }
@ -152,7 +156,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
int[] minutes = invalidMinutes(); int[] minutes = invalidMinutes();
XContentBuilder builder = jsonBuilder() XContentBuilder builder = jsonBuilder()
.startObject() .startObject()
.field("minute", Ints.asList(minutes)) .field("minute", asIterable(minutes))
.endObject(); .endObject();
BytesReference bytes = builder.bytes(); BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes); XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
@ -165,7 +169,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
int[] minutes = validMinutes(); int[] minutes = validMinutes();
XContentBuilder builder = jsonBuilder() XContentBuilder builder = jsonBuilder()
.startObject() .startObject()
.field("minute", Ints.asList(minutes).stream().map(p -> p.toString()).collect(Collectors.toList())) .field("minute", Arrays.stream(minutes).mapToObj(p -> Integer.toString(p)).collect(Collectors.toList()))
.endObject(); .endObject();
BytesReference bytes = builder.bytes(); BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes); XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
@ -174,7 +178,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
assertThat(schedule, notNullValue()); assertThat(schedule, notNullValue());
assertThat(schedule.minutes().length, is(minutes.length)); assertThat(schedule.minutes().length, is(minutes.length));
for (int i = 0; i < minutes.length; i++) { for (int i = 0; i < minutes.length; i++) {
assertThat(Ints.contains(schedule.minutes(), minutes[i]), is(true)); assertThat(contains(schedule.minutes(), minutes[i]), is(true));
} }
} }
@ -183,7 +187,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
int[] minutes = invalidMinutes(); int[] minutes = invalidMinutes();
XContentBuilder builder = jsonBuilder() XContentBuilder builder = jsonBuilder()
.startObject() .startObject()
.field("minute", Ints.asList(minutes).stream().map(p -> p.toString()).collect(Collectors.toList())) .field("minute", Arrays.stream(minutes).mapToObj(p -> Integer.toString(p)).collect(Collectors.toList()))
.endObject(); .endObject();
BytesReference bytes = builder.bytes(); BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes); XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.watcher.trigger.schedule; package org.elasticsearch.watcher.trigger.schedule;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -16,6 +15,7 @@ import org.elasticsearch.watcher.trigger.schedule.support.MonthTimes;
import org.junit.Test; import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.watcher.support.Strings.join;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
/** /**
@ -38,9 +38,9 @@ public class MonthlyScheduleTests extends ScheduleTestCase {
String[] crons = expressions(schedule); String[] crons = expressions(schedule);
assertThat(crons, arrayWithSize(time.times().length)); assertThat(crons, arrayWithSize(time.times().length));
for (DayTimes dayTimes : time.times()) { for (DayTimes dayTimes : time.times()) {
String minStr = Ints.join(",", dayTimes.minute()); String minStr = join(",", dayTimes.minute());
String hrStr = Ints.join(",", dayTimes.hour()); String hrStr = join(",", dayTimes.hour());
String dayStr = Ints.join(",", time.days()); String dayStr = join(",", time.days());
dayStr = dayStr.replace("32", "L"); dayStr = dayStr.replace("32", "L");
assertThat(crons, hasItemInArray("0 " + minStr + " " + hrStr + " " + dayStr + " * ?")); assertThat(crons, hasItemInArray("0 " + minStr + " " + hrStr + " " + dayStr + " * ?"));
} }
@ -58,9 +58,9 @@ public class MonthlyScheduleTests extends ScheduleTestCase {
assertThat(crons, arrayWithSize(count)); assertThat(crons, arrayWithSize(count));
for (MonthTimes monthTimes : times) { for (MonthTimes monthTimes : times) {
for (DayTimes dayTimes : monthTimes.times()) { for (DayTimes dayTimes : monthTimes.times()) {
String minStr = Ints.join(",", dayTimes.minute()); String minStr = join(",", dayTimes.minute());
String hrStr = Ints.join(",", dayTimes.hour()); String hrStr = join(",", dayTimes.hour());
String dayStr = Ints.join(",", monthTimes.days()); String dayStr = join(",", monthTimes.days());
dayStr = dayStr.replace("32", "L"); dayStr = dayStr.replace("32", "L");
assertThat(crons, hasItemInArray("0 " + minStr + " " + hrStr + " " + dayStr + " * ?")); assertThat(crons, hasItemInArray("0 " + minStr + " " + hrStr + " " + dayStr + " * ?"));
} }

View File

@ -5,7 +5,7 @@
*/ */
package org.elasticsearch.watcher.trigger.schedule; package org.elasticsearch.watcher.trigger.schedule;
import com.google.common.primitives.Ints; import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
@ -174,7 +174,7 @@ public abstract class ScheduleTestCase extends ESTestCase {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
days.add(randomIntBetween(1, 31)); days.add(randomIntBetween(1, 31));
} }
return Ints.toArray(days); return CollectionUtils.toArray(days);
} }
protected static Object randomDayOfMonth() { protected static Object randomDayOfMonth() {

View File

@ -6,7 +6,6 @@
package org.elasticsearch.watcher.trigger.schedule; package org.elasticsearch.watcher.trigger.schedule;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
@ -19,6 +18,7 @@ import org.elasticsearch.watcher.trigger.schedule.support.WeekTimes;
import org.junit.Test; import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.watcher.support.Strings.join;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
/** /**
@ -41,7 +41,7 @@ public class WeeklyScheduleTests extends ScheduleTestCase {
String[] crons = expressions(schedule); String[] crons = expressions(schedule);
assertThat(crons, arrayWithSize(time.times().length)); assertThat(crons, arrayWithSize(time.times().length));
for (DayTimes dayTimes : time.times()) { for (DayTimes dayTimes : time.times()) {
assertThat(crons, hasItemInArray("0 " + Ints.join(",", dayTimes.minute()) + " " + Ints.join(",", dayTimes.hour()) + " ? * " + Strings.collectionToCommaDelimitedString(time.days()))); assertThat(crons, hasItemInArray("0 " + join(",", dayTimes.minute()) + " " + join(",", dayTimes.hour()) + " ? * " + Strings.collectionToCommaDelimitedString(time.days())));
} }
} }
@ -57,7 +57,7 @@ public class WeeklyScheduleTests extends ScheduleTestCase {
assertThat(crons, arrayWithSize(count)); assertThat(crons, arrayWithSize(count));
for (WeekTimes weekTimes : times) { for (WeekTimes weekTimes : times) {
for (DayTimes dayTimes : weekTimes.times()) { for (DayTimes dayTimes : weekTimes.times()) {
assertThat(crons, hasItemInArray("0 " + Ints.join(",", dayTimes.minute()) + " " + Ints.join(",", dayTimes.hour()) + " ? * " + Strings.collectionToCommaDelimitedString(weekTimes.days()))); assertThat(crons, hasItemInArray("0 " + join(",", dayTimes.minute()) + " " + join(",", dayTimes.hour()) + " ? * " + Strings.collectionToCommaDelimitedString(weekTimes.days())));
} }
} }
} }

View File

@ -6,7 +6,6 @@
package org.elasticsearch.watcher.trigger.schedule; package org.elasticsearch.watcher.trigger.schedule;
import com.google.common.primitives.Ints;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
@ -18,6 +17,7 @@ import org.elasticsearch.watcher.trigger.schedule.support.YearTimes;
import org.junit.Test; import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.watcher.support.Strings.join;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
/** /**
@ -40,9 +40,9 @@ public class YearlyScheduleTests extends ScheduleTestCase {
String[] crons = expressions(schedule); String[] crons = expressions(schedule);
assertThat(crons, arrayWithSize(time.times().length)); assertThat(crons, arrayWithSize(time.times().length));
for (DayTimes dayTimes : time.times()) { for (DayTimes dayTimes : time.times()) {
String minStr = Ints.join(",", dayTimes.minute()); String minStr = join(",", dayTimes.minute());
String hrStr = Ints.join(",", dayTimes.hour()); String hrStr = join(",", dayTimes.hour());
String dayStr = Ints.join(",", time.days()); String dayStr = join(",", time.days());
dayStr = dayStr.replace("32", "L"); dayStr = dayStr.replace("32", "L");
String monthStr = Strings.collectionToCommaDelimitedString(time.months()); String monthStr = Strings.collectionToCommaDelimitedString(time.months());
String expression = "0 " + minStr + " " + hrStr + " " + dayStr + " " + monthStr + " ?"; String expression = "0 " + minStr + " " + hrStr + " " + dayStr + " " + monthStr + " ?";
@ -63,9 +63,9 @@ public class YearlyScheduleTests extends ScheduleTestCase {
assertThat(crons, arrayWithSize(count)); assertThat(crons, arrayWithSize(count));
for (YearTimes yearTimes : times) { for (YearTimes yearTimes : times) {
for (DayTimes dayTimes : yearTimes.times()) { for (DayTimes dayTimes : yearTimes.times()) {
String minStr = Ints.join(",", dayTimes.minute()); String minStr = join(",", dayTimes.minute());
String hrStr = Ints.join(",", dayTimes.hour()); String hrStr = join(",", dayTimes.hour());
String dayStr = Ints.join(",", yearTimes.days()); String dayStr = join(",", yearTimes.days());
dayStr = dayStr.replace("32", "L"); dayStr = dayStr.replace("32", "L");
String monthStr = Strings.collectionToCommaDelimitedString(yearTimes.months()); String monthStr = Strings.collectionToCommaDelimitedString(yearTimes.months());
assertThat(crons, hasItemInArray("0 " + minStr + " " + hrStr + " " + dayStr + " " + monthStr + " ?")); assertThat(crons, hasItemInArray("0 " + minStr + " " + hrStr + " " + dayStr + " " + monthStr + " ?"));