Skip to content

Commit

Permalink
Code adjustments for JDK 7.
Browse files Browse the repository at this point in the history
  • Loading branch information
albertus82 committed Dec 2, 2023
1 parent 36d183f commit ddec976
Show file tree
Hide file tree
Showing 27 changed files with 63 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ else if (IDialogConstants.HIDE_DETAILS_LABEL.equals(detailsButton.getText())) {
}

public static MultiStatus createMultiStatus(final int severity, final Throwable throwable) {
final Collection<IStatus> childStatuses = new ArrayList<IStatus>();
final Collection<IStatus> childStatuses = new ArrayList<>();

if (throwable != null) {
StringReader sr = null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/albertus82/jface/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ else if (bufferedImage.getColorModel() instanceof IndexColorModel) {
}

public static Map<Rectangle, Image> createImageMap(final Iterable<String> resourceNames, final SortOrder areaSortOrder) {
final Map<Rectangle, Image> map = new TreeMap<Rectangle, Image>(getAreaComparator(areaSortOrder));
final Map<Rectangle, Image> map = new TreeMap<>(getAreaComparator(areaSortOrder));
for (final String resourceName : resourceNames) {
InputStream stream = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static String get(final String key) {
}

public static String get(final String key, final Object... params) {
final List<String> stringParams = new ArrayList<String>(params.length);
final List<String> stringParams = new ArrayList<>(params.length);
for (final Object param : params) {
stringParams.add(String.valueOf(param));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

public class LocalizedWidgets implements Map<Widget, ISupplier<String>> {

private static final Map<Class<? extends Widget>, Method> setTextMethods = new HashMap<Class<? extends Widget>, Method>();
private static final Map<Class<? extends Widget>, Method> setTextMethods = new HashMap<>();

private final Map<Widget, ISupplier<String>> wrappedMap;

/** @see HashMap#HashMap() */
public LocalizedWidgets() {
wrappedMap = new HashMap<Widget, ISupplier<String>>();
wrappedMap = new HashMap<>();
}

/**
Expand All @@ -29,7 +29,7 @@ public LocalizedWidgets() {
* @see HashMap#HashMap(int)
*/
public LocalizedWidgets(final int initialCapacity) {
wrappedMap = new HashMap<Widget, ISupplier<String>>(initialCapacity);
wrappedMap = new HashMap<>(initialCapacity);
}

@Override
Expand Down Expand Up @@ -106,7 +106,7 @@ public Set<Entry<Widget, ISupplier<String>>> entrySet() {

public <T extends Widget> Entry<T, ISupplier<String>> putAndReturn(final T widget, final ISupplier<String> textSupplier) {
put(widget, textSupplier);
return new SimpleEntry<T, ISupplier<String>>(widget, textSupplier);
return new SimpleEntry<>(widget, textSupplier);
}

public void resetText(final Widget widget) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/github/albertus82/jface/maps/MapDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
Expand Down Expand Up @@ -49,7 +50,7 @@ public abstract class MapDialog extends Dialog implements LineParser {

protected static final String HTML_FILE_NAME = "map.html";

private final Set<MapMarker> markers = new HashSet<MapMarker>();
private final Set<MapMarker> markers = new HashSet<>();

private volatile int returnCode = Window.CANCEL;

Expand Down Expand Up @@ -142,7 +143,7 @@ public static URI getMapPage(final Control control, final InputStream is, final
FileWriter fw = null;
BufferedWriter bw = null;
try {
isr = new InputStreamReader(is, "UTF-8");
isr = new InputStreamReader(is, StandardCharsets.UTF_8);
br = new BufferedReader(isr);
tempFile = File.createTempFile(UUID.randomUUID().toString().replace("-", "").toLowerCase(Locale.ROOT), ".html");
fw = new FileWriter(tempFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GoogleMapOptions extends MapOptions {

private GoogleMapType type = DEFAULT_TYPE;

private final Map<GoogleMapControl, Boolean> controls = new EnumMap<GoogleMapControl, Boolean>(GoogleMapControl.class);
private final Map<GoogleMapControl, Boolean> controls = new EnumMap<>(GoogleMapControl.class);

public GoogleMapOptions() {/* Default constructor */}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map.Entry;

Expand Down Expand Up @@ -92,7 +93,7 @@ private static String readAllResource(final String resourceName) {
if (is == null) {
return null;
}
isr = new InputStreamReader(is, "UTF-8");
isr = new InputStreamReader(is, StandardCharsets.UTF_8);
br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LeafletMapOptions extends MapOptions {

private static final long serialVersionUID = 6601920089135707963L;

private final Map<LeafletMapControl, String> controls = new EnumMap<LeafletMapControl, String>(LeafletMapControl.class);
private final Map<LeafletMapControl, String> controls = new EnumMap<>(LeafletMapControl.class);

public Map<LeafletMapControl, String> getControls() {
return controls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class LocalizedLabelsAndValues implements LabelsAndValues {
private final List<LabelValue> entries;

public LocalizedLabelsAndValues() {
entries = new ArrayList<LabelValue>();
entries = new ArrayList<>();
}

public LocalizedLabelsAndValues(final int initialCapacity) {
entries = new ArrayList<LabelValue>(initialCapacity);
entries = new ArrayList<>(initialCapacity);
}

public LocalizedLabelsAndValues(final ISupplier<String> name, final Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public int openDialog(final Shell parentShell, final IPageDefinition selectedPag
preferenceDialog.setSelectedNode(selectedPage.getNodeId());
}

final Map<String, String> configurationBackup = new HashMap<String, String>();
final Map<String, String> configurationBackup = new HashMap<>();
for (final IPreference preference : preferenceItems) {
if (preference.isRestartRequired()) {
configurationBackup.put(preference.getName(), preferenceStore.getString(preference.getName()));
Expand Down Expand Up @@ -136,7 +136,7 @@ protected PreferenceManager createPreferenceManager() {
final PreferenceManager manager = new PreferenceManager();

// Pages creation...
final Map<IPageDefinition, PreferenceNode> preferenceNodes = new HashMap<IPageDefinition, PreferenceNode>();
final Map<IPageDefinition, PreferenceNode> preferenceNodes = new HashMap<>();
for (final IPageDefinition page : pageDefinitions) {
final PreferenceNode preferenceNode = new ConfigurationNode(page, preferenceItems, preferencesCallback);
if (page.getParent() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class StaticLabelsAndValues implements LabelsAndValues {
private final Map<String, String> entries;

public StaticLabelsAndValues() {
entries = new LinkedHashMap<String, String>();
entries = new LinkedHashMap<>();
}

public StaticLabelsAndValues(final int expectedSize) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.albertus82.jface.preference.field;

import java.nio.charset.Charset;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
Expand Down Expand Up @@ -50,7 +51,7 @@ public PasswordFieldEditor(final String name, final String labelText, final Stri
super(name, labelText, parent);
if (hashAlgorithm != null && !hashAlgorithm.isEmpty()) {
this.messageDigest = MessageDigest.getInstance(hashAlgorithm);
this.charset = Charset.forName(DEFAULT_CHARSET_NAME);
this.charset = StandardCharsets.UTF_8;
}
init();
}
Expand All @@ -59,7 +60,7 @@ public PasswordFieldEditor(final String name, final String labelText, final Stri
super(name, labelText, width, parent);
if (hashAlgorithm != null && !hashAlgorithm.isEmpty()) {
this.messageDigest = MessageDigest.getInstance(hashAlgorithm);
this.charset = Charset.forName(DEFAULT_CHARSET_NAME);
this.charset = StandardCharsets.UTF_8;
}
init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class BasePreferencePage extends FieldEditorPreferencePage {

private static final Logger log = LoggerFactory.getLogger(BasePreferencePage.class);

protected static final Map<IPreference, FieldEditorWrapper> universe = new HashMap<IPreference, FieldEditorWrapper>();
protected static final Map<IPreference, FieldEditorWrapper> universe = new HashMap<>();

protected final Map<IPreference, FieldEditorWrapper> fieldEditorMap = new HashMap<IPreference, FieldEditorWrapper>();
protected final Map<IPreference, FieldEditorWrapper> fieldEditorMap = new HashMap<>();
protected Control header;

private IPreferencesCallback preferencesCallback;
Expand Down Expand Up @@ -239,7 +239,7 @@ public void updateCrossChildrenStatus() {
for (final IPreference preference : fieldEditorMap.keySet()) { // iterate over all the preferences on the current page
IPreference parentPreference = preference.getParent();
if (parentPreference != null && !fieldEditorMap.containsKey(parentPreference)) { // if the parent is on another page
final Set<IPreference> parents = new HashSet<IPreference>();
final Set<IPreference> parents = new HashSet<>();

while (parentPreference != null) {
parents.add(parentPreference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
Expand Down Expand Up @@ -57,7 +58,7 @@ public abstract class BaseHttpHandler implements HttpPathHandler {

private static Collection<Resource> resources; // Lazy initialization (may be huge)

private static final Charset charset = initCharset();
private static final Charset charset = StandardCharsets.UTF_8;

public static final String PREFERRED_CHARSET = "UTF-8";

Expand Down Expand Up @@ -118,7 +119,7 @@ public void handle(final HttpExchange exchange) throws IOException {
}

protected Map<String, Object> buildSafeHeadersMap(final Headers headers) {
final Map<String, Object> headersToLog = new TreeMap<String, Object>();
final Map<String, Object> headersToLog = new TreeMap<>();
for (final Entry<String, List<String>> entry : headers.entrySet()) {
final String key = entry.getKey();
if (key != null) {
Expand Down Expand Up @@ -217,7 +218,7 @@ protected void doTrace(final HttpExchange exchange) throws IOException {
}

protected void doOptions(final HttpExchange exchange) throws IOException {
final Set<String> allowedMethods = new TreeSet<String>();
final Set<String> allowedMethods = new TreeSet<>();
if (httpServerConfig.isTraceMethodEnabled()) {
allowedMethods.add(HttpMethod.TRACE.toUpperCase());
}
Expand Down Expand Up @@ -288,18 +289,6 @@ private Method[] getAllDeclaredMethods(final Class<?> c) {
return thisMethods;
}

private static Charset initCharset() {
final String charsetName = PREFERRED_CHARSET;
try {
return Charset.forName(charsetName);
}
catch (final RuntimeException e) {
final Charset defaultCharset = Charset.defaultCharset();
log.log(Level.WARNING, "Cannot determine charset for name \"" + charsetName + "\", falling back to " + defaultCharset + ':', e);
return defaultCharset;
}
}

/**
* Set the {@code Content-Type} response header. The value is determined by the
* URI path extension. This method can be overriden by subclasses.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.albertus82.net.httpserver;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;
Expand All @@ -23,12 +24,10 @@ public class HttpServerAuthenticator extends BasicAuthenticator {

private static final Logger log = LoggerFactory.getLogger(HttpServerAuthenticator.class);

private static final String DEFAULT_CHARSET_NAME = "UTF-8";

private final IAuthenticatorConfig configuration;
private Charset charset = Charset.forName(DEFAULT_CHARSET_NAME);
private Charset charset = StandardCharsets.UTF_8;

private final ThreadLocal<HttpExchange> exchanges = new ThreadLocal<HttpExchange>();
private final ThreadLocal<HttpExchange> exchanges = new ThreadLocal<>();

public HttpServerAuthenticator(final IAuthenticatorConfig configuration) {
super(configuration.getRealm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected Collection<HttpContext> createContexts() {
filtersList = Collections.emptyList();
}

final Collection<HttpContext> httpContexts = new ArrayList<HttpContext>();
final Collection<HttpContext> httpContexts = new ArrayList<>();
final Authenticator authenticator = httpServerConfiguration.getAuthenticator();
final HttpPathHandler[] handlersArray = createHandlers();
if (handlersArray != null && handlersArray.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class RequestParameterExtractor {

public static final String PREFERRED_CHARSET = "UTF-8";

private final Map<String, String[]> parameterMap = new HashMap<String, String[]>();
private final Map<String, String[]> parameterMap = new HashMap<>();

public RequestParameterExtractor(final HttpExchange exchange, final Charset charset) throws IOException {
final Map<String, List<String>> params = new HashMap<String, List<String>>();
final Map<String, List<String>> params = new HashMap<>();
params.putAll(parseQueryParameters(exchange, charset));
if (HttpMethod.POST.equalsIgnoreCase(exchange.getRequestMethod()) || HttpMethod.PUT.equalsIgnoreCase(exchange.getRequestMethod()) || HttpMethod.DELETE.equalsIgnoreCase(exchange.getRequestMethod()) || HttpMethod.PATCH.equalsIgnoreCase(exchange.getRequestMethod())) {
params.putAll(parseBodyParameters(exchange, charset));
Expand Down Expand Up @@ -91,12 +91,12 @@ private Map<String, List<String>> parseBodyParameters(final HttpExchange exchang
}

private Map<String, List<String>> parseQuery(final String query, final Charset charset) throws UnsupportedEncodingException {
final Map<String, List<String>> map = new HashMap<String, List<String>>();
final Map<String, List<String>> map = new HashMap<>();
if (query != null) {
final String[] pairs = query.split("[&]");
final String[] pairs = query.split("&");

for (final String pair : pairs) {
final String[] param = pair.split("[=]");
final String[] param = pair.split("=");

String key = null;
String value = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

public class HtmlUtils {

private static final Set<Character> charsToEscapeForEcmaScript = new HashSet<Character>(Arrays.asList('&', '"', '<', '>', '\'', '/'));
private static final Set<Character> charsToEscapeForEcmaScript = new HashSet<>(Arrays.asList('&', '"', '<', '>', '\'', '/'));

private HtmlUtils() {
throw new IllegalAccessError("Utility class");
}

public static String escapeEcmaScript(final String unescaped) {
String escaped = unescaped.replace("\\", "\\\\");
final Set<Character> replacedChars = new HashSet<Character>();
final Set<Character> replacedChars = new HashSet<>();
for (final char c : escaped.toCharArray()) {
if (!replacedChars.contains(c) && (c < 0x20 || c > 0x7F || charsToEscapeForEcmaScript.contains(c))) {
escaped = escaped.replace(Character.toString(c), String.format(c > 0xFF ? "\\u%04X" : "\\x%02X", (int) c));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static void parseHeaders(final Iterable<byte[]> source, final Headers de
}

private static List<byte[]> split(final byte[] payload) {
final List<byte[]> byteArrays = new ArrayList<byte[]>();
final List<byte[]> byteArrays = new ArrayList<>();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int i = 0; i < payload.length; i++) {
if (payload.length > i + 3 && payload[i] == CR && payload[i + 1] == LF && payload[i + 2] == CR && payload[i + 3] == LF) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/github/albertus82/net/mqtt/MqttUtils.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package io.github.albertus82.net.mqtt;

import java.nio.charset.Charset;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class MqttUtils {

private MqttUtils() {
throw new IllegalAccessError("Utility class");
}

public static final Charset CHARSET_UTF8 = Charset.forName("UTF-8");
public static final Charset CHARSET_UTF8 = StandardCharsets.UTF_8;

static final String HEADER_KEY_CONTENT_ENCODING = "Content-Encoding";
static final String HEADER_KEY_CONTENT_LENGTH = "Content-Length";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/albertus82/util/ByteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static byte[] toByteArray(final int intValue) {
}

public static List<Byte> toByteList(final int intValue) {
final List<Byte> byteList = new ArrayList<Byte>(2);
final List<Byte> byteList = new ArrayList<>(2);
byteList.add((byte) intValue);
byteList.add((byte) (intValue >>> 8));
return byteList;
Expand Down
Loading

0 comments on commit ddec976

Please sign in to comment.