extract method object: process parameters as output variables (IDEA-162642)

This commit is contained in:
Anna.Kozlova
2016-10-17 19:00:10 +02:00
parent e80d2486b2
commit 2a8fc8cbc6
4 changed files with 135 additions and 2 deletions
@@ -0,0 +1,34 @@
import java.util.Arrays;
import java.util.List;
class Foo {
private List<Foo> foos = Arrays.asList(new Foo("one"), new Foo("two"));
private String name;
public Foo(String name) {
this.name = name;
}
public String getName() {
return name;
}
public List<Foo> getFoos() {
return foos;
}
public Foo getFoo(String name) {
if (name != null)
<selection>for (Foo foo : getFoos())
if (foo.getName().equals(name)) {
return foo;
}</selection>
return null;
}
}
@@ -0,0 +1,59 @@
import java.util.Arrays;
import java.util.List;
class Foo {
private List<Foo> foos = Arrays.asList(new Foo("one"), new Foo("two"));
private String name;
public Foo(String name) {
this.name = name;
}
public String getName() {
return name;
}
public List<Foo> getFoos() {
return foos;
}
public Foo getFoo(String name) {
if (name != null)
Inner inner = new Inner(name).invoke();if (inner.is()) return inner.getFoo();
return null;
}
private class Inner {
private boolean myResult;
private String name;
private Foo foo;
public Inner(String name) {
this.name = name;
}
boolean is() {
return myResult;
}
public Foo getFoo() {
return foo;
}
public Inner invoke() {
for (Foo foo : getFoos()) {
Inner.this.foo = foo;
if (foo.getName().equals(name)) {
myResult = true;
return this;
}
}
myResult = false;
return this;
}
}
}