Skip to content

Instantly share code, notes, and snippets.

@jbrains
Forked from CoryFoy/sample.rb
Last active November 28, 2016 21:20
Show Gist options
  • Select an option

  • Save jbrains/34e8718cf773dade3b7bf28081e858b0 to your computer and use it in GitHub Desktop.

Select an option

Save jbrains/34e8718cf773dade3b7bf28081e858b0 to your computer and use it in GitHub Desktop.

Revisions

  1. jbrains revised this gist Nov 28, 2016. 2 changed files with 36 additions and 1 deletion.
    36 changes: 36 additions & 0 deletions PointOfSaleTerminal.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    package ca.jbrains.pos;

    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.InetAddress;
    import java.util.HashMap;

    public class PointOfSaleTerminal {
    public static void main(String[] args) throws IOException {
    final InputStreamReader commandSource = new InputStreamReader(System.in);
    final SanitizeTextCommand sanitizeCommand = new SanitizePointOfSaleCommand();
    final InterpretCommand interpretCommand = new WarnAboutEmptyCommands(
    new SellOneItemController(
    new InMemoryCatalog(
    new HashMap<String, Price>() {{
    put("8586013802135", Price.cents(1000));
    put("12345", Price.cents(150));
    }}
    )
    )::onBarcode
    );
    final CommandResponseFormat commandResponseFormat = CommandResponse::render;
    final DisplayText displayText = new UdpPostOffice(
    InetAddress.getLocalHost(),
    5358,
    "US-ASCII"
    )::sendMessage;

    new StreamTextCommands()
    .streamCommandsFrom(commandSource)
    .flatMap(sanitizeCommand::apply)
    .map(interpretCommand::apply)
    .map(commandResponseFormat::apply)
    .forEach(displayText::apply);
    }
    }
    1 change: 0 additions & 1 deletion sample.rb
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    # TODO: Write sample implementation
  2. @CoryFoy CoryFoy created this gist Nov 28, 2016.
    1 change: 1 addition & 0 deletions sample.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # TODO: Write sample implementation