Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix IDEA warnings "Unnecessary boxing" #198

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ public final class CSSName implements Comparable {
/**
* marker var, used for initialization
*/
private static final Integer PRIMITIVE = new Integer(0);
private static final Integer PRIMITIVE = 0;

/**
* marker var, used for initialization
*/
private static final Integer SHORTHAND = new Integer(1);
private static final Integer SHORTHAND = 1;

/**
* marker var, used for initialization
*/
private static final Integer INHERITS = new Integer(2);
private static final Integer INHERITS = 2;

/**
* marker var, used for initialization
*/
private static final Integer NOT_INHERITED = new Integer(3);
private static final Integer NOT_INHERITED = 3;

/**
* Used to assing unique int id values to new CSSNames created in this class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static short sacPrimitiveTypeForString(String type) {
* @return Returns
*/
public static String stringForSACPrimitiveType(short type) {
return (String) sacTypesStrings.get(new Short(type));
return (String) sacTypesStrings.get(type);
}

/**
Expand All @@ -122,7 +122,7 @@ public static String stringForSACPrimitiveType(short type) {
*/
//TODO: method may be unnecessary (tobe)
public static boolean isAbsoluteUnit(CSSPrimitiveValue primitive) {
short type = ((CSSPrimitiveValue) primitive).getPrimitiveType();
short type = primitive.getPrimitiveType();
return isAbsoluteUnit(type);
}

Expand Down Expand Up @@ -289,15 +289,15 @@ public static boolean isNumber(short cssPrimitiveType) {

// HACK: this is a quick way to perform the lookup, but dumb if the short assigned are > 100; but the compiler will tell us that (PWW 21-01-05)
sacTypesStrings = new HashMap(25);
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_EMS), "em");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_EXS), "ex");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_PX), "px");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_PERCENTAGE), "%");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_IN), "in");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_CM), "cm");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_MM), "mm");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_PT), "pt");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_PC), "pc");
sacTypesStrings.put(CSSPrimitiveValue.CSS_EMS, "em");
sacTypesStrings.put(CSSPrimitiveValue.CSS_EXS, "ex");
sacTypesStrings.put(CSSPrimitiveValue.CSS_PX, "px");
sacTypesStrings.put(CSSPrimitiveValue.CSS_PERCENTAGE, "%");
sacTypesStrings.put(CSSPrimitiveValue.CSS_IN, "in");
sacTypesStrings.put(CSSPrimitiveValue.CSS_CM, "cm");
sacTypesStrings.put(CSSPrimitiveValue.CSS_MM, "mm");
sacTypesStrings.put(CSSPrimitiveValue.CSS_PT, "pt");
sacTypesStrings.put(CSSPrimitiveValue.CSS_PC, "pc");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ public class Conversions {
}

static {
NUMERIC_FONT_WEIGHTS.put(new Float(100f), IdentValue.FONT_WEIGHT_100);
NUMERIC_FONT_WEIGHTS.put(new Float(200f), IdentValue.FONT_WEIGHT_200);
NUMERIC_FONT_WEIGHTS.put(new Float(300f), IdentValue.FONT_WEIGHT_300);
NUMERIC_FONT_WEIGHTS.put(new Float(400f), IdentValue.FONT_WEIGHT_400);
NUMERIC_FONT_WEIGHTS.put(new Float(500f), IdentValue.FONT_WEIGHT_500);
NUMERIC_FONT_WEIGHTS.put(new Float(600f), IdentValue.FONT_WEIGHT_600);
NUMERIC_FONT_WEIGHTS.put(new Float(700f), IdentValue.FONT_WEIGHT_700);
NUMERIC_FONT_WEIGHTS.put(new Float(800f), IdentValue.FONT_WEIGHT_800);
NUMERIC_FONT_WEIGHTS.put(new Float(900f), IdentValue.FONT_WEIGHT_900);
NUMERIC_FONT_WEIGHTS.put(100f, IdentValue.FONT_WEIGHT_100);
NUMERIC_FONT_WEIGHTS.put(200f, IdentValue.FONT_WEIGHT_200);
NUMERIC_FONT_WEIGHTS.put(300f, IdentValue.FONT_WEIGHT_300);
NUMERIC_FONT_WEIGHTS.put(400f, IdentValue.FONT_WEIGHT_400);
NUMERIC_FONT_WEIGHTS.put(500f, IdentValue.FONT_WEIGHT_500);
NUMERIC_FONT_WEIGHTS.put(600f, IdentValue.FONT_WEIGHT_600);
NUMERIC_FONT_WEIGHTS.put(700f, IdentValue.FONT_WEIGHT_700);
NUMERIC_FONT_WEIGHTS.put(800f, IdentValue.FONT_WEIGHT_800);
NUMERIC_FONT_WEIGHTS.put(900f, IdentValue.FONT_WEIGHT_900);
}

