Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrizio authored and Fabrizio committed Jan 28, 2017
1 parent f985f94 commit 42687bb
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Composite/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions Composite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions Composite/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Composite</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions Composite/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
7 changes: 7 additions & 0 deletions Composite/src/Component.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

public interface Component {

public void operation();

public void addComponent(Component component);
}
26 changes: 26 additions & 0 deletions Composite/src/Composite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.ArrayList;
import java.util.List;

public class Composite implements Component {

private String label;

private List<Component> children;

public Composite(String label) {
this.label = label;
children = new ArrayList<Component>();
}

@Override
public void operation() {
System.out.println(label);
for(Component component:children)
component.operation();
}

public void addComponent(Component component) {
children.add(component);
}

}
20 changes: 20 additions & 0 deletions Composite/src/Leaf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

public class Leaf implements Component {

private String label;

public Leaf(String label) {
this.label = label;
}

@Override
public void operation() {
System.out.println(label);
}

@Override
public void addComponent(Component component) {
throw new UnsupportedOperationException();
}

}
26 changes: 26 additions & 0 deletions Composite/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

public class Main {

public static void main(String[] args) {

Component root = new Composite("1");

Component component1 = new Composite("2");
Component component2 = new Composite("3");
Component leaf = new Leaf("4");

root.addComponent(component1);
root.addComponent(component2);
root.addComponent(leaf);

Component leaf1 = new Leaf("5");
Component leaf2 = new Leaf("6");

component1.addComponent(leaf1);
component1.addComponent(leaf2);

Component leaf3 = new Leaf("7");
component2.addComponent(leaf3);
root.operation();
}
}

0 comments on commit 42687bb

Please sign in to comment.