Skip to content

Commit 7fde8d7

Browse files
committed
Use Collections.unmodifiable*
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
1 parent df9e2f8 commit 7fde8d7

File tree

1 file changed

+7
-6
lines changed
  • tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow

1 file changed

+7
-6
lines changed

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/Session.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.google.protobuf.InvalidProtocolBufferException;
2626
import java.util.ArrayList;
27+
import java.util.Collections;
2728
import java.util.Iterator;
2829
import java.util.LinkedHashMap;
2930
import java.util.List;
@@ -173,8 +174,8 @@ private Result(List<Tensor<?>> results, List<Output<?>> fetches, RunMetadata met
173174
}
174175

175176
this.metadata = metadata;
176-
this.results = new ArrayList<>(results);
177-
this.fetches = new ArrayList<>(fetches);
177+
this.results = results;
178+
this.fetches = fetches;
178179
outputMap = new LinkedHashMap<>();
179180
for(int i = 0 ; i < fetches.size() ; i++){
180181
outputMap.put(fetches.get(i), results.get(i));
@@ -192,21 +193,21 @@ private void requireOpen(){
192193
*/
193194
public List<Tensor<?>> getResults() {
194195
requireOpen();
195-
return new ArrayList<>(results);
196+
return Collections.unmodifiableList(results);
196197
}
197198

198199
/**
199200
* Get the outputs that were fetched.
200201
*/
201202
public List<Output<?>> getFetches() {
202-
return new ArrayList<>(fetches);
203+
return Collections.unmodifiableList(fetches);
203204
}
204205

205206
/**
206207
* Get a map of the fetched outputs to their results.
207208
*/
208209
public Map<Output<?>, Tensor<?>> getOutputMap(){
209-
return new LinkedHashMap<>(outputMap);
210+
return Collections.unmodifiableMap(outputMap);
210211
}
211212

212213
/**
@@ -591,7 +592,7 @@ private Result runHelper(boolean wantMetadata) {
591592
} finally {
592593
runRef.close();
593594
}
594-
return new Result(outputs, this.outputs, metadata);
595+
return new Result(outputs, new ArrayList<>(this.outputs), metadata);
595596
}
596597

597598
private class Reference implements AutoCloseable {

0 commit comments

Comments
 (0)