Skip to content

Commit e1059ad

Browse files
committed
Some deprecation warnings removed.
1 parent 1519e57 commit e1059ad

File tree

12 files changed

+63
-76
lines changed

12 files changed

+63
-76
lines changed

aima-core/src/main/java/aima/core/agent/impl/ObjectWithDynamicAttributes.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @author Ciaran O'Reilly
1111
* @author Mike Stampone
1212
*/
13-
public abstract class ObjectWithDynamicAttributes {
13+
public abstract class ObjectWithDynamicAttributes implements Cloneable {
1414
private Map<Object, Object> attributes = new LinkedHashMap<>();
1515

1616
//
@@ -103,17 +103,17 @@ public void removeAttribute(Object key) {
103103
/**
104104
* Creates and returns a copy of this ObjectWithDynamicAttributes
105105
*/
106-
public ObjectWithDynamicAttributes copy() {
107-
ObjectWithDynamicAttributes copy = null;
108-
106+
public ObjectWithDynamicAttributes clone() {
109107
try {
110-
copy = getClass().newInstance();
111-
copy.attributes.putAll(attributes);
108+
ObjectWithDynamicAttributes result;
109+
result = (ObjectWithDynamicAttributes) super.clone();
110+
result.attributes = new LinkedHashMap<>();
111+
result.attributes.putAll(attributes);
112+
return result;
112113
} catch (Exception ex) {
113114
ex.printStackTrace();
114115
}
115-
116-
return copy;
116+
return null;
117117
}
118118

119119
@Override

aima-core/src/main/java/aima/core/learning/framework/DataSetFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
*/
1717
public class DataSetFactory {
1818

19-
public DataSet fromFile(String filename, DataSetSpecification spec,
20-
String separator) throws Exception {
19+
public DataSet fromFile(String filename, DataSetSpecification spec, String separator) throws Exception {
2120
// assumed file in data directory and ends in .csv
2221
DataSet ds = new DataSet(spec);
2322

24-
try(BufferedReader reader = new BufferedReader(new InputStreamReader(
23+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
2524
DataResource.class.getResourceAsStream(filename + ".csv")))) {
2625

2726
String line;

aima-core/src/main/java/aima/core/learning/neural/LayerSensitivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ public Layer getLayer() {
6262
//
6363

6464
private Matrix createDerivativeMatrix(Vector lastInducedField) {
65-
List<Double> lst = new ArrayList<Double>();
65+
List<Double> lst = new ArrayList<>();
6666
for (int i = 0; i < lastInducedField.size(); i++) {
67-
lst.add(new Double(layer.getActivationFunction().deriv(
68-
lastInducedField.getValue(i))));
67+
lst.add(layer.getActivationFunction().deriv(lastInducedField.getValue(i)));
6968
}
7069
return Matrix.createDiagonalMatrix(lst);
7170
}

aima-core/src/main/java/aima/core/learning/neural/NNExample.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,17 @@ public NNExample(List<Double> normalizedInput, List<Double> normalizedTarget) {
1818
}
1919

2020
public NNExample copyExample() {
21-
List<Double> newInput = new ArrayList<Double>();
22-
List<Double> newTarget = new ArrayList<Double>();
23-
for (Double d : normalizedInput) {
24-
newInput.add(new Double(d.doubleValue()));
25-
}
26-
for (Double d : normalizedTarget) {
27-
newTarget.add(new Double(d.doubleValue()));
28-
}
21+
List<Double> newInput = new ArrayList<>(normalizedInput);
22+
List<Double> newTarget = new ArrayList<>(normalizedTarget);
2923
return new NNExample(newInput, newTarget);
3024
}
3125

3226
public Vector getInput() {
33-
Vector v = new Vector(normalizedInput);
34-
return v;
35-
27+
return new Vector(normalizedInput);
3628
}
3729

3830
public Vector getTarget() {
39-
Vector v = new Vector(normalizedTarget);
40-
return v;
41-
31+
return new Vector(normalizedTarget);
4232
}
4333

4434
public boolean isCorrect(Vector prediction) {

aima-core/src/main/java/aima/core/probability/mdp/search/PolicyIteration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public PolicyIteration(PolicyEvaluation<S, A> policyEvaluation) {
6969
public Policy<S, A> policyIteration(MarkovDecisionProcess<S, A> mdp) {
7070
// local variables: U, a vector of utilities for states in S, initially
7171
// zero
72-
Map<S, Double> U = Util.create(mdp.states(), new Double(0));
72+
Map<S, Double> U = Util.create(mdp.states(),0.0);
7373
// &pi;, a policy vector indexed by state, initially random
7474
Map<S, A> pi = initialPolicyVector(mdp);
7575
boolean unchanged;

aima-core/src/main/java/aima/core/probability/mdp/search/ValueIteration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public Map<S, Double> valueIteration(MarkovDecisionProcess<S, A> mdp,
7777
//
7878
// local variables: U, U', vectors of utilities for states in S,
7979
// initially zero
80-
Map<S, Double> U = Util.create(mdp.states(), new Double(0));
81-
Map<S, Double> Udelta = Util.create(mdp.states(), new Double(0));
80+
Map<S, Double> U = Util.create(mdp.states(), 0.0);
81+
Map<S, Double> Udelta = Util.create(mdp.states(), 0.0);
8282
// &delta; the maximum change in the utility of any state in an
8383
// iteration
8484
double delta = 0;

aima-core/src/main/java/aima/core/probability/proposition/IntegerSumProposition.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public IntegerSumProposition(String name, FiniteIntegerDomain sumsDomain,
3535
//
3636
// START-Proposition
3737
public boolean holds(Map<RandomVariable, Object> possibleWorld) {
38-
Integer sum = new Integer(0);
39-
38+
Integer sum = 0;
4039
for (RandomVariable rv : sumVars) {
4140
Object o = possibleWorld.get(rv);
4241
if (o instanceof Integer) {

aima-core/src/test/java/aima/test/core/unit/environment/map/MapTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ public void testLocationsLinkedTo() {
6767

6868
@Test
6969
public void testDistances() {
70-
Assert.assertEquals(new Double(5), aMap.getDistance("A", "B"));
71-
Assert.assertEquals(new Double(6), aMap.getDistance("A", "C"));
72-
Assert.assertEquals(new Double(4), aMap.getDistance("B", "C"));
73-
Assert.assertEquals(new Double(7), aMap.getDistance("C", "D"));
74-
Assert.assertEquals(new Double(14), aMap.getDistance("B", "E"));
70+
Assert.assertEquals((Double) 5.0, aMap.getDistance("A", "B"));
71+
Assert.assertEquals((Double) 6.0, aMap.getDistance("A", "C"));
72+
Assert.assertEquals((Double) 4.0, aMap.getDistance("B", "C"));
73+
Assert.assertEquals((Double) 7.0, aMap.getDistance("C", "D"));
74+
Assert.assertEquals((Double) 14.0, aMap.getDistance("B", "E"));
7575
//
76-
Assert.assertEquals(new Double(5), aMap.getDistance("B", "A"));
77-
Assert.assertEquals(new Double(6), aMap.getDistance("C", "A"));
78-
Assert.assertEquals(new Double(4), aMap.getDistance("C", "B"));
79-
Assert.assertEquals(new Double(7), aMap.getDistance("D", "C"));
76+
Assert.assertEquals((Double) 5.0, aMap.getDistance("B", "A"));
77+
Assert.assertEquals((Double) 6.0, aMap.getDistance("C", "A"));
78+
Assert.assertEquals((Double) 4.0, aMap.getDistance("C", "B"));
79+
Assert.assertEquals((Double) 7.0, aMap.getDistance("D", "C"));
8080

8181
// No distances should be returned if links not established or locations
8282
// do not exist

aima-core/src/test/java/aima/test/core/unit/logic/propositional/parsing/ListTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public void testListOfSymbolsClone() {
2828

2929
@Test
3030
public void testListRemove() {
31-
List<Integer> one = new ArrayList<Integer>();
32-
one.add(new Integer(1));
31+
List<Integer> one = new ArrayList<>();
32+
one.add(1);
3333
Assert.assertEquals(1, one.size());
3434
one.remove(0);
3535
Assert.assertEquals(0, one.size());

aima-core/src/test/java/aima/test/core/unit/util/SetOpsTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ public class SetOpsTest {
1818

1919
@Before
2020
public void setUp() {
21-
s1 = new HashSet<Integer>();
22-
s1.add(new Integer(1));
23-
s1.add(new Integer(2));
24-
s1.add(new Integer(3));
25-
s1.add(new Integer(4));
21+
s1 = new HashSet<>();
22+
s1.add(1);
23+
s1.add(2);
24+
s1.add(3);
25+
s1.add(4);
2626

27-
s2 = new HashSet<Integer>();
28-
s2.add(new Integer(4));
29-
s2.add(new Integer(5));
30-
s2.add(new Integer(6));
27+
s2 = new HashSet<>();
28+
s2.add(4);
29+
s2.add(5);
30+
s2.add(6);
3131
}
3232

3333
@Test
@@ -37,7 +37,7 @@ public void testUnion() {
3737
Assert.assertEquals(4, s1.size());
3838
Assert.assertEquals(3, s2.size());
3939

40-
s1.remove(new Integer(1));
40+
s1.remove(1);
4141
Assert.assertEquals(6, union.size());
4242
Assert.assertEquals(3, s1.size());
4343
Assert.assertEquals(3, s2.size());
@@ -50,7 +50,7 @@ public void testIntersection() {
5050
Assert.assertEquals(4, s1.size());
5151
Assert.assertEquals(3, s2.size());
5252

53-
s1.remove(new Integer(1));
53+
s1.remove(1);
5454
Assert.assertEquals(1, intersection.size());
5555
Assert.assertEquals(3, s1.size());
5656
Assert.assertEquals(3, s2.size());
@@ -60,17 +60,17 @@ public void testIntersection() {
6060
public void testDifference() {
6161
Set<Integer> difference = SetOps.difference(s1, s2);
6262
Assert.assertEquals(3, difference.size());
63-
Assert.assertTrue(difference.contains(new Integer(1)));
64-
Assert.assertTrue(difference.contains(new Integer(2)));
65-
Assert.assertTrue(difference.contains(new Integer(3)));
63+
Assert.assertTrue(difference.contains(1));
64+
Assert.assertTrue(difference.contains(2));
65+
Assert.assertTrue(difference.contains(3));
6666
}
6767

6868
@Test
6969
public void testDifference2() {
70-
Set<Integer> one = new HashSet<Integer>();
71-
Set<Integer> two = new HashSet<Integer>();
72-
one.add(new Integer(1));
73-
two.add(new Integer(1));
70+
Set<Integer> one = new HashSet<>();
71+
Set<Integer> two = new HashSet<>();
72+
one.add(1);
73+
two.add(1);
7474
Set<Integer> difference = SetOps.difference(one, two);
7575
Assert.assertTrue(difference.isEmpty());
7676
}

0 commit comments

Comments
 (0)