diff --git a/src/main/java/org/jreliability/bdd/BDDs.java b/src/main/java/org/jreliability/bdd/BDDs.java index cd3f83d..e3daa46 100644 --- a/src/main/java/org/jreliability/bdd/BDDs.java +++ b/src/main/java/org/jreliability/bdd/BDDs.java @@ -40,7 +40,7 @@ public abstract class BDDs { /** * The platform-independent newline symbol. */ - protected static String newline = System.getProperty("line.separator"); + protected static final String newline = System.getProperty("line.separator"); /** * Returns all variables (elements) {@code T} included in the {@code BDD}. @@ -89,6 +89,8 @@ public static Set> getNodes(T t, BDD bdd) { * the comparator ("<","<=","=",">=",">") * @param rhs * the right hand side value + * @param provider + * the bdd provider * @return the BDD representing this linear constraint */ public static BDD getBDD(List coeffs, List> vars, LinearTerm.Comparator comp, int rhs, @@ -115,8 +117,8 @@ public static BDD getBDD(List coeffs, List> vars, LinearT BDDConstraint constraint = new BDDConstraint<>(rhs, lits); /* - * Handle the case that the lhs is empty and is, thus, 0! If 0 >= - * rhs, return true BDD; else return false BDD + * Handle the case that the lhs is empty and is, thus, 0! If 0 >= rhs, return true BDD; else return false + * BDD */ if (constraint.getLhs().isEmpty()) { if (0 >= constraint.getRhs()) { @@ -147,6 +149,8 @@ public static BDD getBDD(List coeffs, List> vars, LinearT * the type of variables * @param constraint * the greater-equal constraint + * @param provider + * the bdd provider * @return the bdd representation of the given constraint */ protected static BDD getConstraintBDD(BDDConstraint constraint, BDDProvider provider) { @@ -172,8 +176,7 @@ public int compare(Literal o1, Literal o2) { } /** - * Returns a graphical representation of the {@code BDD} in the {@code DOT} - * input format. + * Returns a graphical representation of the {@code BDD} in the {@code DOT} input format. * * @param * the type of variable @@ -201,9 +204,8 @@ public static String toDot(BDD bdd) { } /** - * Calculates the top event of the {@code BDD} based on a - * functionTransformer that delivers for each variable {@code T} a double - * value. + * Calculates the top event of the {@code BDD} based on a functionTransformer that delivers for each variable + * {@code T} a double value. * * @param * the type of variable @@ -318,8 +320,8 @@ protected static double evaluate(BDD bdd, Transformer transfor } /** - * Returns a {@code greater-equal} constraint represented as a {@code BDD} - * via a recursive procedure proposed by {@code Een & Soerrensson 2006}. + * Returns a {@code greater-equal} constraint represented as a {@code BDD} via a recursive procedure proposed by + * {@code Een & Soerrensson 2006}. * * @param * the type of variables @@ -365,8 +367,7 @@ protected static BDD buildConstraintBDD(List> literals, int rh } /** - * Traverses the {@code BDD} to collects all nodes for the {@code DOT} - * representation. + * Traverses the {@code BDD} to collects all nodes for the {@code DOT} representation. * * @param * the type of variables @@ -385,14 +386,14 @@ protected static void collectDotNodes(BDD bdd, StringBuffer dot, Map void collectDotNodes(BDD bdd, StringBuffer dot, Map * the type of variable @@ -439,8 +439,10 @@ protected static void collectDotEdges(BDD bdd, StringBuffer dot, Map " + highVariable + " [style = solid, arrowsize = 0.8];" + newline); - dot.append(variable + " -> " + lowVariable + " [style = dashed, arrowsize = 0.8];" + newline); + dot.append(variable).append(" -> ").append(highVariable).append(" [style = solid, arrowsize = 0.8];") + .append(newline); + dot.append(variable).append(" -> ").append(lowVariable).append(" [style = dashed, arrowsize = 0.8];") + .append(newline); considered.add(bdd); @@ -449,8 +451,7 @@ protected static void collectDotEdges(BDD bdd, StringBuffer dot, Map * the type of variable @@ -471,7 +472,8 @@ protected static void collectDotMarkers(BDD bdd, StringBuffer dot, Map void collectDotMarkers(BDD bdd, StringBuffer dot, Map " + nextVariable + " [style = invis];" + newline); + dot.append(currentVariable).append(" -> ").append(nextVariable).append(" [style = invis];").append(newline); current = next; } } /** - * Traverses the {@code BDD} to setup the correct ranks of all nodes - * belonging to the same variable. + * Traverses the {@code BDD} to setup the correct ranks of all nodes belonging to the same variable. * * @param * the type of variable @@ -511,14 +512,13 @@ protected static void collectDotRanks(BDD bdd, StringBuffer dot, Map> nodes = getNodes(t, bdd); - String tmpDot = "{ rank = same; " + variable + "; "; + dot.append("{ rank = same; ").append(variable).append("; "); for (BDD nodeBDD : nodes) { String nodeVariable = variables.get(nodeBDD); - tmpDot += nodeVariable + "; "; + dot.append(nodeVariable).append("; "); } - tmpDot += "}" + newline; - dot.append(tmpDot); + dot.append("}").append(newline); } } @@ -555,8 +555,7 @@ protected static void collectVariables(BDD bdd, Set variables, Set * the type of variables @@ -583,8 +582,7 @@ protected static void collectVariablesSorted(BDD bdd, List variables) } /** - * Traverses the {@code BDD} to collect all nodes for a given variable - * {@code T}. + * Traverses the {@code BDD} to collect all nodes for a given variable {@code T}. * * @param * the type of variables diff --git a/src/main/java/org/jreliability/bdd/javabdd/JBDDProvider.java b/src/main/java/org/jreliability/bdd/javabdd/JBDDProvider.java index c451e41..17c16f0 100644 --- a/src/main/java/org/jreliability/bdd/javabdd/JBDDProvider.java +++ b/src/main/java/org/jreliability/bdd/javabdd/JBDDProvider.java @@ -38,10 +38,7 @@ public class JBDDProvider implements BDDProvider { * The offset of the variables. */ protected int variableOffset = 0; - /** - * The used {@code Type} of real {@code BDD} implementation. - */ - protected Type type; + /** * The used {@code BDDFactory}. */ @@ -69,8 +66,6 @@ public class JBDDProvider implements BDDProvider { * the number of variables */ public JBDDProvider(Type type, int vars) { - this.type = type; - switch (type) { case JDD: factory = JDDFactory.init(200000, 200000); diff --git a/src/main/java/org/jreliability/bdd/javabdd/JBDDProviderFactory.java b/src/main/java/org/jreliability/bdd/javabdd/JBDDProviderFactory.java index 5584ff9..8cc4f17 100644 --- a/src/main/java/org/jreliability/bdd/javabdd/JBDDProviderFactory.java +++ b/src/main/java/org/jreliability/bdd/javabdd/JBDDProviderFactory.java @@ -50,7 +50,7 @@ public enum Type { /** * The number of initially allocated variables. */ - protected static int INITIAL_VARIABLES = 10; + protected static final int INITIAL_VARIABLES = 10; /** * A map that provides each requested {@code Type} of real {@code BDD} implementation with its specific * {@code JBDDProvider}. diff --git a/src/main/java/org/jreliability/evaluator/MomentEvaluator.java b/src/main/java/org/jreliability/evaluator/MomentEvaluator.java index 051fc5d..5cf3076 100644 --- a/src/main/java/org/jreliability/evaluator/MomentEvaluator.java +++ b/src/main/java/org/jreliability/evaluator/MomentEvaluator.java @@ -1,16 +1,14 @@ /** - * JReliability is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. + * JReliability is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General + * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. * - * JReliability is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. + * JReliability is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. * - * You should have received a copy of the GNU Lesser General Public - * License along with Opt4J. If not, see http://www.gnu.org/licenses/. + * You should have received a copy of the GNU Lesser General Public License along with Opt4J. If not, see + * http://www.gnu.org/licenses/. */ package org.jreliability.evaluator; @@ -18,15 +16,14 @@ import org.jreliability.function.ReliabilityFunction; /** - * The {@code MomentEvaluator} determines the {@code n}-th {@code Moment} of a - * density function {@code f(x)} given a {@code ReliabilityFunction} {@code + * The {@code MomentEvaluator} determines the {@code n}-th {@code Moment} of a density function {@code f(x)} given a + * {@code ReliabilityFunction} {@code * R(x)}. *

* E(X^n)={@code integral_0^infinity x^n f(x) dx}. *

- * It performs an integration from {@code 0} to {@code infinity} using Rombergs - * integration. This is commonly used to derived measures like, e.g., Mean Time - * To Failure (MTTF) (E(X)) and its variance (E(X^2)-E(X)^2). + * It performs an integration from {@code 0} to {@code infinity} using Rombergs integration. This is commonly used to + * derived measures like, e.g., Mean Time To Failure (MTTF) (E(X)) and its variance (E(X^2)-E(X)^2). * * @author glass, lukasiewycz * @@ -39,7 +36,7 @@ public class MomentEvaluator implements Evaluator { * @author lukasiewycz * */ - class MomentFunction implements Function { + static class MomentFunction implements Function { private ReliabilityFunction reliabilityFunction; private int n; @@ -62,6 +59,7 @@ public MomentFunction(ReliabilityFunction reliabilityFunction, int n) { * * @see org.jreliability.function.Function#getY(double) */ + @Override public double getY(double x) { return n * Math.pow(x, n - 1) * reliabilityFunction.getY(x); } @@ -79,8 +77,8 @@ public double getY(double x) { protected final int n; /** - * Constructs a {@code MomentEvaluator} for the given {@code n}-th moment - * and a maximum error / {@code epsilon} of {@code 1.0E-5}. + * Constructs a {@code MomentEvaluator} for the given {@code n}-th moment and a maximum error / {@code epsilon} of + * {@code 1.0E-5}. * * @param n * the n value @@ -90,8 +88,7 @@ public MomentEvaluator(int n) { } /** - * Constructs a {@code MomentEvaluator} for the given {@code n}-th moment - * and a maximum error {@code epsilon}. + * Constructs a {@code MomentEvaluator} for the given {@code n}-th moment and a maximum error {@code epsilon}. * * @param n * the n value @@ -105,8 +102,7 @@ public MomentEvaluator(int n, double epsilon) { this.n = n; this.epsilon = epsilon; if (n < 1) { - throw new IllegalArgumentException( - "An n-th moment with n < 1 is undefined."); + throw new IllegalArgumentException("An n-th moment with n < 1 is undefined."); } } @@ -125,13 +121,11 @@ public double evaluate(ReliabilityFunction reliabilityFunction) { } /** - * Returns the calculated upper bound that will be used in the integration - * process. + * Returns the calculated upper bound that will be used in the integration process. * * @param reliabilityFunction * the reliabilityFunction - * @return the calculated upper bound that will be used in the integration - * process + * @return the calculated upper bound that will be used in the integration process */ public double getUpperBound(ReliabilityFunction reliabilityFunction) { double upperBound = 0.5; @@ -159,8 +153,7 @@ public double getUpperBound(ReliabilityFunction reliabilityFunction) { * the upper bound * @return the value of the integral between a and b */ - protected double integrate(ReliabilityFunction reliabilityFunction, - double a, double b) { + protected double integrate(ReliabilityFunction reliabilityFunction, double a, double b) { Function f = new MomentFunction(reliabilityFunction, n); IntegralEvaluator integral = new IntegralEvaluator(epsilon); diff --git a/src/main/java/org/jreliability/gui/MeasuresPanel.java b/src/main/java/org/jreliability/gui/MeasuresPanel.java index c884b30..ccac60d 100644 --- a/src/main/java/org/jreliability/gui/MeasuresPanel.java +++ b/src/main/java/org/jreliability/gui/MeasuresPanel.java @@ -1,16 +1,14 @@ /** - * JReliability is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. + * JReliability is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General + * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any + * later version. * - * JReliability is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. + * JReliability is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. * - * You should have received a copy of the GNU Lesser General Public - * License along with Opt4J. If not, see http://www.gnu.org/licenses/. + * You should have received a copy of the GNU Lesser General Public License along with Opt4J. If not, see + * http://www.gnu.org/licenses/. */ package org.jreliability.gui; @@ -24,8 +22,8 @@ import java.text.NumberFormat; import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import javax.swing.BorderFactory; import javax.swing.JComponent; @@ -41,8 +39,7 @@ /** * The {@code MeasuresPanel2} collects a {@code MeasurePanel} for each {@code - * ReliabilityFunction} that shall be shown in the GUI and adds them to a - * {@code JTabbedPane}. + * ReliabilityFunction} that shall be shown in the GUI and adds them to a {@code JTabbedPane}. * * @author glass * @@ -82,45 +79,40 @@ public MeasuresPanel(Map reliabilityFunctions) { */ protected void initialize() { tabs = new JTabbedPane(); - for (Entry entry : reliabilityFunctions - .entrySet()) { + for (Entry entry : reliabilityFunctions.entrySet()) { String name = entry.getKey(); ReliabilityFunction function = entry.getValue(); MeasurePanel measurePanel = new MeasurePanel(function); tabs.addTab(name, measurePanel); } this.add(tabs); - this.setBorder(BorderFactory.createCompoundBorder(BorderFactory - .createTitledBorder("Reliability-related Measures"), - BorderFactory.createEmptyBorder(5, 0, 0, 0))); + this.setBorder( + BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Reliability-related Measures"), + BorderFactory.createEmptyBorder(5, 0, 0, 0))); } /** - * The {@code MeasurePanel} shows some common reliability-related measures - * that are derived from the {@code ReliabilityFunctions}. Currently, these - * are related directly to the {@code ReliabilityFunction}, i.e., the - * expected value, the variance, and the standard deviation, as well as some - * familiar reliability measures like Mean-Time-To-Failure and Mission-Time. + * The {@code MeasurePanel} shows some common reliability-related measures that are derived from the + * {@code ReliabilityFunctions}. Currently, these are related directly to the {@code ReliabilityFunction}, i.e., the + * expected value, the variance, and the standard deviation, as well as some familiar reliability measures like + * Mean-Time-To-Failure and Mission-Time. * * @author glass * */ - protected class MeasurePanel extends JPanel implements ActionListener { + protected static class MeasurePanel extends JPanel implements ActionListener { /** - * The {@code Evaluator} to determine the first moment, i.e., the - * expected value. + * The {@code Evaluator} to determine the first moment, i.e., the expected value. */ protected MomentEvaluator firstMoment = new MomentEvaluator(1); /** - * The {@code Evaluator} to determine the second moment, used to derive - * the variance and deviation. + * The {@code Evaluator} to determine the second moment, used to derive the variance and deviation. */ protected MomentEvaluator secondMoment = new MomentEvaluator(2); /** * The {@code Evaluator} to calculate the inverse of the {@code - * Distribution} of the {@code ReliabilityFunction}, used to derive the - * Mission-Time. + * Distribution} of the {@code ReliabilityFunction}, used to derive the Mission-Time. */ protected InverseEvaluator inverse = new InverseEvaluator(); /** @@ -128,8 +120,8 @@ protected class MeasurePanel extends JPanel implements ActionListener { */ protected final ReliabilityFunction reliabilityFunction; /** - * The {code JLabel} that is used to display the Mission-Time {@code MT} - * for the user specified probability {@code p} in {@code p = P[MT]}. + * The {code JLabel} that is used to display the Mission-Time {@code MT} for the user specified probability + * {@code p} in {@code p = P[MT]}. */ protected JLabel mt; /** @@ -137,8 +129,7 @@ protected class MeasurePanel extends JPanel implements ActionListener { */ protected JFormattedTextField mtProbability; /** - * The used {@code NumberFormat} for the {@code mtProbability} text - * field. + * The used {@code NumberFormat} for the {@code mtProbability} text field. */ protected NumberFormat mtFieldFormat; /** @@ -178,10 +169,8 @@ private void initialize() { Double expected = firstMoment.evaluate(reliabilityFunction); JLabel expectedLabel = new JLabel("Expected Value:"); - JPanel propertiesPanel = createPropertiesPanel(expected, - expectedLabel); - JPanel mttfPanel = createMttfPanel(expected, expectedLabel - .getPreferredSize()); + JPanel propertiesPanel = createPropertiesPanel(expected, expectedLabel); + JPanel mttfPanel = createMttfPanel(expected, expectedLabel.getPreferredSize()); JPanel mtPanel = createMtPanel(expectedLabel.getPreferredSize()); this.add(propertiesPanel); @@ -195,10 +184,9 @@ private void initialize() { /* * (non-Javadoc) * - * @see - * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent - * ) + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent ) */ + @Override public void actionPerformed(ActionEvent e) { Double value = ((Number) mtProbability.getValue()).doubleValue(); if (value <= 0 || value >= 1.0) { @@ -218,10 +206,8 @@ public void actionPerformed(ActionEvent e) { * the "expected" label, i.e. the longest * @return the JPanel showing the properties */ - private JPanel createPropertiesPanel(Double expected, - JLabel expectedLabel) { - Double variance = secondMoment.evaluate(reliabilityFunction) - - Math.pow(expected, 2); + private JPanel createPropertiesPanel(Double expected, JLabel expectedLabel) { + Double variance = secondMoment.evaluate(reliabilityFunction) - Math.pow(expected, 2); Double deviation = Math.sqrt(variance); JLabel expectedValue = new JLabel(expected.toString()); @@ -232,9 +218,8 @@ private JPanel createPropertiesPanel(Double expected, JLabel deviationLabel = new JLabel("Deviation:"); JLabel deviationValue = new JLabel(deviation.toString()); - return createSubPanel("Properties", expectedLabel, expectedValue, - varianceLabel, varianceValue, deviationLabel, - deviationValue); + return createSubPanel("Properties", expectedLabel, expectedValue, varianceLabel, varianceValue, + deviationLabel, deviationValue); } /** @@ -252,8 +237,7 @@ private JPanel createMttfPanel(Double mttf, Dimension maxWidth) { JLabel expectedValue = new JLabel(mttf.toString()); - return createSubPanel("Mean-Time-To-Failure", mttfLabel, - expectedValue); + return createSubPanel("Mean-Time-To-Failure", mttfLabel, expectedValue); } /** @@ -280,35 +264,29 @@ private JPanel createMtPanel(Dimension maxwidth) { mt = new JLabel(mtVal.toString()); - return createSubPanel("Mission-Time", pmtLabel, mtProbability, - mtLabel, mt); + return createSubPanel("Mission-Time", pmtLabel, mtProbability, mtLabel, mt); } /** * Creates a {@code JPanel} with a title and a set of label/value pairs. * - * Each label must be followed by its corresponding value. Therefore the - * number of components must be even. + * Each label must be followed by its corresponding value. Therefore the number of components must be even. * * @param title * the title of the panel * @param components - * the alternating array of labels and their corresponding - * values + * the alternating array of labels and their corresponding values * @return */ private JPanel createSubPanel(String title, JComponent... components) { if (components.length % 2 == 1) { - throw new IllegalArgumentException( - "Number of components is odd (" + components.length - + ")."); + throw new IllegalArgumentException("Number of components is odd (" + components.length + ")."); } JPanel subPanel = new JPanel(); - subPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory - .createTitledBorder(title), BorderFactory - .createEmptyBorder(5, 5, 5, 5))); + subPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(title), + BorderFactory.createEmptyBorder(5, 5, 5, 5))); subPanel.setLayout(new GridLayout(0, 2, 10, 10)); @@ -326,14 +304,12 @@ private JPanel createSubPanel(String title, JComponent... components) { if (subPanel.getPreferredSize().width > LARGEStWIDTH) { LARGEStWIDTH = subPanel.getPreferredSize().width; for (JPanel other : SUBPANELS) { - other.setPreferredSize(new Dimension(LARGEStWIDTH, other - .getPreferredSize().height)); + other.setPreferredSize(new Dimension(LARGEStWIDTH, other.getPreferredSize().height)); other.revalidate(); other.repaint(); } } else { - subPanel.setPreferredSize(new Dimension(LARGEStWIDTH, subPanel - .getPreferredSize().height)); + subPanel.setPreferredSize(new Dimension(LARGEStWIDTH, subPanel.getPreferredSize().height)); } SUBPANELS.add(subPanel); return subPanel; @@ -347,5 +323,5 @@ private JPanel createSubPanel(String title, JComponent... components) { /** * The set of subpanels */ - private final static Set SUBPANELS = new HashSet(); + private final static Set SUBPANELS = new HashSet<>(); }