You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2013/08/22 18:06:09 UTC
svn commit: r1516496 -
/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
Author: ggregory
Date: Thu Aug 22 16:06:08 2013
New Revision: 1516496
URL: http://svn.apache.org/r1516496
Log:
Make boxing and unboxing explicit.
Modified:
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java?rev=1516496&r1=1516495&r2=1516496&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java Thu Aug 22 16:06:08 2013
@@ -49,9 +49,9 @@ public final class PropertiesRewritePoli
private PropertiesRewritePolicy(final Configuration config, final List<Property> props) {
this.config = config;
this.properties = new HashMap<Property, Boolean>(props.size());
- for (final Property prop : props) {
- final boolean interpolate = prop.getValue().contains("${");
- properties.put(prop, interpolate);
+ for (final Property property : props) {
+ final Boolean interpolate = Boolean.valueOf(property.getValue().contains("${"));
+ properties.put(property, interpolate);
}
}
@@ -66,7 +66,7 @@ public final class PropertiesRewritePoli
final Map<String, String> props = new HashMap<String, String>(source.getContextMap());
for (final Map.Entry<Property, Boolean> entry : properties.entrySet()) {
final Property prop = entry.getKey();
- props.put(prop.getName(), entry.getValue() ?
+ props.put(prop.getName(), entry.getValue().booleanValue() ?
config.getStrSubstitutor().replace(prop.getValue()) : prop.getValue());
}
Re: svn commit: r1516496 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
Posted by Nick Williams <ni...@nicholaswilliams.net>.
That doesn't seem like sufficient justification to use explicit boxing. Autoboxing was added to the JLS for a reason. If you find code that's confusing, analyze it and comment it, maybe. But I disagree with switching from autoboxing to explicit boxing.
Not to mention that my IDE flags explicit boxing as a warning.
N
On Aug 22, 2013, at 11:12 AM, Gary Gregory wrote:
> On Thu, Aug 22, 2013 at 12:08 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> Why?
>
> Because then the reader knows it is being done on purpose. I've fixed some code today where it looks like unboxing and boxing happened back and forth wastefully. For example, a class was using an Integer instead of an int and conversions took place back and forth. In another case, a string was parsed to an Integer only to be immediately unboxed; same for another call site but for a Long, and so on.
>
> Gary
>
> On Aug 22, 2013, at 9:06 AM, ggregory@apache.org wrote:
>
> > Author: ggregory
> > Date: Thu Aug 22 16:06:08 2013
> > New Revision: 1516496
> >
> > URL: http://svn.apache.org/r1516496
> > Log:
> > Make boxing and unboxing explicit.
> >
> > Modified:
> > logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
> >
> > Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
> > URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java?rev=1516496&r1=1516495&r2=1516496&view=diff
> > ==============================================================================
> > --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java (original)
> > +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java Thu Aug 22 16:06:08 2013
> > @@ -49,9 +49,9 @@ public final class PropertiesRewritePoli
> > private PropertiesRewritePolicy(final Configuration config, final List<Property> props) {
> > this.config = config;
> > this.properties = new HashMap<Property, Boolean>(props.size());
> > - for (final Property prop : props) {
> > - final boolean interpolate = prop.getValue().contains("${");
> > - properties.put(prop, interpolate);
> > + for (final Property property : props) {
> > + final Boolean interpolate = Boolean.valueOf(property.getValue().contains("${"));
> > + properties.put(property, interpolate);
> > }
> > }
> >
> > @@ -66,7 +66,7 @@ public final class PropertiesRewritePoli
> > final Map<String, String> props = new HashMap<String, String>(source.getContextMap());
> > for (final Map.Entry<Property, Boolean> entry : properties.entrySet()) {
> > final Property prop = entry.getKey();
> > - props.put(prop.getName(), entry.getValue() ?
> > + props.put(prop.getName(), entry.getValue().booleanValue() ?
> > config.getStrSubstitutor().replace(prop.getValue()) : prop.getValue());
> > }
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
Re: svn commit: r1516496 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
Posted by Ralph Goers <ra...@dslextreme.com>.
On Aug 22, 2013, at 9:12 AM, Gary Gregory wrote:
> On Thu, Aug 22, 2013 at 12:08 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> Why?
>
> Because then the reader knows it is being done on purpose. I've fixed some code today where it looks like unboxing and boxing happened back and forth wastefully. For example, a class was using an Integer instead of an int and conversions took place back and forth. In another case, a string was parsed to an Integer only to be immediately unboxed; same for another call site but for a Long, and so on.
Yes, I saw those and didn't question them. Autoboxing was added to the language for a reason. The use below seems like a perfectly valid use of it. Furthermore, I wouldn't be surprised if the compiler is smart enough to realize that boxing and unboxing is going on and optimizes it away, but in those cases I have no problem in correcting the code.
Ralph
>
> Gary
>
> On Aug 22, 2013, at 9:06 AM, ggregory@apache.org wrote:
>
> > Author: ggregory
> > Date: Thu Aug 22 16:06:08 2013
> > New Revision: 1516496
> >
> > URL: http://svn.apache.org/r1516496
> > Log:
> > Make boxing and unboxing explicit.
> >
> > Modified:
> > logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
> >
> > Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
> > URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java?rev=1516496&r1=1516495&r2=1516496&view=diff
> > ==============================================================================
> > --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java (original)
> > +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java Thu Aug 22 16:06:08 2013
> > @@ -49,9 +49,9 @@ public final class PropertiesRewritePoli
> > private PropertiesRewritePolicy(final Configuration config, final List<Property> props) {
> > this.config = config;
> > this.properties = new HashMap<Property, Boolean>(props.size());
> > - for (final Property prop : props) {
> > - final boolean interpolate = prop.getValue().contains("${");
> > - properties.put(prop, interpolate);
> > + for (final Property property : props) {
> > + final Boolean interpolate = Boolean.valueOf(property.getValue().contains("${"));
> > + properties.put(property, interpolate);
> > }
> > }
> >
> > @@ -66,7 +66,7 @@ public final class PropertiesRewritePoli
> > final Map<String, String> props = new HashMap<String, String>(source.getContextMap());
> > for (final Map.Entry<Property, Boolean> entry : properties.entrySet()) {
> > final Property prop = entry.getKey();
> > - props.put(prop.getName(), entry.getValue() ?
> > + props.put(prop.getName(), entry.getValue().booleanValue() ?
> > config.getStrSubstitutor().replace(prop.getValue()) : prop.getValue());
> > }
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
Re: svn commit: r1516496 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
Posted by Gary Gregory <ga...@gmail.com>.
On Thu, Aug 22, 2013 at 12:08 PM, Ralph Goers <ra...@dslextreme.com>wrote:
> Why?
>
Because then the reader knows it is being done on purpose. I've fixed some
code today where it looks like unboxing and boxing happened back and forth
wastefully. For example, a class was using an Integer instead of an int and
conversions took place back and forth. In another case, a string was parsed
to an Integer only to be immediately unboxed; same for another call site
but for a Long, and so on.
Gary
>
> On Aug 22, 2013, at 9:06 AM, ggregory@apache.org wrote:
>
> > Author: ggregory
> > Date: Thu Aug 22 16:06:08 2013
> > New Revision: 1516496
> >
> > URL: http://svn.apache.org/r1516496
> > Log:
> > Make boxing and unboxing explicit.
> >
> > Modified:
> >
> logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
> >
> > Modified:
> logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
> > URL:
> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java?rev=1516496&r1=1516495&r2=1516496&view=diff
> >
> ==============================================================================
> > ---
> logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
> (original)
> > +++
> logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
> Thu Aug 22 16:06:08 2013
> > @@ -49,9 +49,9 @@ public final class PropertiesRewritePoli
> > private PropertiesRewritePolicy(final Configuration config, final
> List<Property> props) {
> > this.config = config;
> > this.properties = new HashMap<Property, Boolean>(props.size());
> > - for (final Property prop : props) {
> > - final boolean interpolate = prop.getValue().contains("${");
> > - properties.put(prop, interpolate);
> > + for (final Property property : props) {
> > + final Boolean interpolate =
> Boolean.valueOf(property.getValue().contains("${"));
> > + properties.put(property, interpolate);
> > }
> > }
> >
> > @@ -66,7 +66,7 @@ public final class PropertiesRewritePoli
> > final Map<String, String> props = new HashMap<String,
> String>(source.getContextMap());
> > for (final Map.Entry<Property, Boolean> entry :
> properties.entrySet()) {
> > final Property prop = entry.getKey();
> > - props.put(prop.getName(), entry.getValue() ?
> > + props.put(prop.getName(), entry.getValue().booleanValue() ?
> > config.getStrSubstitutor().replace(prop.getValue()) :
> prop.getValue());
> > }
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: svn commit: r1516496 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
Posted by Ralph Goers <ra...@dslextreme.com>.
Why?
On Aug 22, 2013, at 9:06 AM, ggregory@apache.org wrote:
> Author: ggregory
> Date: Thu Aug 22 16:06:08 2013
> New Revision: 1516496
>
> URL: http://svn.apache.org/r1516496
> Log:
> Make boxing and unboxing explicit.
>
> Modified:
> logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
>
> Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java
> URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java?rev=1516496&r1=1516495&r2=1516496&view=diff
> ==============================================================================
> --- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java (original)
> +++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/PropertiesRewritePolicy.java Thu Aug 22 16:06:08 2013
> @@ -49,9 +49,9 @@ public final class PropertiesRewritePoli
> private PropertiesRewritePolicy(final Configuration config, final List<Property> props) {
> this.config = config;
> this.properties = new HashMap<Property, Boolean>(props.size());
> - for (final Property prop : props) {
> - final boolean interpolate = prop.getValue().contains("${");
> - properties.put(prop, interpolate);
> + for (final Property property : props) {
> + final Boolean interpolate = Boolean.valueOf(property.getValue().contains("${"));
> + properties.put(property, interpolate);
> }
> }
>
> @@ -66,7 +66,7 @@ public final class PropertiesRewritePoli
> final Map<String, String> props = new HashMap<String, String>(source.getContextMap());
> for (final Map.Entry<Property, Boolean> entry : properties.entrySet()) {
> final Property prop = entry.getKey();
> - props.put(prop.getName(), entry.getValue() ?
> + props.put(prop.getName(), entry.getValue().booleanValue() ?
> config.getStrSubstitutor().replace(prop.getValue()) : prop.getValue());
> }
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org