Skip to content

Commit

Permalink
JSPWIKI-1136 - Refine Class member fields
Browse files Browse the repository at this point in the history
  • Loading branch information
arturobernalg committed Dec 6, 2020
1 parent 9c313bf commit 41863a1
Show file tree
Hide file tree
Showing 71 changed files with 162 additions and 153 deletions.
14 changes: 8 additions & 6 deletions jspwiki-api/src/main/java/org/apache/wiki/api/Release.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ public static boolean isNewerOrEqual( final String version ) throws IllegalArgum
return true;
}
final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS );
final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION;
final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION;
final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION;
final int versionCompoLength = versionComponents.length;
final int reqVersion = versionCompoLength > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION;
final int reqRevision = versionCompoLength > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION;
final int reqMinorRevision = versionCompoLength > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION;

if( VERSION == reqVersion ) {
if( REVISION == reqRevision ) {
Expand Down Expand Up @@ -139,9 +140,10 @@ public static boolean isOlderOrEqual( final String version ) throws IllegalArgum
}

final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS );
final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION;
final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION;
final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION;
final int versionCompoLength = versionComponents.length;
final int reqVersion = versionCompoLength > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION;
final int reqRevision = versionCompoLength > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION;
final int reqMinorRevision = versionCompoLength > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION;

