Skip to content

Commit

Permalink
Improved: Add missing ‘static’ modifier for private methods
Browse files Browse the repository at this point in the history
(OFBIZ-11098)

In order to make it clear when a method is not depending on the
internal state of an object, it is a good practice to declare it as
static.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1860937 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jun 10, 2019
1 parent 08f0b84 commit ffe2e7f
Show file tree
Hide file tree
Showing 42 changed files with 162 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public String toXml() {
* The value of the node being created.
* @return An XML node as a String in <nodName>nodeValue</nodeName> format
*/
private String createNode(String nodeName, String nodeValue) {
private static String createNode(String nodeName, String nodeValue) {
return "<" + nodeName + ">" + nodeValue + "</" + nodeName + ">";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public PcChargeApi send() throws IOException, GeneralException {

}

private boolean checkIn(String name) {
private static boolean checkIn(String name) {
for (String element : validOut) {
if (name.equals(element)) {
return false;
Expand All @@ -216,7 +216,7 @@ private boolean checkIn(String name) {
return true;
}

private boolean checkOut(String name) {
private static boolean checkOut(String name) {
for (String element : validIn) {
if (name.equals(element)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public RitaApi send() throws IOException, GeneralException {
throw new IllegalStateException("Cannot send output object");
}

private boolean checkIn(String name) {
private static boolean checkIn(String name) {
for (String element : validOut) {
if (name.equals(element)) {
return false;
Expand All @@ -213,7 +213,7 @@ private boolean checkIn(String name) {
return true;
}

private boolean checkOut(String name) {
private static boolean checkOut(String name) {
for (String element : validIn) {
if (name.equals(element)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public void calcAndAddTax(GenericValue shipAddress, boolean skipEmptyAddresses)
csi.clearAllTaxInfo();
continue;
}
List<List<? extends Object>> taxReturn = this.getTaxAdjustments(dispatcher, "calcTax", serviceContext);
List<List<? extends Object>> taxReturn = getTaxAdjustments(dispatcher, "calcTax", serviceContext);

if (Debug.verboseOn()) {
Debug.logVerbose("ReturnList: " + taxReturn, module);
Expand Down Expand Up @@ -908,7 +908,8 @@ private Map<String, Object> makeTaxContext(int shipGroup, GenericValue shipAddre
}

// Calc the tax adjustments.
private List<List<? extends Object>> getTaxAdjustments(LocalDispatcher dispatcher, String taxService, Map<String, Object> serviceContext) throws GeneralException {
private static List<List<? extends Object>> getTaxAdjustments(LocalDispatcher dispatcher, String taxService,
Map<String, Object> serviceContext) throws GeneralException {
Map<String, Object> serviceResult = null;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void addOrIncreaseLine(String orderId, String orderItemSeqId, String ship
this.runEvents(PackingEvent.EVENT_CODE_ADD);
}

private BigDecimal numAvailableItems(GenericValue res) {
private static BigDecimal numAvailableItems(GenericValue res) {
// In simple situations, the reserved quantity will match the quantity from the order item.
// If there is a back order, quantity from order may exceed quantity currently reserved and on hand.
// resQty should never exceed the quantity from the order item, because that quantity was the quantity reserved in the first place.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public boolean start() {
*
* @param componentsClassPath a list of classpaths for all components
*/
private void loadClassPathForAllComponents(List<Classpath> componentsClassPath) {
private static void loadClassPathForAllComponents(List<Classpath> componentsClassPath) {
List<URL> allComponentUrls = new ArrayList<>();
for(Classpath classPath : componentsClassPath) {
try {
Expand Down Expand Up @@ -256,7 +256,7 @@ private void loadComponentWithDependency() throws IOException, ComponentExceptio
* @param location directory location of the component
* @return The component configuration
*/
private ComponentConfig retrieveComponentConfig(String name, String location) {
private static ComponentConfig retrieveComponentConfig(String name, String location) {
ComponentConfig config = null;
try {
config = ComponentConfig.getComponentConfig(name, location);
Expand Down Expand Up @@ -331,7 +331,7 @@ private List<ComponentConfig.DependsOnInfo> checkDependencyForComponent(Componen
* @return the constructed classpath
* @throws IOException
*/
private Classpath buildClasspathFromComponentConfig(ComponentConfig config) throws IOException {
private static Classpath buildClasspathFromComponentConfig(ComponentConfig config) throws IOException {
Classpath classPath = new Classpath();
String configRoot = config.getRootLocation().replace('\\', '/');
configRoot = configRoot.endsWith("/") ? configRoot : configRoot + "/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ public synchronized void load(Config config, List<StartupCommand> ofbizCommands)
startLoadedContainers();
}

private Collection<ContainerConfig.Configuration> retrieveOfbizContainers(String configFile) throws StartupException {
private static Collection<ContainerConfig.Configuration> retrieveOfbizContainers(String configFile)
throws StartupException {
try {
return ContainerConfig.getConfigurations(configFile);
} catch (ContainerException e) {
throw new StartupException(e);
}
}

private List<ContainerConfig.Configuration> filterContainersHavingMatchingLoaders(List<String> loaders,
private static List<ContainerConfig.Configuration> filterContainersHavingMatchingLoaders(List<String> loaders,
Collection<ContainerConfig.Configuration> containerConfigs) {
return containerConfigs.stream()
.filter(containerCfg ->
Expand All @@ -99,7 +100,7 @@ private List<ContainerConfig.Configuration> filterContainersHavingMatchingLoader
.collect(Collectors.toList());
}

private List<Container> loadContainersFromConfigurations(List<ContainerConfig.Configuration> containerConfigs,
private static List<Container> loadContainersFromConfigurations(List<ContainerConfig.Configuration> containerConfigs,
Config config, List<StartupCommand> ofbizCommands) throws StartupException {

List<Container> loadContainers = new ArrayList<>();
Expand All @@ -112,8 +113,7 @@ private List<Container> loadContainersFromConfigurations(List<ContainerConfig.Co
return loadContainers;
}

private Container loadContainer(String configFile,
ContainerConfig.Configuration containerCfg,
private static Container loadContainer(String configFile, ContainerConfig.Configuration containerCfg,
List<StartupCommand> ofbizCommands) throws StartupException {
// load the container class
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void setPropertiesParams(String settingsResourceName, String[] propNames)
}
}

private Object fromKey(Object key) {
private static Object fromKey(Object key) {
return key == null ? ObjectType.NULL : key;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void setValue(ELContext context, Object base, Object property, Object val
}
}

private final boolean isResolvable(Object base) {
private final static boolean isResolvable(Object base) {
return base != null && (base instanceof Node || base instanceof NodeImpl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void testQuietly() {
everythingTest();
}

private void everythingTest() {
private static void everythingTest() {
Map<String, Object> testMap = new HashMap<>();
testMap.put("date", new java.util.Date(1234567890));
testMap.put("usd", "USD");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public String getName() {
return name;
}

private Property retrieveTomcatEngineConfig(ContainerConfig.Configuration cc) throws ContainerException {
private static Property retrieveTomcatEngineConfig(ContainerConfig.Configuration cc) throws ContainerException {
List<ContainerConfig.Configuration.Property> engineProps = cc.getPropertiesWithValue("engine");
if (UtilValidate.isEmpty(engineProps)) {
throw new ContainerException("Cannot load CatalinaContainer; no engines defined.");
Expand All @@ -175,7 +175,7 @@ private Property retrieveTomcatEngineConfig(ContainerConfig.Configuration cc) th
return engineProps.get(0);
}

private Tomcat prepareTomcatServer(ContainerConfig.Configuration cc,
private static Tomcat prepareTomcatServer(ContainerConfig.Configuration cc,
ContainerConfig.Configuration.Property engineConfig) throws ContainerException {

System.setProperty(Globals.CATALINA_HOME_PROP, System.getProperty("ofbiz.home") + "/" +
Expand Down Expand Up @@ -205,7 +205,7 @@ private Tomcat prepareTomcatServer(ContainerConfig.Configuration cc,
return tomcat;
}

private Engine prepareTomcatEngine(Tomcat tomcat, Property engineConfig) {
private static Engine prepareTomcatEngine(Tomcat tomcat, Property engineConfig) {
Engine engine = tomcat.getEngine();
engine.setName(engineConfig.name);

Expand All @@ -218,7 +218,7 @@ private Engine prepareTomcatEngine(Tomcat tomcat, Property engineConfig) {
return engine;
}

private Host prepareHost(Tomcat tomcat, List<String> virtualHosts) {
private static Host prepareHost(Tomcat tomcat, List<String> virtualHosts) {
Host host;

if (UtilValidate.isEmpty(virtualHosts)) {
Expand All @@ -240,7 +240,7 @@ private Host prepareHost(Tomcat tomcat, List<String> virtualHosts) {
return host;
}

private Host prepareVirtualHost(Tomcat tomcat, List<String> virtualHosts) {
private static Host prepareVirtualHost(Tomcat tomcat, List<String> virtualHosts) {
// assume that the first virtual-host will be the default; additional virtual-hosts will be aliases
String hostName = virtualHosts.get(0);
Host host;
Expand All @@ -262,7 +262,7 @@ private Host prepareVirtualHost(Tomcat tomcat, List<String> virtualHosts) {
return host;
}

private Property prepareTomcatClustering(Host host, Property engineConfig) throws ContainerException {
private static Property prepareTomcatClustering(Host host, Property engineConfig) throws ContainerException {
Property clusterProp = null;

List<Property> clusterProps = engineConfig.getPropertiesWithValue("cluster");
Expand Down Expand Up @@ -291,7 +291,7 @@ private Property prepareTomcatClustering(Host host, Property engineConfig) throw
return clusterProp;
}

private NioReceiver prepareChannelReceiver(Property clusterProp) throws ContainerException {
private static NioReceiver prepareChannelReceiver(Property clusterProp) throws ContainerException {
NioReceiver listener = new NioReceiver();

String tla = ContainerConfig.getPropertyValue(clusterProp, "tcp-listen-host", "auto");
Expand All @@ -312,7 +312,7 @@ private NioReceiver prepareChannelReceiver(Property clusterProp) throws Containe
return listener;
}

private ReplicationTransmitter prepareChannelSender(Property clusterProp) throws ContainerException {
private static ReplicationTransmitter prepareChannelSender(Property clusterProp) throws ContainerException {
ReplicationTransmitter trans = new ReplicationTransmitter();
try {
MultiPointSender mps = (MultiPointSender)Class.forName(ContainerConfig.getPropertyValue(clusterProp,
Expand All @@ -324,7 +324,7 @@ private ReplicationTransmitter prepareChannelSender(Property clusterProp) throws
return trans;
}

private McastService prepareChannelMcastService(Property clusterProp) throws ContainerException {
private static McastService prepareChannelMcastService(Property clusterProp) throws ContainerException {
McastService mcast = new McastService();

String mcb = ContainerConfig.getPropertyValue(clusterProp, "mcast-bind-addr", null);
Expand All @@ -349,7 +349,7 @@ private McastService prepareChannelMcastService(Property clusterProp) throws Con
return mcast;
}

private ClusterManager prepareClusterManager(Property clusterProp) throws ContainerException {
private static ClusterManager prepareClusterManager(Property clusterProp) throws ContainerException {
String mgrClassName = ContainerConfig.getPropertyValue(clusterProp, "manager-class", "org.apache.catalina.ha.session.DeltaManager");
try {
return (ClusterManager)Class.forName(mgrClassName).getDeclaredConstructor().newInstance();
Expand All @@ -358,14 +358,14 @@ private ClusterManager prepareClusterManager(Property clusterProp) throws Contai
}
}

private ReplicationValve prepareClusterValve(Property clusterProp) {
private static ReplicationValve prepareClusterValve(Property clusterProp) {
ReplicationValve clusterValve = new ReplicationValve();
String defaultValveFilter = ".*\\.gif;.*\\.js;.*\\.jpg;.*\\.htm;.*\\.html;.*\\.txt;.*\\.png;.*\\.css;.*\\.ico;.*\\.htc;";
clusterValve.setFilter(ContainerConfig.getPropertyValue(clusterProp, "rep-valve-filter", defaultValveFilter));
return clusterValve;
}

private List<Valve> prepareTomcatEngineValves(Property engineConfig) throws ContainerException {
private static List<Valve> prepareTomcatEngineValves(Property engineConfig) throws ContainerException {
List<Valve> engineValves = new ArrayList<>();

// configure the CrossSubdomainSessionValve
Expand Down Expand Up @@ -410,7 +410,7 @@ private List<Valve> prepareTomcatEngineValves(Property engineConfig) throws Cont
return engineValves;
}

private List<Connector> prepareTomcatConnectors(Configuration configuration) throws ContainerException {
private static List<Connector> prepareTomcatConnectors(Configuration configuration) throws ContainerException {
List<Property> connectorProps = configuration.getPropertiesWithValue("connector");
if (UtilValidate.isEmpty(connectorProps)) {
throw new ContainerException("Cannot load CatalinaContainer; no connectors defined!");
Expand All @@ -421,7 +421,7 @@ private List<Connector> prepareTomcatConnectors(Configuration configuration) thr
.collect(Collectors.toList());
}

private Connector prepareConnector(Property connectorProp) {
private static Connector prepareConnector(Property connectorProp) {
Connector connector = new Connector(ContainerConfig.getPropertyValue(connectorProp, "protocol", "HTTP/1.1"));
connector.setPort(ContainerConfig.getPropertyValue(connectorProp, "port", 0) + Start.getInstance().getConfig().portOffset);
if ("true".equals(ContainerConfig.getPropertyValue(connectorProp, "upgradeProtocol", "false"))) {
Expand All @@ -445,7 +445,7 @@ private Connector prepareConnector(Property connectorProp) {
return connector;
}

private void loadWebapps(Tomcat tomcat, ContainerConfig.Configuration configuration, Property clusterProp) {
private static void loadWebapps(Tomcat tomcat, ContainerConfig.Configuration configuration, Property clusterProp) {
ScheduledExecutorService executor = ExecutionPool.getScheduledExecutor(new ThreadGroup(module),
"catalina-startup", Runtime.getRuntime().availableProcessors(), 0, true);
List<Future<Context>> futures = new ArrayList<>();
Expand Down Expand Up @@ -473,7 +473,7 @@ private void loadWebapps(Tomcat tomcat, ContainerConfig.Configuration configurat
executor.shutdown();
}

private List<String> getWebappMounts(ComponentConfig.WebappInfo webappInfo) {
private static List<String> getWebappMounts(ComponentConfig.WebappInfo webappInfo) {
List<String> allAppsMounts = new ArrayList<>();
String engineName = webappInfo.server;
String mount = webappInfo.getContextRoot();
Expand All @@ -486,7 +486,7 @@ private List<String> getWebappMounts(ComponentConfig.WebappInfo webappInfo) {
return allAppsMounts;
}

private Callable<Context> createCallableContext(Tomcat tomcat, ComponentConfig.WebappInfo appInfo,
private static Callable<Context> createCallableContext(Tomcat tomcat, ComponentConfig.WebappInfo appInfo,
Property clusterProp, ContainerConfig.Configuration configuration) {

Debug.logInfo("Creating context [" + appInfo.name + "]", module);
Expand All @@ -500,7 +500,7 @@ private Callable<Context> createCallableContext(Tomcat tomcat, ComponentConfig.W
};
}

private StandardContext prepareContext(Host host, ContainerConfig.Configuration configuration,
private static StandardContext prepareContext(Host host, ContainerConfig.Configuration configuration,
ComponentConfig.WebappInfo appInfo, Property clusterProp) throws ContainerException {

StandardContext context = new StandardContext();
Expand Down Expand Up @@ -560,7 +560,7 @@ private StandardContext prepareContext(Host host, ContainerConfig.Configuration
return context;
}

private String getWebappRootLocation(ComponentConfig.WebappInfo appInfo) {
private static String getWebappRootLocation(ComponentConfig.WebappInfo appInfo) {
String location = appInfo.componentConfig.getRootLocation() + appInfo.location;
location = location.replace('\\', '/');
if (location.endsWith("/")) {
Expand All @@ -569,15 +569,16 @@ private String getWebappRootLocation(ComponentConfig.WebappInfo appInfo) {
return location;
}

private String getWebappMountPoint(ComponentConfig.WebappInfo appInfo) {
private static String getWebappMountPoint(ComponentConfig.WebappInfo appInfo) {
String mount = appInfo.mountPoint;
if (mount.endsWith("/*")) {
mount = mount.substring(0, mount.length() - 2);
}
return mount;
}

private boolean isContextDistributable(ContainerConfig.Configuration configuration, String location) throws ContainerException {
private static boolean isContextDistributable(ContainerConfig.Configuration configuration, String location)
throws ContainerException {
String webXmlFilePath = new StringBuilder().append("file:///").append(location).append("/WEB-INF/web.xml").toString();
boolean appIsDistributable = ContainerConfig.getPropertyValue(configuration, "apps-distributable", true);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public PerformFindTests(String name) {
super(name);
}

private List<GenericValue> getCompleteList(Map<String, Object> context) {
private static List<GenericValue> getCompleteList(Map<String, Object> context) {
List<GenericValue> foundElements = new LinkedList<>();
try (EntityListIterator listIt = (EntityListIterator) context.get("listIt")) {
if (listIt != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ModelDataFileReader(URL readerURL) throws DataFileException {
this.modelDataFiles = Collections.unmodifiableMap(createModelDataFiles());
}

private ModelDataFile createModelDataFile(Element dataFileElement) {
private static ModelDataFile createModelDataFile(Element dataFileElement) {
ModelDataFile dataFile = new ModelDataFile();
String tempStr;

Expand Down Expand Up @@ -163,7 +163,7 @@ private Map<String, ModelDataFile> createModelDataFiles() throws DataFileExcepti
return result;
}

private ModelField createModelField(Element fieldElement) {
private static ModelField createModelField(Element fieldElement) {
ModelField field = new ModelField();
String tempStr;

Expand Down Expand Up @@ -203,7 +203,7 @@ private ModelField createModelField(Element fieldElement) {
return field;
}

private ModelRecord createModelRecord(Element recordElement) {
private static ModelRecord createModelRecord(Element recordElement) {
ModelRecord record = new ModelRecord();
String tempStr;

Expand Down
Loading

0 comments on commit ffe2e7f

Please sign in to comment.