Skip to content

Commit

Permalink
[FLINK-4665] [misc] Remove unnecessary boxing/unboxing of primitive t…
Browse files Browse the repository at this point in the history
…ypes in various places

This closes apache#2537
  • Loading branch information
apivovarov authored and StephanEwen committed Sep 23, 2016
1 parent 335a282 commit 37c9512
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ && isTagged(values.get(0))
else {
final int constant = tagged(values.get(2)).getIntConstant();

if (constant < 0 || Integer.valueOf(methodOwner.split("Tuple")[1]) <= constant ) {
if (constant < 0 || Integer.parseInt(methodOwner.split("Tuple")[1]) <= constant ) {
analyzer.handleInvalidTupleAccess();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void combine(Aggregator<Float, Float> other) {
@Override
public Float result() {
// overflow will go to infinity
return new Double(sum.value()).floatValue();
return (float) sum.value();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import org.apache.commons.cli.Option;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.annotation.Public;
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.util.Preconditions;
Expand Down Expand Up @@ -275,7 +275,7 @@ public boolean has(String value) {
public int getInt(String key) {
addToDefaults(key, null);
String value = getRequired(key);
return Integer.valueOf(value);
return Integer.parseInt(value);
}

/**
Expand All @@ -285,11 +285,10 @@ public int getInt(String key) {
public int getInt(String key, int defaultValue) {
addToDefaults(key, Integer.toString(defaultValue));
String value = get(key);
if(value == null) {
if (value == null) {
return defaultValue;
} else {
return Integer.valueOf(value);
}
return Integer.parseInt(value);
}

// -------------- LONG
Expand All @@ -301,7 +300,7 @@ public int getInt(String key, int defaultValue) {
public long getLong(String key) {
addToDefaults(key, null);
String value = getRequired(key);
return Long.valueOf(value);
return Long.parseLong(value);
}

/**
Expand All @@ -311,11 +310,10 @@ public long getLong(String key) {
public long getLong(String key, long defaultValue) {
addToDefaults(key, Long.toString(defaultValue));
String value = get(key);
if(value == null) {
if (value == null) {
return defaultValue;
} else {
return Long.valueOf(value);
}
return Long.parseLong(value);
}

// -------------- FLOAT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ private void testSplitCsvInputStream(int bufferSize, boolean failAtStart) throws
if (recordCounter == 1) {
assertNotNull(result);
assertEquals("this is", result.f0);
assertEquals(new Integer(1), result.f1);
assertEquals(Integer.valueOf(1), result.f1);
assertEquals(new Double(2.0), result.f2);
assertEquals((long) format.getCurrentState(), 15);
} else if (recordCounter == 2) {
assertNotNull(result);
assertEquals("a test", result.f0);
assertEquals(new Integer(3), result.f1);
assertEquals(Integer.valueOf(3), result.f1);
assertEquals(new Double(4.0), result.f2);
assertEquals((long) format.getCurrentState(), 29);
} else if (recordCounter == 3) {
assertNotNull(result);
assertEquals("#next", result.f0);
assertEquals(new Integer(5), result.f1);
assertEquals(Integer.valueOf(5), result.f1);
assertEquals(new Double(6.0), result.f2);
assertEquals((long) format.getCurrentState(), 42);
} else {
Expand Down Expand Up @@ -196,21 +196,21 @@ private void ignoreInvalidLines(int bufferSize) {
result = format.nextRecord(result);
assertNotNull(result);
assertEquals("this is", result.f0);
assertEquals(new Integer(1), result.f1);
assertEquals(Integer.valueOf(1), result.f1);
assertEquals(new Double(2.0), result.f2);
assertEquals((long) format.getCurrentState(), 65);

result = format.nextRecord(result);
assertNotNull(result);
assertEquals("a test", result.f0);
assertEquals(new Integer(3), result.f1);
assertEquals(Integer.valueOf(3), result.f1);
assertEquals(new Double(4.0), result.f2);
assertEquals((long) format.getCurrentState(), 91);

result = format.nextRecord(result);
assertNotNull(result);
assertEquals("#next", result.f0);
assertEquals(new Integer(5), result.f1);
assertEquals(Integer.valueOf(5), result.f1);
assertEquals(new Double(6.0), result.f2);
assertEquals((long) format.getCurrentState(), 104);

Expand Down Expand Up @@ -248,13 +248,13 @@ public void ignoreSingleCharPrefixComments() {
result = format.nextRecord(result);
assertNotNull(result);
assertEquals("this is", result.f0);
assertEquals(new Integer(1), result.f1);
assertEquals(Integer.valueOf(1), result.f1);
assertEquals(new Double(2.0), result.f2);

result = format.nextRecord(result);
assertNotNull(result);
assertEquals("a test", result.f0);
assertEquals(new Integer(3), result.f1);
assertEquals(Integer.valueOf(3), result.f1);
assertEquals(new Double(4.0), result.f2);

result = format.nextRecord(result);
Expand Down Expand Up @@ -292,13 +292,13 @@ public void ignoreMultiCharPrefixComments() {
result = format.nextRecord(result);
assertNotNull(result);
assertEquals("this is", result.f0);
assertEquals(new Integer(1), result.f1);
assertEquals(Integer.valueOf(1), result.f1);
assertEquals(new Double(2.0), result.f2);

result = format.nextRecord(result);
assertNotNull(result);
assertEquals("a test", result.f0);
assertEquals(new Integer(3), result.f1);
assertEquals(Integer.valueOf(3), result.f1);
assertEquals(new Double(4.0), result.f2);

result = format.nextRecord(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public PointWithLabel map(String value) throws Exception {
for (int i = 0; i < split.length; i++) {

if (i == 42 - 1) {
p.setLabel(new Integer(split[i].trim().substring(0, 1)));
p.setLabel(Integer.valueOf(split[i].trim().substring(0, 1)));
} else {
if (a < 42 && !split[i].trim().isEmpty()) {
features[a++] = Double.parseDouble(split[i].trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.flink.api.common.functions.ReduceFunction;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.api.common.operators.DualInputSemanticProperties;
import org.apache.flink.api.common.operators.Keys;
import org.apache.flink.api.common.operators.SingleInputSemanticProperties;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.common.typeinfo.TypeInformation;
Expand All @@ -35,7 +36,6 @@
import org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst;
import org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsSecond;
import org.apache.flink.api.java.functions.SemanticPropUtil;
import org.apache.flink.api.common.operators.Keys;
import org.apache.flink.api.java.tuple.Tuple1;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.tuple.Tuple3;
Expand Down Expand Up @@ -700,7 +700,7 @@ public static class Map37 implements MapFunction<Tuple1<Tuple1<String>>, Tuple1<
@SuppressWarnings("unchecked")
@Override
public Tuple1<Tuple1<String>> map(Tuple1<Tuple1<String>> value) throws Exception {
((Tuple1<String>) value.getField(Integer.valueOf("2."))).f0 = "Hello";
((Tuple1<String>) value.getField(Integer.parseInt("2."))).f0 = "Hello";
return value;
}
}
Expand Down

0 comments on commit 37c9512

Please sign in to comment.