if( VERSION == reqVersion ) {
if( REVISION == reqRevision ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public final class WikiEventManager {
private static final Logger log = Logger.getLogger(WikiEventManager.class);

/* If true, permits a WikiEventMonitor to be set. */
private static boolean c_permitMonitor = false;
private static final boolean c_permitMonitor = false;

/* Optional listener to be used as all-event monitor. */
private static WikiEventListener c_monitor = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public class WikiPageEvent extends WikiEvent {
/** Indicates a wiki page reindex event (a page was changed when requested to a provided) */
public static final int PAGE_REINDEX = 28;

private String m_pagename;
private final String m_pagename;

// ............

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WikiPageRenameEvent extends WikiPageEvent {
/** Indicates a page rename event. This is based on events generated by {@link org.apache.wiki.content.PageRenamer}. */
public static final int PAGE_RENAMED = 28;

private String m_oldpagename;
private final String m_oldpagename;

// ............

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one
*/
public class LinkCollector implements StringTransmutator {

private List< String > m_items = new ArrayList<>();
private final List< String > m_items = new ArrayList<>();

/**
* Returns a List of Strings representing links.
Expand Down
8 changes: 4 additions & 4 deletions jspwiki-main/src/main/java/org/apache/wiki/WatchDog.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ Licensed to the Apache Software Foundation (ASF) under one
*/
public final class WatchDog {

private Watchable m_watchable;
private final Watchable m_watchable;
private final Stack< State > m_stateStack = new Stack<>();
private boolean m_enabled = true;
private Engine m_engine;
private final Engine m_engine;

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

private static Map< Integer, WeakReference< WatchDog > > c_kennel = new ConcurrentHashMap<>();
private static final Map< Integer, WeakReference< WatchDog > > c_kennel = new ConcurrentHashMap<>();
private static WikiBackgroundThread c_watcherThread;

/**
Expand Down Expand Up @@ -399,7 +399,7 @@ protected long getExpiryTime() {
* This class wraps a Thread so that it can become Watchable.
*/
private static class ThreadWrapper implements Watchable {
private Thread m_thread;
private final Thread m_thread;

public ThreadWrapper( final Thread thread ) {
m_thread = thread;
Expand Down
2 changes: 1 addition & 1 deletion jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public class WikiEngine implements Engine {
private boolean m_isConfigured = false;

/** Stores wikiengine attributes. */
private Map< String, Object > m_attributes = new ConcurrentHashMap<>();
private final Map< String, Object > m_attributes = new ConcurrentHashMap<>();

/** Stores WikiEngine's associated managers. */
protected Map< Class< ? >, Object > managers = new ConcurrentHashMap<>();
Expand Down
4 changes: 2 additions & 2 deletions jspwiki-main/src/main/java/org/apache/wiki/WikiPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Licensed to the Apache Software Foundation (ASF) under one
// need to figure out the metadata lifecycle.
public class WikiPage implements Page {

private String m_name;
private Engine m_engine;
private final String m_name;
private final Engine m_engine;
private String m_wiki;
private Date m_lastModified;
private long m_fileSize = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public final class WikiSession implements Session {

private static final String ALL = "*";

private static ThreadLocal< Session > c_guestSession = new ThreadLocal<>();
private static final ThreadLocal< Session > c_guestSession = new ThreadLocal<>();

private final Subject m_subject = new Subject();

Expand Down
7 changes: 4 additions & 3 deletions jspwiki-main/src/main/java/org/apache/wiki/ajax/AjaxUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Licensed to the Apache Software Foundation (ASF) under one
*/
public class AjaxUtil extends HttpServlet {
private static final long serialVersionUID = 3170439306358345408L;
private static Gson gson = new Gson();
private static final Gson gson = new Gson();

/**
* Uses Google Gson (https://code.google.com/p/google-gson/) to convert to JSON
Expand Down Expand Up @@ -65,15 +65,16 @@ public static String getNextPathPart( String path, String lastPart ) throws Serv
if( !lastPart.endsWith( "/" ) ) {
lastPart += "/";
}
final int lastPartLength = lastPart.length();
int index = path.indexOf( lastPart );
if( index < 0 ) {
lastPart = lastPart.substring( 0, lastPart.length() - 1 );
lastPart = lastPart.substring( 0, lastPartLength - 1 );
index = path.indexOf( lastPart );
if( index < 0 ) {
throw new ServletException( "Invalid path provided " + path + " does not contain '" + lastPart + "'" );
}
}
path = path.substring( index + lastPart.length() );
path = path.substring( index + lastPartLength );
index = path.indexOf( "/" );
if( index == -1 ) {
index = path.indexOf( "#" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one
public class Attachment extends WikiPage implements org.apache.wiki.api.core.Attachment {

private String m_fileName;
private String m_parentName;
private final String m_parentName;
private boolean m_cacheable = true;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class DefaultAttachmentManager implements AttachmentManager {

private static final Logger log = Logger.getLogger( DefaultAttachmentManager.class );
private AttachmentProvider m_provider;
private Engine m_engine;
private CacheManager m_cacheManager = CacheManager.getInstance();
private final Engine m_engine;
private final CacheManager m_cacheManager = CacheManager.getInstance();
private Cache m_dynamicAttachments;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class DefaultAuthenticationManager implements AuthenticationManager {
private boolean m_storeIPAddress = true;

/** Keeps a list of the usernames who have attempted a login recently. */
private TimedCounterList< String > m_lastLoginAttempts = new TimedCounterList<>();
private final TimedCounterList< String > m_lastLoginAttempts = new TimedCounterList<>();

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class DefaultAuthorizationManager implements AuthorizationManager {
private Authorizer m_authorizer = null;

/** Cache for storing ProtectionDomains used to evaluate the local policy. */
private Map< Principal, ProtectionDomain > m_cachedPds = new WeakHashMap<>();
private final Map< Principal, ProtectionDomain > m_cachedPds = new WeakHashMap<>();

private Engine m_engine = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public Principal[] listWikiNames() throws WikiSecurityException {
*/
public static final class JSONUserModule implements WikiAjaxServlet {

private volatile DefaultUserManager m_manager;
private final DefaultUserManager m_manager;

/**
* Create a new JSONUserModule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ Licensed to the Apache Software Foundation (ASF) under one
*/
public final class SecurityVerifier {

private Engine m_engine;
private final Engine m_engine;

private boolean m_isSecurityPolicyConfigured = false;

private Principal[] m_policyPrincipals = new Principal[0];

private Session m_session;
private final Session m_session;

/** Message prefix for errors. */
public static final String ERROR = "Error.";
Expand Down Expand Up @@ -199,10 +199,13 @@ public String policyRoleTable()
final String[] groupActions = new String[]
{ "view", "edit", null, null, "delete" };


final int rolesLength = roles.length;
final int pageActionsLength = pageActions.length;
// Calculate column widths
final String colWidth;
if( pageActions.length > 0 && roles.length > 0 ) {
colWidth = ( 67f / ( pageActions.length * roles.length ) ) + "%";
if( pageActionsLength > 0 && rolesLength > 0 ) {
colWidth = ( 67f / ( pageActionsLength * rolesLength ) ) + "%";
} else {
colWidth = "67%";
}
Expand All @@ -212,20 +215,20 @@ public String policyRoleTable()
// Write the table header
s.append( "<table class=\"wikitable\" border=\"1\">\n" );
s.append( " <colgroup span=\"1\" width=\"33%\"/>\n" );
s.append( " <colgroup span=\"" + pageActions.length * roles.length + "\" width=\"" + colWidth
s.append( " <colgroup span=\"" + pageActionsLength * rolesLength + "\" width=\"" + colWidth
+ "\" align=\"center\"/>\n" );
s.append( " <tr>\n" );
s.append( " <th rowspan=\"2\" valign=\"bottom\">Permission</th>\n" );
for( int i = 0; i < roles.length; i++ )
for( int i = 0; i < rolesLength; i++ )
{
s.append( " <th colspan=\"" + pageActions.length + "\" title=\"" + roles[i].getClass().getName() + "\">"
s.append( " <th colspan=\"" + pageActionsLength + "\" title=\"" + roles[i].getClass().getName() + "\">"
+ roles[i].getName() + "</th>\n" );
}
s.append( " </tr>\n" );

// Print a column for each role
s.append( " <tr>\n" );
for( int i = 0; i < roles.length; i++ )
for( int i = 0; i < rolesLength; i++ )
{
for( final String pageAction : pageActions )
{
Expand Down Expand Up @@ -272,7 +275,7 @@ public String policyRoleTable()
s.append( " <td>WikiPermission \"" + wiki + "\",\"" + wikiPerm + "\"</td>\n" );
for( final Principal role : roles ) {
final Permission permission = new WikiPermission( wiki, wikiPerm );
s.append( printPermissionTest( permission, role, pageActions.length ) );
s.append( printPermissionTest( permission, role, pageActionsLength ) );
}
s.append( " </tr>\n" );
}
Expand All @@ -283,7 +286,7 @@ public String policyRoleTable()
for( final Principal role : roles )
{
final Permission permission = new AllPermission( wiki );
s.append( printPermissionTest( permission, role, pageActions.length ) );
s.append( printPermissionTest( permission, role, pageActionsLength ) );
}
s.append( " </tr>\n" );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Licensed to the Apache Software Foundation (ASF) under one
public class AclEntryImpl implements AclEntry, Serializable {

private static final long serialVersionUID = 1L;
private Vector< Permission > m_permissions = new Vector<>();
private final Vector< Permission > m_permissions = new Vector<>();
private Principal m_principal;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ public class XMLGroupDatabase implements GroupDatabase {

private Document m_dom = null;

private DateFormat m_defaultFormat = DateFormat.getDateTimeInstance();
private final DateFormat m_defaultFormat = DateFormat.getDateTimeInstance();

private File m_file = null;

private Engine m_engine = null;

private Map<String, Group> m_groups = new ConcurrentHashMap<>();
private final Map<String, Group> m_groups = new ConcurrentHashMap<>();

/**
* Looks up and deletes a {@link Group} from the group database. If the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,15 @@ public GroupPermission( String group, String actions )
m_group = groupName;

// Parse actions
String[] groupActions = actions.toLowerCase().split( ACTION_SEPARATOR );
final String[] groupActions = actions.toLowerCase().split( ACTION_SEPARATOR );
Arrays.sort( groupActions, String.CASE_INSENSITIVE_ORDER );
m_mask = createMask( actions );
StringBuilder buffer = new StringBuilder();
for( int i = 0; i < groupActions.length; i++ )
final int groupActionsLength = groupActions.length;
for( int i = 0; i < groupActionsLength; i++ )
{
buffer.append( groupActions[i] );
if ( i < ( groupActions.length - 1 ) )
if ( i < ( groupActionsLength - 1 ) )
{
buffer.append( ACTION_SEPARATOR );
}
Expand Down Expand Up @@ -345,7 +346,7 @@ protected static int impliedMask( int mask )
* @param actions the actions for this permission, separated by commas
* @return the binary actions mask
*/
protected static int createMask( String actions )
protected static int createMask( final String actions )
{
if ( actions == null || actions.length() == 0 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,12 @@ public PagePermission( final String page, final String actions )
final String[] pageActions = StringUtils.split( actions.toLowerCase(), ACTION_SEPARATOR );
Arrays.sort( pageActions, String.CASE_INSENSITIVE_ORDER );
m_mask = createMask( actions );
final int pageActionsLength = pageActions.length;
final StringBuilder buffer = new StringBuilder();
for( int i = 0; i < pageActions.length; i++ )
for( int i = 0; i < pageActionsLength; i++ )
{
buffer.append( pageActions[i] );
if ( i < ( pageActions.length - 1 ) )
if ( i < ( pageActionsLength - 1 ) )
{
buffer.append( ACTION_SEPARATOR );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private PermissionFactory() {}
* This is a WeakHashMap<Integer,PagePermission>, which stores the
* cached page permissions.
*/
private static WeakHashMap<Integer, PagePermission> c_cache = new WeakHashMap<>();
private static final WeakHashMap<Integer, PagePermission> c_cache = new WeakHashMap<>();

/**
* Get a permission object for a WikiPage and a set of actions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class DefaultUserProfile implements UserProfile {
private static final String EMPTY_STRING = "";
private static final String WHITESPACE = "\\s";

private Map< String, Serializable > attributes = new HashMap<>();
private final Map< String, Serializable > attributes = new HashMap<>();
private Date created = null;
private String email = null;
private String fullname = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ private String[] sequence( final String wikiText ) {
* all necessary variables.
*/
private final class ChangeMerger implements RevisionVisitor {
private StringBuffer m_sb;
private final StringBuffer m_sb;

/** Keeping score of the original lines to process */
private int m_max;
private final int m_max;

private int m_index = 0;

Expand All @@ -227,7 +227,7 @@ private final class ChangeMerger implements RevisionVisitor {
private StringBuffer m_newBuf;

/** Reference to the source string array */
private String[] m_origStrings;
private final String[] m_origStrings;

private ChangeMerger( final StringBuffer sb, final String[] origStrings, final int max ) {
m_sb = sb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class ExternalDiffProvider implements DiffProvider {
//the external program generates a format suitible for the colorization code of the
//TraditionalDiffProvider, currently set to true for legacy compatibility.
//I don't think this 'feature' ever worked right, did it?...
private boolean m_traditionalColorization = true;
private final boolean m_traditionalColorization = true;

/**
* Creates a new ExternalDiffProvider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public String makeDiffHtml( final Context ctx, final String p1, final String p2

private static final class RevisionPrint implements RevisionVisitor {

private StringBuffer m_result;
private Context m_context;
private ResourceBundle m_rb;
private final StringBuffer m_result;
private final Context m_context;
private final ResourceBundle m_rb;

private RevisionPrint( final Context ctx, final StringBuffer sb ) {
m_result = sb;
Expand Down
Loading

0 comments on commit 41863a1

Please sign in to comment.