The following code simulates the use of a PS/2 keyboard in a USB bus. It defines a PS/2 keyboard (adaptee), a USB device interface (target), a PS2ToUSBAdapter (adapter), and the wires to link in order to make the device work:
package gof.structural.adapter;import java.util.Arrays;import java.util.Collections;import java.util.List;class WireCap { WireCap link = WireCap.LooseCap; private Wire wire; publicstatic WireCap LooseCap = new WireCap(null); public WireCap(Wire wire) { this.wire = wire; } publicvoid addLinkTo(WireCap link) { this.link = link; } public Wire getWire() { return wire; } public String toString() { if (link.equals(WireCap.LooseCap)) return "WireCap belonging to LooseCap"; return "WireCap belonging to " + wire ...