static {
Expand All @@ -198,7 +198,7 @@ public static FSRGBColor getColor(String ident) {
}

public static IdentValue getNumericFontWeight(float weight) {
return (IdentValue)NUMERIC_FONT_WEIGHTS.get(new Float(weight));
return (IdentValue)NUMERIC_FONT_WEIGHTS.get(weight);
}

public static PropertyValue getBorderWidth(String ident) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ private static void createChildren(
Node startAttribute = working.getAttributes().getNamedItem("start");
if (startAttribute != null) {
try {
start = new Integer(Integer.parseInt(startAttribute.getNodeValue()) - 1);
start = Integer.parseInt(startAttribute.getNodeValue()) - 1;
} catch (NumberFormatException e) {
// ignore
}
Expand All @@ -1112,7 +1112,7 @@ private static void createChildren(
Node valueAttribute = working.getAttributes().getNamedItem("value");
if (valueAttribute != null) {
try {
start = new Integer(Integer.parseInt(valueAttribute.getNodeValue()) - 1);
start = Integer.parseInt(valueAttribute.getNodeValue()) - 1;
} catch (NumberFormatException e) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* {@link SharedContext}.
*/
public class LayoutContext implements CssContext {
private SharedContext _sharedContext;
private final SharedContext _sharedContext;

private Layer _rootLayer;

Expand All @@ -67,12 +67,12 @@ public class LayoutContext implements CssContext {

private FontContext _fontContext;

private ContentFunctionFactory _contentFunctionFactory = new ContentFunctionFactory();
private final ContentFunctionFactory _contentFunctionFactory = new ContentFunctionFactory();

private int _extraSpaceTop;
private int _extraSpaceBottom;

private Map _counterContextMap = new HashMap();
private final Map _counterContextMap = new HashMap();

private String _pendingPageName;
private String _pageName;
Expand Down Expand Up @@ -419,7 +419,7 @@ private boolean incrementCounter(CounterData cd) {
if (_parent == null) return false;
return _parent.incrementCounter(cd);
} else {
_counters.put(cd.getName(), new Integer(currentValue.intValue() + cd.getValue()));
_counters.put(cd.getName(), currentValue + cd.getValue());
return true;
}
}
Expand All @@ -428,13 +428,13 @@ private boolean incrementCounter(CounterData cd) {
private void incrementListItemCounter(int increment) {
Integer currentValue = (Integer) _counters.get("list-item");
if (currentValue == null) {
currentValue = new Integer(0);
currentValue = 0;
}
_counters.put("list-item", new Integer(currentValue.intValue() + increment));
_counters.put("list-item", currentValue + increment);
}

private void resetCounter(CounterData cd) {
_counters.put(cd.getName(), new Integer(cd.getValue()));
_counters.put(cd.getName(), cd.getValue());
}

public int getCurrentCounterValue(String name) {
Expand All @@ -445,7 +445,7 @@ public int getCurrentCounterValue(String name) {
_parent.resetCounter(new CounterData(name, 0));
return 0;
} else {
return value.intValue();
return value;
}
}

Expand All @@ -463,7 +463,7 @@ public List getCurrentCounterValues(String name) {
_parent.getCounterValues(name, values);
if (values.size() == 0) {
_parent.resetCounter(new CounterData(name, 0));
values.add(new Integer(0));
values.add(0);
}
return values;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ protected void applyComponentStyle(JButton button) {

FSDerivedValue widthValue = style.valueByName(CSSName.WIDTH);
if (widthValue instanceof LengthValue)
intrinsicWidth = new Integer(getBox().getContentWidth());
intrinsicWidth = getBox().getContentWidth();

FSDerivedValue heightValue = style.valueByName(CSSName.HEIGHT);
if (heightValue instanceof LengthValue)
intrinsicHeight = new Integer(getBox().getHeight());
intrinsicHeight = getBox().getHeight();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
import java.awt.*;

public abstract class FormField {
private XhtmlForm _parentForm;
private Element _element;
private final XhtmlForm _parentForm;
private final Element _element;
private FormFieldState _originalState;
private JComponent _component;
private LayoutContext context;
private BlockBox box;
private final LayoutContext context;
private final BlockBox box;
protected Integer intrinsicWidth;
protected Integer intrinsicHeight;

Expand Down Expand Up @@ -108,9 +108,9 @@ private void initialize() {

if (_component != null) {
if (intrinsicWidth == null)
intrinsicWidth = new Integer(_component.getPreferredSize().width);
intrinsicWidth = _component.getPreferredSize().width;
if (intrinsicHeight == null)
intrinsicHeight = new Integer(_component.getPreferredSize().height);
intrinsicHeight = _component.getPreferredSize().height;

_component.setSize(getIntrinsicSize());

Expand Down Expand Up @@ -219,7 +219,7 @@ public Font getFont() {
protected static Integer getLengthValue(CalculatedStyle style, CSSName cssName) {
FSDerivedValue widthValue = style.valueByName(cssName);
if (widthValue instanceof LengthValue) {
return new Integer((int)widthValue.asFloat());
return (int) widthValue.asFloat();
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@
package org.xhtmlrenderer.simple.extend.form;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.*;
import javax.swing.plaf.basic.BasicButtonUI;

import org.w3c.dom.Element;
Expand Down Expand Up @@ -83,20 +78,17 @@ public Dimension getPreferredSize() {

FSDerivedValue widthValue = style.valueByName(CSSName.WIDTH);
if (widthValue instanceof LengthValue) {
intrinsicWidth = new Integer(getBox().getContentWidth());
intrinsicWidth = getBox().getContentWidth();
}

FSDerivedValue heightValue = style.valueByName(CSSName.HEIGHT);
if (heightValue instanceof LengthValue) {
intrinsicHeight = new Integer(getBox().getHeight());
intrinsicHeight = getBox().getHeight();
}

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
XRLog.layout("Image pressed: Submit");

getParentForm().submit(getComponent());
}
button.addActionListener(event -> {
XRLog.layout("Image pressed: Submit");
getParentForm().submit(getComponent());
});

return button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected FormFieldState loadOriginalState() {
Element option = (Element) options.item(i);

if (option.hasAttribute("selected") && option.getAttribute("selected").equalsIgnoreCase("selected")) {
list.add(new Integer(i));
list.add(i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
*/
package org.xhtmlrenderer.simple.extend.form;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import java.awt.*;

import javax.swing.*;
import javax.swing.plaf.basic.BasicTextAreaUI;
import javax.swing.plaf.basic.BasicTextUI;

Expand All @@ -38,8 +37,6 @@
import org.xhtmlrenderer.simple.extend.XhtmlForm;
import org.xhtmlrenderer.util.GeneralUtil;

import java.awt.*;

class TextAreaField extends FormField {
private TextAreaFieldJTextArea _textarea;

Expand Down Expand Up @@ -95,10 +92,10 @@ protected void applyComponentStyle(TextAreaFieldJTextArea textArea, JScrollPane
Integer paddingBottom = getLengthValue(style, CSSName.PADDING_BOTTOM);
Integer paddingRight = getLengthValue(style, CSSName.PADDING_RIGHT);

int top = paddingTop == null ? 2 : Math.max(2, paddingTop.intValue());
int left = paddingLeft == null ? 3 : Math.max(3, paddingLeft.intValue());
int bottom = paddingBottom == null ? 2 : Math.max(2, paddingBottom.intValue());
int right = paddingRight == null ? 3 : Math.max(3, paddingRight.intValue());
int top = paddingTop == null ? 2 : Math.max(2, paddingTop);
int left = paddingLeft == null ? 3 : Math.max(3, paddingLeft);
int bottom = paddingBottom == null ? 2 : Math.max(2, paddingBottom);
int right = paddingRight == null ? 3 : Math.max(3, paddingRight);

//if a border is set or a background color is set, then use a special JButton with the BasicButtonUI.
if (disableOSBorder) {
Expand All @@ -117,12 +114,12 @@ protected void applyComponentStyle(TextAreaFieldJTextArea textArea, JScrollPane

FSDerivedValue widthValue = style.valueByName(CSSName.WIDTH);
if (widthValue instanceof LengthValue) {
intrinsicWidth = new Integer(getBox().getContentWidth() + left + right);
intrinsicWidth = getBox().getContentWidth() + left + right;
}

FSDerivedValue heightValue = style.valueByName(CSSName.HEIGHT);
if (heightValue instanceof LengthValue) {
intrinsicHeight = new Integer(getBox().getHeight() + top + bottom);
intrinsicHeight = getBox().getHeight() + top + bottom;
}
}

Expand All @@ -145,7 +142,7 @@ protected String[] getFieldValues() {
}


private class TextAreaFieldJTextArea extends JTextArea {
private static class TextAreaFieldJTextArea extends JTextArea {
int columnWidth = 0;

public TextAreaFieldJTextArea(int rows, int columns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ protected void applyComponentStyle(JComponent component) {
Integer paddingRight = getLengthValue(style, CSSName.PADDING_RIGHT);


int top = paddingTop == null ? 2 : Math.max(2, paddingTop.intValue());
int left = paddingLeft == null ? 3 : Math.max(3, paddingLeft.intValue());
int bottom = paddingBottom == null ? 2 : Math.max(2, paddingBottom.intValue());
int right = paddingRight == null ? 3 : Math.max(3, paddingRight.intValue());
int top = paddingTop == null ? 2 : Math.max(2, paddingTop);
int left = paddingLeft == null ? 3 : Math.max(3, paddingLeft);
int bottom = paddingBottom == null ? 2 : Math.max(2, paddingBottom);
int right = paddingRight == null ? 3 : Math.max(3, paddingRight);

//if a border is set or a background color is set, then use a special JButton with the BasicButtonUI.
if (disableOSBorder) {
Expand All @@ -116,12 +116,12 @@ protected void applyComponentStyle(JComponent component) {

FSDerivedValue widthValue = style.valueByName(CSSName.WIDTH);
if (widthValue instanceof LengthValue) {
intrinsicWidth = new Integer(getBox().getContentWidth() + left + right);
intrinsicWidth = getBox().getContentWidth() + left + right;
}

FSDerivedValue heightValue = style.valueByName(CSSName.HEIGHT);
if (heightValue instanceof LengthValue) {
intrinsicHeight = new Integer(getBox().getHeight() + top + bottom);
intrinsicHeight = getBox().getHeight() + top + bottom;
}
}

Expand Down
Loading