Paste: ugly java

Author: crest
Mode: java
Date: Mon, 26 Jul 2010 16:20:16
Plain Text |
package test;

import java.util.UUID;

import data.MasterDataSet;
import data.SlaveDataSet;
import data.SlaveVersion;
import data.StringValue;

public class Main {
	static void puts(Object o) {
		System.out.println(o);
	}
	
	public static void main(String[] args) {
		// create datasets
		MasterDataSet master = new MasterDataSet();
		SlaveDataSet  slave1 = new SlaveDataSet();
		SlaveDataSet  slave2 = new SlaveDataSet();
		
		// create a value (datasets contain values)
		StringValue value1 = new StringValue("foo");
		UUID        id1    = value1.getID();
		slave1.add(value1);
		
		// push to master as slave1
		slave1.pushToMaster(master, id1);
		
		// change value in slave1
		StringValue value2 = value1.change("bar");
		slave1.add(value2);
		
		// push to master as slave1
		slave1.pushToMaster(master, id1);
		
		
		// pull from master as slave2
		slave2.pullFromMaster(master, id1);
		
		// change value in slave2
		SlaveVersion version1 = slave2.get(id1);
		StringValue  value3   = (StringValue) version1.getValue();
		StringValue  value4   = value3.change("baz");
		
		// push to master as slave2
		slave2.add(value4);
		slave2.pushToMaster(master, id1);
		
		puts(slave2);
		puts(master);
		
		// pull from master as slave1
		slave1.pullFromMaster(master, id1);
		puts(slave1);
	}
}

Annotation: nice version

Author: crest
Mode: java
Date: Mon, 26 Jul 2010 16:20:59
Plain Text |
package test;

import java.util.UUID;

import data.DuplicateUUIDException;
import data.ForeignValueException;
import data.MasterDataSet;
import data.StringChanger;
import data.StringValue;

public class Main {
	static void puts(Object o) {
		System.out.println(o);
	}
	
	private static StringValue change(StringValue oldValue, String newContent) throws ForeignValueException {
		StringChanger changer = oldValue.getChanger();
		changer.setContent(newContent);
		changer.commit();
		return changer.getResult();
	}
	
	public static void main(String[] args) throws ForeignValueException, DuplicateUUIDException {
		MasterDataSet<StringValue> master = new MasterDataSet<StringValue>();
		
		StringValue   sv1 = new StringValue(master, "foo");
		UUID          id1 = sv1.getID();
		StringValue   sv2 = change(sv1, "bar");
		
		puts(master);
	}
}

New Annotation

Summary:
Author:
Mode:
Body: