import com.vaadin.server.ErrorEvent;
import com.vaadin.server.ErrorHandler;
+import java.util.stream.Stream;
/**
* <code>EventRouter</code> class implementing the inheritable event listening
// Find the correct method
final Method[] methods = target.getClass().getMethods();
- Method method = null;
- for (int i = 0; i < methods.length; i++) {
- if (methods[i].getName().equals(methodName)) {
- method = methods[i];
- }
- }
- if (method == null) {
- throw new IllegalArgumentException();
- }
+
+ final Method method = Stream.of(methods)
+ .filter(m -> methodName.equals(m.getName()))
+ .findAny().orElseThrow(IllegalArgumentException::new);
// Remove the listeners
if (listenerList != null) {
// Send the event to all listeners. The listeners themselves
// will filter out unwanted events.
final Object[] listeners = listenerList.toArray();
- for (int i = 0; i < listeners.length; i++) {
- ListenerMethod listenerMethod = (ListenerMethod) listeners[i];
+ for (Object listener : listeners) {
+ ListenerMethod listenerMethod = (ListenerMethod) listener;
if (null != errorHandler) {
try {
listenerMethod.receiveEvent(event);
import java.util.EventObject;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.util.stream.Stream;
/**
* <p>
private static Method findHighestMethod(Class<?> cls, String method,
Class<?>[] paramTypes) {
Class<?>[] ifaces = cls.getInterfaces();
- for (int i = 0; i < ifaces.length; i++) {
- Method ifaceMethod = findHighestMethod(ifaces[i], method,
- paramTypes);
+ for (Class<?> iface : ifaces) {
+ Method ifaceMethod = findHighestMethod(iface, method, paramTypes);
if (ifaceMethod != null) {
return ifaceMethod;
}
return parentMethod;
}
}
- Method[] methods = cls.getMethods();
- for (int i = 0; i < methods.length; i++) {
- // we ignore parameter types for now - you need to add this
- if (methods[i].getName().equals(method)) {
- return methods[i];
- }
- }
- return null;
+
+ // we ignore parameter types for now - you need to add this
+ return Stream.of(cls.getMethods())
+ .filter(m -> method.equals(m.getName()))
+ .findAny().orElse(null);
+
}
/**
// Finds the correct method
final Method[] methods = target.getClass().getMethods();
Method method = null;
- for (int i = 0; i < methods.length; i++) {
- if (methods[i].getName().equals(methodName)) {
- method = methods[i];
+ for (Method method1 : methods) {
+ if (method1.getName().equals(methodName)) {
+ method = method1;
}
}
if (method == null) {
// Find the correct method
final Method[] methods = target.getClass().getMethods();
Method method = null;
- for (int i = 0; i < methods.length; i++) {
- if (methods[i].getName().equals(methodName)) {
- method = methods[i];
+ for (Method method1 : methods) {
+ if (method1.getName().equals(methodName)) {
+ method = method1;
}
}
if (method == null) {
// Finds the correct method
final Method[] methods = target.getClass().getMethods();
Method method = null;
- for (int i = 0; i < methods.length; i++) {
- if (methods[i].getName().equals(methodName)) {
- method = methods[i];
+ for (Method method1 : methods) {
+ if (method1.getName().equals(methodName)) {
+ method = method1;
}
}
if (method == null) {
}
} else if (isForm(component)) {
HasComponents form = (HasComponents) component;
- for (Iterator<Component> iterator = form.iterator(); iterator
- .hasNext();) {
- Component child = iterator.next();
+ for (Component child : form) {
errors = validateComponentRelativeSizes(child, errors, parent);
}
}
connectorTracker);
}
- // Collections
- if (JsonConstants.VTYPE_LIST.equals(transportType)) {
- return decodeList(targetType, restrictToInternalTypes,
+ if (null != transportType) // Collections
+ switch (transportType) {
+ case JsonConstants.VTYPE_LIST:
+ return decodeList(targetType, restrictToInternalTypes,
(JsonArray) encodedJsonValue, connectorTracker);
- } else if (JsonConstants.VTYPE_SET.equals(transportType)) {
- return decodeSet(targetType, restrictToInternalTypes,
+ case JsonConstants.VTYPE_SET:
+ return decodeSet(targetType, restrictToInternalTypes,
(JsonArray) encodedJsonValue, connectorTracker);
- } else if (JsonConstants.VTYPE_MAP.equals(transportType)) {
- return decodeMap(targetType, restrictToInternalTypes,
+ case JsonConstants.VTYPE_MAP:
+ return decodeMap(targetType, restrictToInternalTypes,
encodedJsonValue, connectorTracker);
+ default:
+ break;
}
// Arrays
return connectorTracker.getConnector(encodedJsonValue.asString());
}
- // Legacy types
-
- if (JsonConstants.VTYPE_STRING.equals(transportType)) {
- return encodedJsonValue.asString();
- } else if (JsonConstants.VTYPE_INTEGER.equals(transportType)) {
- return (int) encodedJsonValue.asNumber();
- } else if (JsonConstants.VTYPE_LONG.equals(transportType)) {
- return (long) encodedJsonValue.asNumber();
- } else if (JsonConstants.VTYPE_FLOAT.equals(transportType)) {
- return (float) encodedJsonValue.asNumber();
- } else if (JsonConstants.VTYPE_DOUBLE.equals(transportType)) {
- return encodedJsonValue.asNumber();
- } else if (JsonConstants.VTYPE_BOOLEAN.equals(transportType)) {
- return encodedJsonValue.asBoolean();
+
+ if (null != transportType) // Legacy types
+ switch (transportType) {
+ case JsonConstants.VTYPE_STRING:
+ return encodedJsonValue.asString();
+ case JsonConstants.VTYPE_INTEGER:
+ return (int) encodedJsonValue.asNumber();
+ case JsonConstants.VTYPE_LONG:
+ return (long) encodedJsonValue.asNumber();
+ case JsonConstants.VTYPE_FLOAT:
+ return (float) encodedJsonValue.asNumber();
+ case JsonConstants.VTYPE_DOUBLE:
+ return encodedJsonValue.asNumber();
+ case JsonConstants.VTYPE_BOOLEAN:
+ return encodedJsonValue.asBoolean();
+ default:
+ break;
}
throw new JsonException("Unknown type " + transportType);
if (directory.exists() && !directory.isHidden()) {
// Get the list of the files contained in the directory
String[] files = directory.list();
- for (int i = 0; i < files.length; i++) {
+ for (String file : files) {
// we are only interested in .gwt.xml files
- if (!files[i].endsWith(".gwt.xml")) {
+ if (!file.endsWith(".gwt.xml")) {
continue;
}
-
// remove the .gwt.xml extension
- String classname = files[i].substring(0, files[i].length() - 8);
+ String classname = file.substring(0, file.length() - 8);
String packageName = locationString
- .substring(locationString.lastIndexOf("/") + 1);
+ .substring(locationString.lastIndexOf("/") + 1);
classname = packageName + "." + classname;
-
if (!WidgetSetBuilder.isWidgetset(classname)) {
// Only return widgetsets and not GWT modules to avoid
// comparing modules and widgetsets
continue;
}
-
if (!widgetsets.containsKey(classname)) {
String packagePath = packageName.replaceAll("\\.", "/");
String basePath = location.getFile();
if (basePath.endsWith("/" + packagePath)) {
basePath = basePath.replaceAll("/" + packagePath + "$",
- "");
+ "");
} else if (basePath.endsWith("/" + packagePath + "/")) {
basePath = basePath.replaceAll("/" + packagePath + "/$",
- "");
+ "");
} else {
throw new IllegalStateException(
- "Error trying to find base path, location ("
- + location.getFile()
- + ") does not end in expected '/"
- + packagePath + "'");
+ "Error trying to find base path, location ("
+ + location.getFile()
+ + ") does not end in expected '/"
+ + packagePath + "'");
}
try {
URL url = new URL(location.getProtocol(),
- location.getHost(), location.getPort(),
- basePath);
+ location.getHost(), location.getPort(),
+ basePath);
widgetsets.put(classname, url);
} catch (MalformedURLException e) {
// should never happen as based on an existing URL,
.getValue("Vaadin-Widgetsets");
if (value != null) {
String[] widgetsetNames = value.split(",");
- for (int i = 0; i < widgetsetNames.length; i++) {
- String widgetsetname = widgetsetNames[i].trim();
+ for (String widgetsetName : widgetsetNames) {
+ String widgetsetname = widgetsetName.trim();
if (!widgetsetname.equals("")) {
widgetsets.put(widgetsetname, location);
}
.getValue("Vaadin-Stylesheets");
if (value != null) {
String[] stylesheets = value.split(",");
- for (int i = 0; i < stylesheets.length; i++) {
- String stylesheet = stylesheets[i].trim();
+ for (String untrimmedStylesheet : stylesheets) {
+ String stylesheet = untrimmedStylesheet.trim();
if (!stylesheet.equals("")) {
addonStyles.put(stylesheet, location);
}
debug("Classpath: " + classpath);
String[] split = classpath.split(pathSep);
- for (int i = 0; i < split.length; i++) {
- String classpathEntry = split[i];
+ for (String classpathEntry : split) {
if (acceptClassPathEntry(classpathEntry)) {
locations.add(classpathEntry);
}
// add all directories recursively
File[] dirs = file.listFiles(DIRECTORIES_ONLY);
- for (int i = 0; i < dirs.length; i++) {
+ for (File dir : dirs) {
try {
// add the present directory
- if (!dirs[i].isHidden()
- && !dirs[i].getPath().contains(File.separator + ".")) {
- String key = dirs[i].getCanonicalPath() + "/" + name
- + dirs[i].getName();
- URL url = dirs[i].getCanonicalFile().toURI().toURL();
+ if (!dir.isHidden() && !dir.getPath().contains(File.separator + ".")) {
+ String key = dir.getCanonicalPath() + "/" + name + dir.getName();
+ URL url = dir.getCanonicalFile().toURI().toURL();
locations.put(key, url);
}
- } catch (Exception ioe) {
+ }catch (Exception ioe) {
return;
}
- include(name + dirs[i].getName(), dirs[i], locations);
+ include(name + dir.getName(), dir, locations);
}
}
}
String[] cssProperties = css.split(";");
- for (int i = 0; i < cssProperties.length; i++) {
- String[] keyValuePair = cssProperties[i].split(":");
+ for (String cssProperty : cssProperties) {
+ String[] keyValuePair = cssProperty.split(":");
String key = keyValuePair[0].trim();
if (key.equals("")) {
continue;
String symbol = value.replaceAll("[0-9\\.\\-]+", "");
if (!symbol.equals("")) {
value = value.substring(0, value.indexOf(symbol))
- .trim();
+ .trim();
}
float v = Float.parseFloat(value);
Unit unit = Unit.getUnitFromSymbol(symbol);
- if (key.equals("top")) {
- topValue = v;
- topUnits = unit;
- } else if (key.equals("right")) {
- rightValue = v;
- rightUnits = unit;
- } else if (key.equals("bottom")) {
- bottomValue = v;
- bottomUnits = unit;
- } else if (key.equals("left")) {
- leftValue = v;
- leftUnits = unit;
+ switch (key) {
+ case "top":
+ topValue = v;
+ topUnits = unit;
+ break;
+ case "right":
+ rightValue = v;
+ rightUnits = unit;
+ break;
+ case "bottom":
+ bottomValue = v;
+ bottomUnits = unit;
+ break;
+ case "left":
+ leftValue = v;
+ leftUnits = unit;
+ break;
}
}
}
// this is implemented differently than other listeners to maintain
// backwards compatibility
if (progressListeners != null) {
- for (Iterator<ProgressListener> it = progressListeners
- .iterator(); it.hasNext();) {
- ProgressListener l = it.next();
+ for (ProgressListener l : progressListeners) {
l.updateProgress(totalBytes, contentLength);
}
}
propertyName = removeSubsequentUppercase(propertyName);
String[] words = propertyName.split("(?<!^)(?=[A-Z])");
StringBuilder builder = new StringBuilder();
- for (int i = 0; i < words.length; i++) {
+ for (String word : words) {
if (builder.length() > 0) {
builder.append("-");
}
- builder.append(words[i].toLowerCase());
+ builder.append(word.toLowerCase());
}
return builder.toString();
}
throw new IllegalArgumentException(
"Value must be OK or NOTOK");
}, model -> {
- if (model.equals("1")) {
- return "OK";
- } else if (model.equals("2")) {
- return "NOTOK";
- } else {
- throw new IllegalArgumentException(
- "Value in model must be 1 or 2");
- }
+ switch (model) {
+ case "1":
+ return "OK";
+ case "2":
+ return "NOTOK";
+ default:
+ throw new IllegalArgumentException(
+ "Value in model must be 1 or 2");
+ }
});
binding.bind(StatusBean::getStatus, StatusBean::setStatus);
binder.setBean(bean);
}
String[] split = classpath.split(pathSep);
- for (int i = 0; i < split.length; i++) {
- String classpathEntry = split[i];
+ for (String classpathEntry : split) {
locations.add(classpathEntry);
}
Boolean[] explicitImmediate = { null, Boolean.FALSE, Boolean.TRUE,
Boolean.TRUE };
boolean[] immediate = { true, false, true, true };
- for (int i = 0; i < design.length; i++) {
- component = (AbstractComponent) Design
- .read(new ByteArrayInputStream(
- design[i].getBytes(Charset.forName("UTF-8"))));
+ for (String designElements : design) {
+ component = (AbstractComponent) Design.read(new ByteArrayInputStream(designElements.getBytes(Charset.forName("UTF-8"))));
}
}