Skip to content

Commit

Permalink
- typos
Browse files Browse the repository at this point in the history
- cosmetics
- micro optimizations
- generics
- for loop
- code clarifications
- final on effective final class variables

Signed-off-by: pizzi80 <[email protected]>
  • Loading branch information
pizzi80 committed Mar 2, 2024
1 parent 39ed397 commit a14a03a
Show file tree
Hide file tree
Showing 20 changed files with 410 additions and 444 deletions.
4 changes: 2 additions & 2 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<description>EE4J Compatible Implementation for Jakarta Faces API</description>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<mojarra.logstrings.version>${project.version}</mojarra.logstrings.version>
</properties>

Expand Down
3 changes: 3 additions & 0 deletions impl/src/main/java/com/sun/faces/RIConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class RIConstants {

public static final Class<?>[] EMPTY_CLASS_ARGS = new Class[0];
public static final Object[] EMPTY_METH_ARGS = new Object[0];
public static final String[][] EMPTY_STRING_MATRIX = new String[0][0];

/**
* <p>
Expand All @@ -71,6 +72,8 @@ public class RIConstants {

public static final String PUSH_RESOURCE_URLS_KEY_NAME = FACES_PREFIX + "resourceUrls";

public static final String RESOURCE_NOT_FOUND = "RES_NOT_FOUND";

/**
* Marker used when saving the list of component adds and removes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public String convertToString(Class<?> targetClass, Object value) {
protected UIComponent getComponent() {
FacesContext context = FacesContext.getCurrentInstance();
if (context != null) {
return (UIComponent) RequestStateManager.get(context, RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME);
return RequestStateManager.get(context, RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public String toString() {

/**
* Create the full path to the resource. If the resource can be compressed, setup the compressedPath ivar so that the
* path refers to the directory refereneced by the context attribute <code>jakarta.servlet.context.tempdir</code>.
* path refers to the directory referenced by the context attribute <code>jakarta.servlet.context.tempdir</code>.
*/
private void initPath(boolean isDevStage) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public class ResourceCache {
/**
* The <code>ResourceInfo<code> cache.
*/
private MultiKeyConcurrentHashMap<Object, ResourceInfoCheckPeriodProxy> resourceCache;
private final MultiKeyConcurrentHashMap<Object, ResourceInfoCheckPeriodProxy> resourceCache;

/**
* Resource check period in minutes.
*/
private long checkPeriod;
private final long checkPeriod;

// ------------------------------------------------------------ Constructors

Expand Down Expand Up @@ -99,8 +99,14 @@ public ResourceInfo add(ResourceInfo info, List<String> contracts) {
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, "Caching ResourceInfo: {0}", info.toString());
}
ResourceInfoCheckPeriodProxy proxy = resourceCache.putIfAbsent(info.name, info.libraryName, info.localePrefix, new ArrayList(contracts),
new ResourceInfoCheckPeriodProxy(info, checkPeriod));
ResourceInfoCheckPeriodProxy proxy = resourceCache.putIfAbsent(
info.name,
info.libraryName,
info.localePrefix,
new ArrayList<>(contracts),
new ResourceInfoCheckPeriodProxy(info, checkPeriod)
);

return proxy != null ? proxy.getResourceInfo() : null;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected boolean compressContent(ClientResourceInfo info) throws IOException {
* </p>
*
* <p>
* See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html RFC 2616, sec. 14 for details on the
* See <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">...</a> RFC 2616, sec. 14 for details on the
* accept-encoding header.
* </p>
*
Expand Down Expand Up @@ -416,7 +416,7 @@ protected boolean clientAcceptsCompression(FacesContext ctx) {
break;
}
if (value.contains("*") && !value.contains("*;q=0,") && !value.endsWith("*;q=0")) {
// gzip not explictly listed, but client sent *
// gzip not explicitly listed, but client sent *
// meaning gzip is implicitly acceptable
// keep looping to ensure we don't come across a
// *;q=0 value.
Expand All @@ -436,7 +436,7 @@ protected boolean clientAcceptsCompression(FacesContext ctx) {

/**
* <p>
* Utility method to peform the necessary actions to compress content.
* Utility method to perform the necessary actions to compress content.
* </p>
*
* <p>
Expand Down Expand Up @@ -568,7 +568,7 @@ public int read() throws IOException {
nextRead = -1;
failedExpressionTest = false;
} else if (writingExpression) {
if (0 < buf.size()) {
if ( !buf.isEmpty() ) {
i = buf.remove(0);
} else {
writingExpression = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.sun.faces.application.resource;

import java.util.Objects;

public class ResourceInfo {

ResourceHelper helper;
Expand All @@ -29,14 +31,13 @@ public class ResourceInfo {
boolean doNotCache = false;

public ResourceInfo(LibraryInfo library, ContractInfo contract, String name, VersionInfo version) {
this.contract = contract;
this.library = library;
helper = library.getHelper();
localePrefix = library.getLocalePrefix();
this.contract = contract;
this.name = name;
this.version = version;
libraryName = library.getName();

this.helper = library.getHelper();
this.localePrefix = library.getLocalePrefix();
this.libraryName = library.getName();
}

public ResourceInfo(ContractInfo contract, String name, VersionInfo version, ResourceHelper helper) {
Expand Down Expand Up @@ -73,49 +74,23 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ResourceInfo other = (ResourceInfo) obj;
if (helper != other.helper && (helper == null || !helper.equals(other.helper))) {
return false;
}
if (library != other.library && (library == null || !library.equals(other.library))) {
return false;
}
if (libraryName == null ? other.libraryName != null : !libraryName.equals(other.libraryName)) {
if ( ! (obj instanceof ResourceInfo info) ) {
return false;
}
if (localePrefix == null ? other.localePrefix != null : !localePrefix.equals(other.localePrefix)) {
return false;
}
if (name == null ? other.name != null : !name.equals(other.name)) {
return false;
}
if (path == null ? other.path != null : !path.equals(other.path)) {
return false;
}
if (version != other.version && (version == null || !version.equals(other.version))) {
return false;
}
if (doNotCache != other.doNotCache) {
return false;
}
return true;

return Objects.equals(helper, info.helper) &&
Objects.equals(library, info.library) &&
Objects.equals(libraryName, info.libraryName) &&
Objects.equals(localePrefix, info.localePrefix) &&
Objects.equals(name, info.name) &&
Objects.equals(path, info.path) &&
Objects.equals(version, info.version) &&
doNotCache == info.doNotCache;
}

@Override
public int hashCode() {
int hash = 7;
hash = 17 * hash + (helper != null ? helper.hashCode() : 0);
hash = 17 * hash + (library != null ? library.hashCode() : 0);
hash = 17 * hash + (libraryName != null ? libraryName.hashCode() : 0);
hash = 17 * hash + (localePrefix != null ? localePrefix.hashCode() : 0);
hash = 17 * hash + (name != null ? name.hashCode() : 0);
hash = 17 * hash + (path != null ? path.hashCode() : 0);
hash = 17 * hash + (version != null ? version.hashCode() : 0);
hash = 17 * hash + (doNotCache ? 1 : 0);
return hash;
return Objects.hash(helper, library, contract, libraryName, localePrefix, name, path, version, doNotCache);
}

public boolean isDoNotCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ public class ResourceManager {
/**
* {@link ResourceHelper} used for looking up webapp-based resources.
*/
private WebappResourceHelper webappResourceHelper = new WebappResourceHelper();
private final WebappResourceHelper webappResourceHelper = new WebappResourceHelper();

/**
* {@link ResourceHelper} used for looking up webapp-based facelets resources.
*/
private FaceletWebappResourceHelper faceletWebappResourceHelper = new FaceletWebappResourceHelper(webappResourceHelper);
private final FaceletWebappResourceHelper faceletWebappResourceHelper = new FaceletWebappResourceHelper(webappResourceHelper);

/**
* {@link ResourceHelper} used for looking up classpath-based resources.
*/
private ClasspathResourceHelper classpathResourceHelper = new ClasspathResourceHelper();
private final ClasspathResourceHelper classpathResourceHelper = new ClasspathResourceHelper();

/**
* Cache for storing {@link ResourceInfo} instances to reduce the cost of the resource lookups.
*/
private ResourceCache cache;
private final ResourceCache cache;

/**
* Patterns used to find {@link ResourceInfo} instances that may have their content compressed.
Expand Down Expand Up @@ -568,7 +568,7 @@ private List<String> getResourceLibraryContracts(FacesContext context) {
// it is a resource request. look at the parameter con=.

String param = context.getExternalContext().getRequestParameterMap().get("con");
if (!nameContainsForbiddenSequence(param) && param != null && param.trim().length() > 0) {
if (!nameContainsForbiddenSequence(param) && param != null && !param.trim().isEmpty()) {
return Arrays.asList(param);
}
}
Expand Down Expand Up @@ -610,7 +610,7 @@ private void initCompressableTypes(Map<String, Object> appMap) {

WebConfiguration config = WebConfiguration.getInstance();
String value = config.getOptionValue(WebConfiguration.WebContextInitParameter.CompressableMimeTypes);
if (value != null && value.length() > 0) {
if (value != null && !value.isEmpty()) {
String[] values = Util.split(appMap, value, ",");
if (values != null) {
for (String s : values) {
Expand Down
Loading

0 comments on commit a14a03a

Please sign in to comment.