Skip to content

Commit

Permalink
Fix generics
Browse files Browse the repository at this point in the history
Signed-off-by: Alexei Barantsev <barancev@gmail.com>
  • Loading branch information
asashour authored and barancev committed Apr 12, 2017
1 parent 1fee32b commit 138e3ab
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private FirefoxDriver(
}

private static CommandExecutor toExecutor(FirefoxOptions options) {
DriverService.Builder builder;
DriverService.Builder<?, ?> builder;

if (options.isLegacy()) {
builder = XpiDriverService.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static FirefoxOptions fromJsonMap(Map<String, Object> map) throws IOException {

if (map.containsKey("args")) {
@SuppressWarnings("unchecked") // #YOLO
List<String> list = (List) getOption(map, "args", List.class);
List<String> list = (List<String>) getOption(map, "args", List.class);
options.addArguments(list);
}

Expand All @@ -114,7 +114,7 @@ static FirefoxOptions fromJsonMap(Map<String, Object> map) throws IOException {

if (map.containsKey("prefs")) {
@SuppressWarnings("unchecked") // #YOLO
Map<String, Object> prefs = (Map) getOption(map, "prefs", Map.class);
Map<String, Object> prefs = (Map<String, Object>) getOption(map, "prefs", Map.class);
prefs.forEach((key, value) -> {
if (value instanceof Boolean) {
options.addPreference(key, (Boolean) value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected RemoteWebDriver extractRemoteWebDriver(WebDriver driver) {
} else if (Proxy.isProxyClass(driver.getClass())) {
InvocationHandler handler = Proxy.getInvocationHandler(driver);
if (handler instanceof JdkHandler) {
return ((JdkHandler) handler).driver;
return ((JdkHandler<?>) handler).driver;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ private Object convertJsonPrimitive(JsonPrimitive json) {
}
}

private Enum convertEnum(Class clazz, Object text) {
private Enum<?> convertEnum(Class<?> clazz, Object text) {
String toConvert = text instanceof JsonElement ?
((JsonElement) text).getAsString() : String.valueOf(text);

Function<Class, Enum<?>> asEnum = (c) -> {
Function<Class<?>, Enum<?>> asEnum = (c) -> {
for (Object value : c.getEnumConstants()) {
if (value.toString().equalsIgnoreCase(toConvert)) {
return (Enum<?>) value;
Expand All @@ -273,8 +273,8 @@ private Enum convertEnum(Class clazz, Object text) {
return asEnum.apply(clazz);
}

Class[] allClasses = clazz.getClasses();
for (Class current : allClasses) {
Class<?>[] allClasses = clazz.getClasses();
for (Class<?> current : allClasses) {
if (current.isEnum()) {
return asEnum.apply(current);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public abstract class AbstractHttpCommandCodec implements CommandCodec<HttpReque
private static final Splitter PATH_SPLITTER = Splitter.on('/').omitEmptyStrings();
private static final String SESSION_ID_PARAM = "sessionId";

private final ConcurrentHashMap<String, CommandSpec> nameToSpec = new ConcurrentHashMap();
private final ConcurrentHashMap<String, CommandSpec> nameToSpec = new ConcurrentHashMap<>();
private final Map<String, String> aliases = new HashMap<>();
private final BeanToJsonConverter beanToJsonConverter = new BeanToJsonConverter();
private final JsonToBeanConverter jsonToBeanConverter = new JsonToBeanConverter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ protected OutputStream getOutputStream() {
return outputStream;
}

public static abstract class Builder<DS extends DriverService, B extends Builder> {
public static abstract class Builder<DS extends DriverService, B extends Builder<?, ?>> {

private int port = 0;
private File exe = null;
Expand All @@ -250,6 +250,7 @@ public static abstract class Builder<DS extends DriverService, B extends Builder
* @param file The executable to use.
* @return A self reference.
*/
@SuppressWarnings("unchecked")
public B usingDriverExecutable(File file) {
checkNotNull(file);
checkExecutable(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static SafariOptions fromCapabilities(Capabilities capabilities)
return (SafariOptions) cap;
} else if (cap instanceof Map) {
try {
return SafariOptions.fromJsonMap((Map) cap);
return SafariOptions.fromJsonMap((Map<?, ?>) cap);
} catch (IOException e) {
throw new WebDriverException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ public Object apply(WebDriver driver) {
Object value = ((JavascriptExecutor) driver).executeScript(javaScript);

if (value instanceof List) {
return ((List) value).isEmpty() ? null : value;
return ((List<?>) value).isEmpty() ? null : value;
}
if (value instanceof String) {
return ((String) value).isEmpty() ? null : value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public void testShouldStillIncludeScreenshotEvenIfServerSideExceptionsAreDisable

@Test
public void testStatusCodesRaisedBackToStatusMatches() {
Map<Integer, Class> exceptions = new HashMap<>();
Map<Integer, Class<?>> exceptions = new HashMap<>();
exceptions.put(ErrorCodes.NO_SUCH_SESSION, NoSuchSessionException.class);
exceptions.put(ErrorCodes.NO_SUCH_ELEMENT, NoSuchElementException.class);
exceptions.put(ErrorCodes.NO_SUCH_FRAME, NoSuchFrameException.class);
Expand Down Expand Up @@ -470,7 +470,7 @@ public void testStatusCodesRaisedBackToStatusMatches() {
exceptions.put(ErrorCodes.INVALID_XPATH_SELECTOR_RETURN_TYPER, InvalidSelectorException.class);

Set<String> collectedFailures = new HashSet<>();
for (Map.Entry<Integer, Class> exception : exceptions.entrySet()) {
for (Map.Entry<Integer, Class<?>> exception : exceptions.entrySet()) {
try {
handler.throwIfResponseFailed(createResponse(exception.getKey()), 123);
fail("Should have thrown an Exception");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ public void shouldNotIncludeNonProtocolExtensionKeys() throws IOException {

Map<?, ?> capabilities = (Map<?, ?>) rawCaps;

Map<?, ?> always = (Map<?, ?>) capabilities.get("alwaysMatch");
Map<String, ?> always = (Map<String, ?>) capabilities.get("alwaysMatch");
List<Map<?, ?>> first = (List<Map<?, ?>>) capabilities.get("firstMatch");

// We don't care where they are, but we want to see "se:option" and not "option"
Set<String> keys = new HashSet(always.keySet());
Set<String> keys = new HashSet<>(always.keySet());
keys.addAll(first.stream()
.map(Map::keySet)
.flatMap(Collection::stream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void extractsAllParametersFromUrl() throws URISyntaxException {
codec.defineCommand("pick", GET, "/fruit/:fruit/size/:size");

Command decoded = codec.decode(request);
assertThat(decoded.getParameters(), is((Map) ImmutableMap.of(
assertThat(decoded.getParameters(), is((Map<String, String>) ImmutableMap.of(
"fruit", "apple",
"size", "large")));
}
Expand All @@ -228,7 +228,7 @@ public void extractsAllParameters() throws URISyntaxException {

Command decoded = codec.decode(request);
assertThat(decoded.getSessionId(), is(new SessionId("sessionX")));
assertThat(decoded.getParameters(), is((Map) ImmutableMap.of(
assertThat(decoded.getParameters(), is((Map<String, String>) ImmutableMap.of(
"fruit", "apple", "size", "large", "color", "red")));
}

Expand All @@ -247,7 +247,7 @@ public void ignoresNullSessionIdInSessionBody() throws URISyntaxException {

Command decoded = codec.decode(request);
assertThat(decoded.getSessionId(), is(nullValue()));
assertThat(decoded.getParameters(), is((Map) ImmutableMap.of(
assertThat(decoded.getParameters(), is((Map<String, String>) ImmutableMap.of(
"fruit", "apple", "size", "large", "color", "red")));
}

Expand Down Expand Up @@ -290,7 +290,7 @@ public void codecRoundTrip() {

assertThat(decoded.getName(), is(original.getName()));
assertThat(decoded.getSessionId(), is(original.getSessionId()));
assertThat(decoded.getParameters(), is((Map) original.getParameters()));
assertThat(decoded.getParameters(), is((Map<?, ?>) original.getParameters()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ protected boolean isMergeAble(Object other, Object target) {
}

if (target instanceof Collection) {
return !((Collection) other).isEmpty();
return !((Collection<?>) other).isEmpty();
}

if (target instanceof Map) {
return !((Map) other).isEmpty();
return !((Map<?, ?>) other).isEmpty();
}

return true;
Expand All @@ -303,16 +303,16 @@ public String toString() {

public StringBuilder toString(String format, String name, Object value) {
StringBuilder sb = new StringBuilder();
List iterator;
List<?> iterator;
if (value instanceof List) {
iterator = (List)value;
iterator = (List<?>)value;
} else {
iterator = Arrays.asList(value);
}
for (Object v : iterator) {
if (v != null &&
!(v instanceof Map && ((Map) v).isEmpty()) &&
!(v instanceof Collection && ((Collection) v).isEmpty())) {
!(v instanceof Map && ((Map<?, ?>) v).isEmpty()) &&
!(v instanceof Collection && ((Collection<?>) v).isEmpty())) {
sb.append(String.format(format, name, v));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private HandlerFactory getHandlerFactory(Class<? extends RestishHandler<?>> hand
}

private static Constructor<? extends RestishHandler<?>> getConstructor(
Class<? extends RestishHandler<?>> handlerClazz, Class... types) {
Class<? extends RestishHandler<?>> handlerClazz, Class<?>... types) {
try {
return handlerClazz.getConstructor(types);
} catch (NoSuchMethodException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public String getNumTestPasses() {
return numTestPasses;
}

public Collection getTestTables() {
public Collection<String> getTestTables() {
return testTables;
}

Expand Down Expand Up @@ -239,11 +239,11 @@ public String decode(String string) {
}
}

public List decodeListOfStrings(List list) {
public List<String> decodeListOfStrings(List<String> list) {
List<String> decodedList = new LinkedList<>();

for (Object o : list) {
decodedList.add(decode((String) o));
for (String o : list) {
decodedList.add(decode(o));
}

return decodedList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void testMergeWithRealValues() {
GridNodeConfiguration other = new GridNodeConfiguration();
other.id = "myid";
DesiredCapabilities dc =
new DesiredCapabilities(new ImmutableMap.Builder().put("chrome", "foo").build());
new DesiredCapabilities(new ImmutableMap.Builder<String, String>().put("chrome", "foo").build());
other.capabilities = Arrays.asList(dc);
other.downPollingLimit = 50;
other.hub = "http://dummyhost";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public Object getAttribute(String s) {
return attributes.get(s);
}

public Enumeration getAttributeNames() {
public Enumeration<String> getAttributeNames() {
return Collections.enumeration(attributes.keySet());
}

Expand Down Expand Up @@ -258,6 +258,7 @@ public String[] getParameterValues(String s) {
return values.toArray(new String[values.size()]);
}

@SuppressWarnings({"unchecked", "rawtypes"})
public Map getParameterMap() {
return Collections.unmodifiableMap(parameters);
}
Expand Down Expand Up @@ -308,7 +309,7 @@ public Locale getLocale() {
throw new UnsupportedOperationException();
}

public Enumeration getLocales() {
public Enumeration<Locale> getLocales() {
throw new UnsupportedOperationException();
}

Expand Down

0 comments on commit 138e3ab

Please sign in to comment.