fix: Return immutable objects

This commit is contained in:
1ambda 2016-11-15 18:17:10 +09:00
parent 3acde5693d
commit 5460241a38
2 changed files with 23 additions and 4 deletions

View file

@ -17,6 +17,7 @@
package org.apache.zeppelin.interpreter;
import java.util.ArrayList;
import java.util.List;
/**
@ -96,6 +97,20 @@ public class InterpreterOption {
this.perNote = perNote;
}
public static InterpreterOption fromInterpreterOption(InterpreterOption other) {
InterpreterOption option = new InterpreterOption();
option.remote = other.remote;
option.host = other.host;
option.port = other.port;
option.perNote = other.perNote;
option.perUser = other.perUser;
option.isExistingProcess = other.isExistingProcess;
option.setPermission = other.setPermission;
option.users = new ArrayList<>(other.users);
return option;
}
public boolean isRemote() {
return remote;
}

View file

@ -285,10 +285,14 @@ public class InterpreterFactory implements InterpreterGroupFactory {
}
private InterpreterSetting createFromInterpreterSettingRef(InterpreterSetting o) {
InterpreterSetting setting =
new InterpreterSetting(o.getName(), o.getName(), o.getInterpreterInfos(),
convertInterpreterProperties((Map<String, InterpreterProperty>) o.getProperties()),
o.getDependencies(), o.getOption(), o.getPath());
// return immutable objects
List<InterpreterInfo> infos = new ArrayList<>(o.getInterpreterInfos());
List<Dependency> deps = new ArrayList<>(o.getDependencies());
Properties props = convertInterpreterProperties((Map<String, InterpreterProperty>) o.getProperties());
InterpreterOption option = InterpreterOption.fromInterpreterOption(o.getOption());
InterpreterSetting setting = new InterpreterSetting(o.getName(), o.getName(),
o.getInterpreterInfos(), props, deps, o.getOption(), o.getPath());
setting.setInterpreterGroupFactory(this);
return setting;
}