Skip to content

Instantly share code, notes, and snippets.

@libliboom
Created October 31, 2019 18:41
Show Gist options
  • Save libliboom/9e395cf1849c98e269d09243cea37b71 to your computer and use it in GitHub Desktop.
Save libliboom/9e395cf1849c98e269d09243cea37b71 to your computer and use it in GitHub Desktop.
// 반환 결과값이 단순한 경우
int size() {
int result = 1;
for (Node each : getChildren())
result += each.size();
return result;
}
// 파라미터를 전달해서 결과를 수집하는 직관적인 경우
asList() {
List results = new ArrayList();
addTo(results);
return results;
}
addTo(List elements) {
elements.add(getValue());
for (Node each : getChildren())
each.addTo(elements);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment