GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • LiquidJava Docs
  • Getting Started
  • Setup
  • Overview
  • Annotations
  • @Refinement
  • @RefinementAlias
  • @StateRefinement
  • @ExternalRefinementsFor
  • @Ghost
  • @RefinementPredicate
  • Verification Features
  • Method Calls and Returns
  • Conditionals

This view

  • Original page
  • New address

GeezerVison is showing liquid-java.github.io — Email

Email

This example models a builder-style API where methods must be called in a specific order to create a valid Email object.

import java.util.ArrayList;
import java.util.List;
import liquidjava.specification.*;

@StateSet({"empty", "senderSet", "receiverSet", "bodySet"})
public class Email {

    @StateRefinement(to="empty()")
    public Email() {}

    @Refinement("_ == this")
    @StateRefinement(from="empty()", to="senderSet()")
    public Email from(String s) { return this; }

    @Refinement("_ == this")
    @StateRefinement(from="senderSet() || receiverSet()", to="receiverSet()")
    public Email to(String s) { return this; }

    @Refinement("_ == this")
    @StateRefinement(from="receiverSet()")
    public Email subject(String s) { return this; }

    @Refinement("_ == this")
    @StateRefinement(from="receiverSet()", to="bodySet()")
    public Email body(String s) { return this; }

    @Refinement("_ == this")
    @StateRefinement(from="bodySet()")
    public Email build() { return this; }
}
Email email = new Email();
email.from("me")
     .to("bob")
     .to("alice")
     .subject("greetings")
     .body("hello!")
     .build();
Email email = new Email();
email.from("me")
     .to("bob")
     .build(); // State Refinement Error

LiquidJava enforces the intended protocol:

  • The from must be set first
  • The to must be set at least once before setting the body
  • The subject is optional, but if used it must be set before the body
  • The build method can only be called after the body is set
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.