Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 23 files changed
  • 0 comments
  • 1 contributor
7  .classpath
... ...
@@ -0,0 +1,7 @@
  1
+<?xml version="1.0" encoding="UTF-8"?>
  2
+<classpath>
  3
+	<classpathentry kind="src" path="src"/>
  4
+	<classpathentry kind="src" path="gen"/>
  5
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
  6
+	<classpathentry kind="output" path="bin/classes"/>
  7
+</classpath>
33  .project
... ...
@@ -0,0 +1,33 @@
  1
+<?xml version="1.0" encoding="UTF-8"?>
  2
+<projectDescription>
  3
+	<name>DiasporaApp</name>
  4
+	<comment></comment>
  5
+	<projects>
  6
+	</projects>
  7
+	<buildSpec>
  8
+		<buildCommand>
  9
+			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
  10
+			<arguments>
  11
+			</arguments>
  12
+		</buildCommand>
  13
+		<buildCommand>
  14
+			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
  15
+			<arguments>
  16
+			</arguments>
  17
+		</buildCommand>
  18
+		<buildCommand>
  19
+			<name>org.eclipse.jdt.core.javabuilder</name>
  20
+			<arguments>
  21
+			</arguments>
  22
+		</buildCommand>
  23
+		<buildCommand>
  24
+			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
  25
+			<arguments>
  26
+			</arguments>
  27
+		</buildCommand>
  28
+	</buildSpec>
  29
+	<natures>
  30
+		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
  31
+		<nature>org.eclipse.jdt.core.javanature</nature>
  32
+	</natures>
  33
+</projectDescription>
18  AndroidManifest.xml
... ...
@@ -0,0 +1,18 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3
+      package="org.lambertini"
  4
+      android:versionCode="1"
  5
+      android:versionName="1.0">
  6
+    <uses-sdk android:minSdkVersion="4" />
  7
+
  8
+    <application android:icon="@drawable/icon" android:label="@string/app_name">
  9
+        <activity android:name=".MainDiasporaActivity"
  10
+                  android:label="@string/app_name">
  11
+            <intent-filter>
  12
+                <action android:name="android.intent.action.MAIN" />
  13
+                <category android:name="android.intent.category.LAUNCHER" />
  14
+            </intent-filter>
  15
+        </activity>
  16
+
  17
+    </application>
  18
+</manifest>
36  proguard.cfg
... ...
@@ -0,0 +1,36 @@
  1
+-optimizationpasses 5
  2
+-dontusemixedcaseclassnames
  3
+-dontskipnonpubliclibraryclasses
  4
+-dontpreverify
  5
+-verbose
  6
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
  7
+
  8
+-keep public class * extends android.app.Activity
  9
+-keep public class * extends android.app.Application
  10
+-keep public class * extends android.app.Service
  11
+-keep public class * extends android.content.BroadcastReceiver
  12
+-keep public class * extends android.content.ContentProvider
  13
+-keep public class * extends android.app.backup.BackupAgentHelper
  14
+-keep public class * extends android.preference.Preference
  15
+-keep public class com.android.vending.licensing.ILicensingService
  16
+
  17
+-keepclasseswithmembernames class * {
  18
+    native <methods>;
  19
+}
  20
+
  21
+-keepclasseswithmembernames class * {
  22
+    public <init>(android.content.Context, android.util.AttributeSet);
  23
+}
  24
+
  25
+-keepclasseswithmembernames class * {
  26
+    public <init>(android.content.Context, android.util.AttributeSet, int);
  27
+}
  28
+
  29
+-keepclassmembers enum * {
  30
+    public static **[] values();
  31
+    public static ** valueOf(java.lang.String);
  32
+}
  33
+
  34
+-keep class * implements android.os.Parcelable {
  35
+  public static final android.os.Parcelable$Creator *;
  36
+}
11  project.properties
... ...
@@ -0,0 +1,11 @@
  1
+# This file is automatically generated by Android Tools.
  2
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
  3
+#
  4
+# This file must be checked in Version Control Systems.
  5
+#
  6
+# To customize properties used by the Ant build system use,
  7
+# "ant.properties", and override values to adapt the script to your
  8
+# project structure.
  9
+
  10
+# Project target.
  11
+target=android-4
BIN  res/drawable-hdpi/icon.png
BIN  res/drawable-ldpi/icon.png
BIN  res/drawable-mdpi/icon.png
24  res/layout/cluster_item_property.xml
... ...
@@ -0,0 +1,24 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<LinearLayout
  3
+  xmlns:android="http://schemas.android.com/apk/res/android"
  4
+  android:orientation="vertical"
  5
+  android:layout_width="fill_parent"
  6
+  android:layout_height="fill_parent">
  7
+        <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
  8
+            <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabcontent">
  9
+                <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab2">
  10
+                    <TabHost android:layout_weight="1" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
  11
+                        <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
  12
+                            <TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
  13
+                            <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabcontent">
  14
+                                <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab1"></LinearLayout>
  15
+                                <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab2"></LinearLayout>
  16
+                                <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab3"></LinearLayout>
  17
+                            </FrameLayout>
  18
+                        </LinearLayout>
  19
+                    </TabHost>
  20
+                </LinearLayout>
  21
+            </FrameLayout>
  22
+        </LinearLayout>
  23
+    
  24
+</LinearLayout>
29  res/layout/diaspora_list_item.xml
... ...
@@ -0,0 +1,29 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<LinearLayout
  3
+  xmlns:android="http://schemas.android.com/apk/res/android"
  4
+  android:orientation="vertical"
  5
+  android:layout_width="fill_parent"
  6
+  android:layout_height="fill_parent">
  7
+    <TextView android:text="TextView" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/li_Name" android:padding="4dip" android:layout_height="wrap_content" android:layout_width="fill_parent"></TextView>
  8
+    <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content">
  9
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="Env: " android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/TextView01"></TextView>
  10
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="Env: " android:layout_width="wrap_content" android:id="@+id/li_Env" android:textAppearance="?android:attr/textAppearanceMedium" android:includeFontPadding="true"></TextView>
  11
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="Tech: " android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/TextView03"></TextView>
  12
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="Tech: " android:layout_width="wrap_content" android:id="@+id/li_Tech" android:textAppearance="?android:attr/textAppearanceMedium" ></TextView>
  13
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="Res: " android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/TextView04" ></TextView>
  14
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Res: " android:id="@+id/li_Res"></TextView>
  15
+    </LinearLayout>
  16
+    <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" >
  17
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="Aspects: " android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/textView3"></TextView>
  18
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="fill_parent" android:id="@+id/li_aspects"></TextView>
  19
+    </LinearLayout>
  20
+    <LinearLayout android:id="@+id/linearLayout3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" >
  21
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="Links to: " android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/textView4"></TextView>
  22
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="fill_parent" android:id="@+id/li_links_to"></TextView>
  23
+    </LinearLayout>
  24
+    <LinearLayout android:id="@+id/linearLayout4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" >
  25
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="Linked by: " android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/textView6"></TextView>
  26
+        <TextView android:padding="2dip" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="fill_parent" android:id="@+id/li_linked_by"></TextView>
  27
+    </LinearLayout>
  28
+    
  29
+</LinearLayout>
9  res/layout/diaspora_main_activity.xml
... ...
@@ -0,0 +1,9 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3
+    android:orientation="vertical"
  4
+    android:layout_width="fill_parent"
  5
+    android:layout_height="fill_parent"
  6
+    >
  7
+    <Button android:text="@string/create_new_cluster" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/btn_NewCluster"></Button>
  8
+    <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/list_cluster_nodes"></ListView>
  9
+</LinearLayout>
9  res/layout/main.xml
... ...
@@ -0,0 +1,9 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3
+    android:orientation="vertical"
  4
+    android:layout_width="fill_parent"
  5
+    android:layout_height="fill_parent"
  6
+    >
  7
+    <Button android:text="@string/create_new_cluster" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/btnNewCluster"></Button>
  8
+    <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/list_cluster"></ListView>
  9
+</LinearLayout>
6  res/values/strings.xml
... ...
@@ -0,0 +1,6 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<resources>
  3
+    <string name="hello">Hello World, MainDiasporaActivity!</string>
  4
+    <string name="app_name">DiasporaApp</string>
  5
+    <string name="create_new_cluster">Create new Cluster</string>
  6
+</resources>
99  src/org/lambertini/MainDiasporaActivity.java
... ...
@@ -0,0 +1,99 @@
  1
+package org.lambertini;
  2
+
  3
+import org.json.JSONException;
  4
+import org.json.JSONObject;
  5
+import org.lambertini.helpers.ClusterAdapter;
  6
+import org.lambertini.structures.Cluster;
  7
+
  8
+import android.app.Activity;
  9
+import android.app.Application;
  10
+import android.content.Context;
  11
+import android.os.Bundle;
  12
+import android.view.View;
  13
+import android.view.View.OnClickListener;
  14
+import android.widget.AdapterView.OnItemClickListener;
  15
+import android.widget.AdapterView;
  16
+import android.widget.Button;
  17
+import android.widget.ListView;
  18
+import android.widget.SimpleAdapter;
  19
+
  20
+public class MainDiasporaActivity extends Activity {
  21
+    Cluster c;
  22
+    ListView lv;
  23
+    
  24
+	/** Called when the activity is first created. */
  25
+    @Override
  26
+    public void onCreate(Bundle savedInstanceState) {
  27
+        super.onCreate(savedInstanceState);
  28
+        setContentView(R.layout.diaspora_main_activity);
  29
+        
  30
+        lv = (ListView)findViewById(R.id.list_cluster_nodes);
  31
+        Button btn = (Button)findViewById(R.id.btn_NewCluster);
  32
+        
  33
+        if (savedInstanceState != null
  34
+        		&& !savedInstanceState.isEmpty() 
  35
+        		&& savedInstanceState.containsKey("CLUSTER"))
  36
+            	c = Cluster.fromStringData(savedInstanceState.getString("CLUSTER"));
  37
+        else
  38
+        	c = new Cluster(12);
  39
+        
  40
+
  41
+        SimpleAdapter sa = ClusterAdapter.createSimpleAdapterForCluster(c, this.getApplicationContext());
  42
+        
  43
+        lv.setAdapter (sa);
  44
+        lv.setOnItemClickListener(new OnItemClickListener() {
  45
+        	@Override
  46
+        	public void onItemClick(
  47
+        			AdapterView<?> parent, 
  48
+					View view, 
  49
+					int position,
  50
+					long id) {
  51
+        		// TODO Auto-generated method stub
  52
+        		
  53
+        	}
  54
+        });
  55
+        
  56
+        btn.setOnClickListener(new OnClickListener() {
  57
+			
  58
+			@Override
  59
+			public void onClick(View v) {
  60
+				// TODO Auto-generated method stub
  61
+				c = new Cluster(12);
  62
+		        SimpleAdapter sa = ClusterAdapter.createSimpleAdapterForCluster(c, MainDiasporaActivity.this.getApplicationContext());
  63
+		        lv.setAdapter(sa);
  64
+		        
  65
+				
  66
+			}
  67
+		});
  68
+        
  69
+    }
  70
+    
  71
+    @Override
  72
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
  73
+    	// TODO Auto-generated method stub
  74
+    	super.onRestoreInstanceState(savedInstanceState);
  75
+    }
  76
+    
  77
+    @Override
  78
+    protected void onResume() {
  79
+    	// TODO Auto-generated method stub
  80
+    	super.onResume();
  81
+    }
  82
+    
  83
+    @Override
  84
+    protected void onPause() {
  85
+    	// TODO Auto-generated method stub
  86
+    	super.onPause();
  87
+    	
  88
+    }
  89
+    
  90
+    @Override
  91
+    protected void onSaveInstanceState(Bundle outState) {
  92
+    	// TODO Auto-generated method stub
  93
+    	super.onSaveInstanceState(outState);
  94
+    	Bundle b = outState;
  95
+    	b.putString("CLUSTER", c.toStringData());
  96
+    }
  97
+    
  98
+    
  99
+}
41  src/org/lambertini/helpers/ClusterAdapter.java
... ...
@@ -0,0 +1,41 @@
  1
+package org.lambertini.helpers;
  2
+
  3
+import java.util.ArrayList;
  4
+import java.util.HashMap;
  5
+
  6
+import org.lambertini.*;
  7
+import org.lambertini.structures.Cluster;
  8
+import org.lambertini.structures.ClusterNode;
  9
+
  10
+import android.content.Context;
  11
+import android.widget.SimpleAdapter;
  12
+
  13
+public class ClusterAdapter {
  14
+	public static SimpleAdapter createSimpleAdapterForCluster(Cluster c, Context appContext) {
  15
+		ArrayList<HashMap<String,Object>> data = new ArrayList<HashMap<String,Object>>();
  16
+        for (int idx = 0; idx < c.getNodes().size(); idx++) {
  17
+        	ClusterNode cn = c.getNodes().get(idx);
  18
+        	HashMap<String,Object> hm = new HashMap<String, Object>();
  19
+        	hm.put("Name", cn.getName());
  20
+        	hm.put("Tech",cn.getTech());
  21
+        	hm.put("Env",cn.getEnv());
  22
+        	hm.put("Res",cn.getRes ());
  23
+        	hm.put("Aspects",cn.getCumulativeAspects());
  24
+        	hm.put("LinksTo",cn.getLinksTo(c));
  25
+        	hm.put("LinkedBy",cn.getLinkedBy(c) );
  26
+        	data.add(hm);
  27
+        }
  28
+        
  29
+        String[] from = new String[] {"Name","Tech", "Env", "Res","Aspects","LinksTo","LinkedBy"};
  30
+        int[] to = new int[] { R.id.li_Name, R.id.li_Tech, R.id.li_Env, R.id.li_Res, R.id.li_aspects, 
  31
+        		R.id.li_links_to, R.id.li_linked_by};
  32
+        SimpleAdapter sa = new SimpleAdapter (
  33
+        			appContext,
  34
+        			data,
  35
+        			R.layout.diaspora_list_item,
  36
+        			from,
  37
+        			to
  38
+        		);
  39
+		return sa;
  40
+	}
  41
+}
121  src/org/lambertini/structures/Aspect.java
... ...
@@ -0,0 +1,121 @@
  1
+package org.lambertini.structures;
  2
+
  3
+import java.io.Serializable;
  4
+
  5
+public class Aspect implements Serializable, IStringSerializable {
  6
+	private String aspect;
  7
+	private int minTech;
  8
+	private int maxTech;
  9
+	private int minEnv;
  10
+	private int maxEnv;
  11
+	private int minRes;
  12
+	private int maxRes;
  13
+	
  14
+	
  15
+	public Aspect(String aspectData) {
  16
+		setMinTech(-100);
  17
+		setMinRes(-100);
  18
+		setMinEnv(-100);
  19
+		setMaxTech(100);
  20
+		setMaxRes(100);
  21
+		setMaxEnv(100);
  22
+		
  23
+		String[] items = aspectData.split("\\|");
  24
+		aspect = items[0];
  25
+		if (items.length > 1) {
  26
+			for (int h = 1; h < items.length; h++) {
  27
+				String sItem = items[h].toUpperCase().trim();
  28
+				String[] atoms = sItem.split("\\=");
  29
+				String a1 = atoms[0].substring(0,4).trim();
  30
+				int i1 = Integer.parseInt(atoms[1].trim());
  31
+				if (a1 == "MINT") minTech = i1;
  32
+				if (a1 == "MINE") minEnv = i1;
  33
+				if (a1 == "MINR") minRes = i1;
  34
+				if (a1 == "MAXT") maxTech = i1;
  35
+				if (a1 == "MAXE") maxEnv = i1;
  36
+				if (a1 == "MAXR") maxRes = i1;
  37
+			}
  38
+		}
  39
+	}
  40
+	
  41
+	public void setAspect(String aspect1) {
  42
+		this.aspect = aspect1;
  43
+	}
  44
+	public String getAspect() {
  45
+		return aspect;
  46
+	}
  47
+
  48
+	public void setMinTech(int minTech) {
  49
+		this.minTech = minTech;
  50
+	}
  51
+
  52
+	public int getMinTech() {
  53
+		return minTech;
  54
+	}
  55
+
  56
+	public void setMaxTech(int maxTech) {
  57
+		this.maxTech = maxTech;
  58
+	}
  59
+
  60
+	public int getMaxTech() {
  61
+		return maxTech;
  62
+	}
  63
+
  64
+	public void setMinEnv(int minEnv) {
  65
+		this.minEnv = minEnv;
  66
+	}
  67
+
  68
+	public int getMinEnv() {
  69
+		return minEnv;
  70
+	}
  71
+
  72
+	public void setMaxEnv(int maxEnv) {
  73
+		this.maxEnv = maxEnv;
  74
+	}
  75
+
  76
+	public int getMaxEnv() {
  77
+		return maxEnv;
  78
+	}
  79
+
  80
+	public void setMinRes(int minRes) {
  81
+		this.minRes = minRes;
  82
+	}
  83
+
  84
+	public int getMinRes() {
  85
+		return minRes;
  86
+	}
  87
+
  88
+	public void setMaxRes(int maxRes) {
  89
+		this.maxRes = maxRes;
  90
+	}
  91
+
  92
+	public int getMaxRes() {
  93
+		return maxRes;
  94
+	}
  95
+	
  96
+	public boolean canApplyToClusterNode(ClusterNode cn) {
  97
+		boolean res = true;
  98
+		if (!(cn.getTech() >= minTech)) return false;
  99
+		if (!(cn.getEnv() >= minEnv)) return false;
  100
+		if (!(cn.getRes() >= minRes)) return false;
  101
+		if (!(cn.getTech() <= maxTech)) return false;
  102
+		if (!(cn.getEnv() <= maxEnv)) return false;
  103
+		if (!(cn.getRes() <= maxRes)) return false;
  104
+			
  105
+		return res;
  106
+	}
  107
+	
  108
+	@Override
  109
+	public String toString() {
  110
+		// TODO Auto-generated method stub
  111
+		return aspect;
  112
+//		return String.format("%s : Tech: %d,%d; Env: %d,%d; Res: %d, %d", 
  113
+//				aspect, minTech, maxTech, minEnv, maxEnv, minRes, maxRes);
  114
+	}
  115
+
  116
+	@Override
  117
+	public String toStringData() {
  118
+		// TODO Auto-generated method stub
  119
+		return this.aspect;
  120
+	}
  121
+}
154  src/org/lambertini/structures/Cluster.java
... ...
@@ -0,0 +1,154 @@
  1
+package org.lambertini.structures;
  2
+
  3
+import java.io.Serializable;
  4
+import java.util.ArrayList;
  5
+
  6
+import org.lambertini.structures.providers.AspectProvider;
  7
+import org.lambertini.structures.providers.PlaceProvider;
  8
+
  9
+public class Cluster implements Serializable, IStringSerializable {
  10
+	
  11
+	private ArrayList<ClusterNode> nodes;
  12
+	private String name;
  13
+
  14
+
  15
+	/**
  16
+	 * @return the nodes
  17
+	 */
  18
+	public ArrayList<ClusterNode> getNodes() {
  19
+		return nodes;
  20
+	}
  21
+
  22
+	public void setName(String name) {
  23
+		this.name = name;
  24
+	}
  25
+
  26
+	public String getName() {
  27
+		return name;
  28
+	}
  29
+
  30
+	public Cluster() {
  31
+		this.nodes = new ArrayList<ClusterNode>();
  32
+		name = PlaceProvider.getInstance().makeWord();
  33
+	}
  34
+	
  35
+	public Cluster(int n) {
  36
+		this.nodes = new ArrayList<ClusterNode>();
  37
+		name = PlaceProvider.getInstance().makeWord();
  38
+		for (int h = 0; h < n; h++)  
  39
+			nodes.add(new ClusterNode( PlaceProvider.getInstance().makeWord() ));
  40
+		linkClusterNodes();
  41
+		AspectProvider.getInstance().populateCluster(this);
  42
+	}
  43
+	
  44
+	public void linkClusterNodes() {
  45
+		if (nodes != null && nodes.size() > 1) {
  46
+			int w = nodes.size()-1;
  47
+			for (int h = 0; h <= w; h++) 
  48
+				nodes.get(h).clearLinks();
  49
+			for (int h = 0; h < w; h++) {
  50
+				int diceRes = Dice.getInstance().fudgeDice(4);
  51
+				ClusterNode cn = nodes.get(h);
  52
+				ClusterNode cn1; int idx_next;
  53
+				idx_next = h+1;
  54
+				linkCoupleOfClusterNodes(cn, w, h, idx_next);
  55
+				if (diceRes >= 0) {
  56
+					idx_next = h+2;
  57
+					linkCoupleOfClusterNodes(cn, w, h, idx_next);
  58
+				}
  59
+				if (diceRes > 0) {
  60
+					idx_next = h+3;
  61
+					linkCoupleOfClusterNodes(cn, w, h, idx_next);
  62
+				}
  63
+			}
  64
+		}
  65
+		checkForSlipstream();
  66
+	}
  67
+
  68
+	private void checkForSlipstream() {
  69
+		// TODO Auto-generated method stub
  70
+		boolean hasSlipStream = false;
  71
+		if (nodes != null && nodes.size() > 1) {
  72
+			for (int h = 0; h < nodes.size(); h++) {
  73
+				ClusterNode n = nodes.get(h);
  74
+				if (n.hasSlipstreamGuarantee()) {
  75
+					hasSlipStream = true;
  76
+					break;
  77
+				}
  78
+			}
  79
+			if (!hasSlipStream) {
  80
+				int idx = Dice.getInstance().roll(nodes.size());
  81
+				nodes.get(idx).setTech(2);
  82
+			}
  83
+		}
  84
+		
  85
+	}
  86
+
  87
+	private void linkCoupleOfClusterNodes(ClusterNode cnBase, int clusterSize,
  88
+			int idxBase, int idxNext) {
  89
+		ClusterNode cn1;
  90
+		if (idxNext <= clusterSize) {
  91
+			cn1 = nodes.get(idxNext);
  92
+			cnBase.getPointsTo().add(idxNext);
  93
+			cn1.getPointedBy().add(idxBase);
  94
+		}
  95
+	}
  96
+	
  97
+	@Override
  98
+	public String toString() {
  99
+		// TODO Auto-generated method stub
  100
+		StringBuilder sb = new StringBuilder();
  101
+		sb.append("Cluster " + name+"\n\n");
  102
+		for (int h = 0; h < nodes.size(); h++) {
  103
+			ClusterNode cn = nodes.get(h);
  104
+			sb.append(cn.toString()+"\n");
  105
+			if (cn.getPointsTo().size() > 0) {
  106
+				sb.append("\tPoints to:\n");
  107
+				for (int i1 = 0; i1 < cn.getPointsTo().size(); i1++) {
  108
+					ClusterNode cn2 = nodes.get(cn.getPointsTo().get(i1));
  109
+					sb.append(String.format("\t - %s\n", cn2.getName()));
  110
+				}
  111
+			}
  112
+			if (cn.getPointedBy().size() > 0) {
  113
+				sb.append("\tPointed by:\n");
  114
+				for (int i1 = 0; i1 < cn.getPointedBy().size(); i1++) {
  115
+					ClusterNode cn2 = nodes.get(cn.getPointedBy().get(i1));
  116
+					sb.append(String.format("\t - %s\n", cn2.getName()));
  117
+				}
  118
+			}
  119
+			
  120
+		}
  121
+		return sb.toString();
  122
+	}
  123
+	
  124
+	public String toHtml() {
  125
+		StringBuilder sb = new StringBuilder();
  126
+		sb.append(String.format ("<h1>%s</h1>\n", name));
  127
+		for (int h = 0; h < nodes.size(); h++)
  128
+			sb.append(nodes.get(h).toHtml());
  129
+		return sb.toString();
  130
+	}
  131
+
  132
+	@Override
  133
+	public String toStringData() {
  134
+		// TODO Auto-generated method stub
  135
+		StringBuilder sb = new StringBuilder();
  136
+		sb.append(name).append(";;");
  137
+		for (int h = 0; h < nodes.size(); h++)
  138
+			sb.append(nodes.get(h).toStringData()).append(";;");
  139
+		return sb.toString();
  140
+	}
  141
+	
  142
+	public static Cluster fromStringData(String sData) {
  143
+		String[] items = sData.split("\\;\\;");
  144
+		if (items.length > 1) {
  145
+			Cluster c = new Cluster();
  146
+			c.setName(items[0]);
  147
+			for (int h = 1; h < items.length; h++)
  148
+				c.nodes.add(ClusterNode.fromStringData(items[h]));
  149
+			return c;
  150
+		}
  151
+		return null;
  152
+		
  153
+	}
  154
+}
235  src/org/lambertini/structures/ClusterNode.java
... ...
@@ -0,0 +1,235 @@
  1
+package org.lambertini.structures;
  2
+
  3
+import java.io.Serializable;
  4
+import java.util.ArrayList;
  5
+import java.util.Collections;
  6
+
  7
+public class ClusterNode implements Serializable, IStringSerializable {
  8
+
  9
+	private String name;
  10
+	private int env;
  11
+	private int res;
  12
+	private int tech;
  13
+	
  14
+	private ArrayList<Integer> pointsTo;
  15
+	private ArrayList<Integer> pointedBy;
  16
+	private ArrayList<Aspect>  aspectList;
  17
+	
  18
+	
  19
+	private void initializeNode (String name) {
  20
+		Dice d = Dice.getInstance();
  21
+		this.env = d.fudgeDice(4);
  22
+		this.res = d.fudgeDice(4);
  23
+		this.tech = d.fudgeDice(4);
  24
+		this.setPointsTo(new ArrayList<Integer>());
  25
+		this.setPointedBy(new ArrayList<Integer>());
  26
+	}
  27
+	
  28
+	public ClusterNode() {
  29
+		this.name = "Diaspora Node";
  30
+		initializeNode(name);
  31
+		aspectList = new ArrayList<Aspect>();
  32
+	}
  33
+	
  34
+	public ClusterNode(String name) 
  35
+	{
  36
+		this.name = name;
  37
+		initializeNode(this.name);
  38
+		aspectList = new ArrayList<Aspect>();
  39
+		pointedBy = new ArrayList<Integer>();
  40
+		pointsTo = new ArrayList<Integer>();
  41
+		
  42
+	}
  43
+	
  44
+	/**
  45
+	 * @param name the name to set
  46
+	 */
  47
+	public void setName(String name) {
  48
+		this.name = name;
  49
+	}
  50
+	/**
  51
+	 * @return the name
  52
+	 */
  53
+	public String getName() {
  54
+		return name;
  55
+	}
  56
+	/**
  57
+	 * @param env the env to set
  58
+	 */
  59
+	public void setEnv(int env) {
  60
+		this.env = env;
  61
+	}
  62
+	/**
  63
+	 * @return the env
  64
+	 */
  65
+	public int getEnv() {
  66
+		return env;
  67
+	}
  68
+	/**
  69
+	 * @param res the res to set
  70
+	 */
  71
+	public void setRes(int res) {
  72
+		this.res = res;
  73
+	}
  74
+	/**
  75
+	 * @return the res
  76
+	 */
  77
+	public int getRes() {
  78
+		return res;
  79
+	}
  80
+	/**
  81
+	 * @param tech the tech to set
  82
+	 */
  83
+	public void setTech(int tech) {
  84
+		this.tech = tech;
  85
+	}
  86
+	/**
  87
+	 * @return the tech
  88
+	 */
  89
+	public int getTech() {
  90
+		return tech;
  91
+	}
  92
+
  93
+	/**
  94
+	 * @param pointsTo the pointsTo to set
  95
+	 */
  96
+	public void setPointsTo(ArrayList<Integer> pointsTo) {
  97
+		this.pointsTo = pointsTo;
  98
+	}
  99
+
  100
+	/**
  101
+	 * @return the pointsTo
  102
+	 */
  103
+	public ArrayList<Integer> getPointsTo() {
  104
+		return pointsTo;
  105
+	}
  106
+
  107
+	/**
  108
+	 * @param pointedBy the pointedBy to set
  109
+	 */
  110
+	public void setPointedBy(ArrayList<Integer> pointedBy) {
  111
+		this.pointedBy = pointedBy;
  112
+	}
  113
+
  114
+	/**
  115
+	 * @return the pointedBy
  116
+	 */
  117
+	public ArrayList<Integer> getPointedBy() {
  118
+		return pointedBy;
  119
+	}
  120
+	
  121
+	@Override
  122
+	public String toString() {
  123
+		// TODO Auto-generated method stub
  124
+		StringBuilder sb = new StringBuilder();
  125
+		for (int h = 0; h < aspectList.size(); h++) {
  126
+			sb.append("\t").append(aspectList.get(h)).append("\n");
  127
+		}
  128
+		
  129
+		return String.format("----------------------\nNode: %s, E:%d, T:%d, R:%s\nAspects:\n%s\n", 
  130
+				this.name, this.env, this.tech, this.res, sb.toString());
  131
+	}
  132
+	
  133
+	public String toHtml() {
  134
+		StringBuilder sb = new StringBuilder();
  135
+		sb.append(String.format(
  136
+				"<div class='node'>\n"+
  137
+				"<h2>%s</h2>\n"+
  138
+				"<div class='stats'>\n"+
  139
+				"<ul><li>Tech: %d</li>"+
  140
+				"<li>Env: %d</li>"+
  141
+				"<li>Res: %d</li></ul>\n"+
  142
+				"<div class='aspects'>"+
  143
+				"<ol><li>%s</li>"+
  144
+				"<li>%s</li>"+
  145
+				"<li>%s</li></ol>\n</div>\n</div>\n",
  146
+				name, tech, env, res, 
  147
+				aspectList.get(0).getAspect(), 
  148
+				aspectList.get(1).getAspect(), 
  149
+				aspectList.get(2).getAspect() ));
  150
+		return sb.toString();
  151
+	}
  152
+
  153
+	public void clearLinks() {
  154
+		// TODO Auto-generated method stub
  155
+		this.pointedBy.clear();
  156
+		this.pointsTo.clear();
  157
+	}
  158
+
  159
+
  160
+	public ArrayList<Aspect> getAspectList() {
  161
+		return aspectList;
  162
+	}
  163
+	
  164
+	public void resetAspectList() { aspectList.clear(); }
  165
+	
  166
+	public boolean hasSlipstreamGuarantee() { return this.tech >= 2; }
  167
+	
  168
+	public String getCumulativeAspects() {
  169
+		return 
  170
+			aspectList.get(0).getAspect()+"\n" +
  171
+			aspectList.get(1).getAspect()+"\n" +
  172
+			aspectList.get(2).getAspect();
  173
+	}
  174
+	
  175
+	public String getLinksTo(Cluster c) {
  176
+		String res = "";
  177
+		for (int h = 0; h < pointsTo.size(); h++)
  178
+			res += c.getNodes().get(pointsTo.get(h)).getName() + ", ";
  179
+		return res;
  180
+	}
  181
+	
  182
+	public String getLinkedBy(Cluster c) {
  183
+		String res = "";
  184
+		for (int h = 0; h < pointedBy.size(); h++)
  185
+			res += c.getNodes().get(pointedBy.get(h)).getName() + ", ";
  186
+		return res;
  187
+	}
  188
+
  189
+	@Override
  190
+	public String toStringData() {
  191
+		// TODO Auto-generated method stub
  192
+		StringBuilder sb = new StringBuilder();
  193
+		sb.append(this.name).append("|")
  194
+			.append(this.tech).append("|")
  195
+			.append(this.env).append("|")
  196
+			.append(this.res).append("|")
  197
+			.append(aspectList.get(0).toStringData()).append("|")
  198
+			.append(aspectList.get(1).toStringData()).append("|")
  199
+			.append(aspectList.get(2).toStringData()).append("|");
  200
+		for (int h = 0; h < pointsTo.size(); h++)
  201
+			sb.append(pointsTo.get(h)).append(",");
  202
+		sb.append("|");
  203
+		for (int h = 0; h < pointedBy.size(); h++)
  204
+			sb.append(pointedBy.get(h)).append(",");
  205
+		return sb.toString();
  206
+	}
  207
+	
  208
+	public static ClusterNode fromStringData(String s) {
  209
+		String[] items = s.split("\\|");
  210
+		if (items != null && items.length >= 7) {
  211
+			ClusterNode cn = new ClusterNode();
  212
+			cn.name = items[0];
  213
+			cn.tech = Integer.parseInt(items[1]);
  214
+			cn.env = Integer.parseInt(items[2]);
  215
+			cn.res = Integer.parseInt(items[3]);
  216
+			cn.aspectList.add(  new Aspect(items[4]) );
  217
+			cn.aspectList.add(  new Aspect(items[5]) );
  218
+			cn.aspectList.add(  new Aspect(items[6]) );
  219
+			if (items.length > 7) {
  220
+				String[] intItems = items[7].split("\\,");
  221
+				for (int h = 0; h < intItems.length; h++)
  222
+					if (intItems[h] != null && intItems[h].length()  > 0)
  223
+						cn.pointsTo.add(Integer.parseInt(intItems[h]));
  224
+			}
  225
+			if (items.length > 8) {
  226
+				String[] intItems = items[8].split("\\,");
  227
+				for (int h = 0; h < intItems.length; h++)
  228
+					if (intItems[h] != null && intItems[h].length()  > 0)
  229
+						cn.pointedBy.add(Integer.parseInt(intItems[h]));
  230
+			}
  231
+			return cn;
  232
+		}
  233
+		return null;
  234
+	}
  235
+}
43  src/org/lambertini/structures/Dice.java
... ...
@@ -0,0 +1,43 @@
  1
+package org.lambertini.structures;
  2
+
  3
+import java.util.Random;
  4
+import java.util.concurrent.locks.ReentrantLock;
  5
+
  6
+public class Dice {
  7
+	
  8
+	Random _rnd;
  9
+	static Dice _instance;
  10
+	
  11
+	//private constructor
  12
+	public Dice() { 
  13
+		_rnd = new Random();
  14
+	}
  15
+	
  16
+	public static Dice getInstance() {
  17
+		ReentrantLock lock = new ReentrantLock();
  18
+		lock.lock();
  19
+		try {
  20
+			if (_instance == null)
  21
+				_instance = new Dice();
  22
+		}
  23
+		finally {
  24
+			lock.unlock();
  25
+		}
  26
+		return _instance;
  27
+	}
  28
+	
  29
+	public int fudgeDice() {
  30
+		return _rnd.nextInt(3) -1;
  31
+	}
  32
+	
  33
+	public int fudgeDice(int numOfDice) {
  34
+		int res = 0;
  35
+		for (int h = 0; h < numOfDice; h++) {
  36
+			res += fudgeDice();
  37
+		}
  38
+		return res;
  39
+	}
  40
+
  41
+	public int roll(int max_num) { return _rnd.nextInt(max_num);  }
  42
+
  43
+}
5  src/org/lambertini/structures/IStringSerializable.java
... ...
@@ -0,0 +1,5 @@
  1
+package org.lambertini.structures;
  2
+
  3
+public interface IStringSerializable {
  4
+	String toStringData();
  5
+}
113  src/org/lambertini/structures/Node.java
... ...
@@ -0,0 +1,113 @@
  1
+package org.lambertini.structures;
  2
+
  3
+import java.util.ArrayList;
  4
+
  5
+public class Node {
  6
+
  7
+	private String name;
  8
+	private int env;
  9
+	private int res;
  10
+	private int tech;
  11
+	
  12
+	private ArrayList<Integer> pointsTo;
  13
+	private ArrayList<Integer> pointedBy;
  14
+	
  15
+	
  16
+	private void initializeNode (String name) {
  17
+		Dice d = Dice.getInstance();
  18
+		this.env = d.fudgeDice(4);
  19
+		this.res = d.fudgeDice(4);
  20
+		this.tech = d.fudgeDice(4);
  21
+		this.setPointsTo(new ArrayList<Integer>());
  22
+		this.setPointedBy(new ArrayList<Integer>());
  23
+	}
  24
+	
  25
+	public Node() {
  26
+		this.name = "Diaspora Node";
  27
+		initializeNode(name);
  28
+	}
  29
+	
  30
+	public Node(String name) 
  31
+	{
  32
+		this.name = name;
  33
+		initializeNode(this.name);
  34
+	}
  35
+	
  36
+	/**
  37
+	 * @param name the name to set
  38
+	 */
  39
+	public void setName(String name) {
  40
+		this.name = name;
  41
+	}
  42
+	/**
  43
+	 * @return the name
  44
+	 */
  45
+	public String getName() {
  46
+		return name;
  47
+	}
  48
+	/**
  49
+	 * @param env the env to set
  50
+	 */
  51
+	public void setEnv(int env) {
  52
+		this.env = env;
  53
+	}
  54
+	/**
  55
+	 * @return the env
  56
+	 */
  57
+	public int getEnv() {
  58
+		return env;
  59
+	}
  60
+	/**
  61
+	 * @param res the res to set
  62
+	 */
  63
+	protected void setRes(int res) {
  64
+		this.res = res;
  65
+	}
  66
+	/**
  67
+	 * @return the res
  68
+	 */
  69
+	protected int getRes() {
  70
+		return res;
  71
+	}
  72
+	/**
  73
+	 * @param tech the tech to set
  74
+	 */
  75
+	public void setTech(int tech) {
  76
+		this.tech = tech;
  77
+	}
  78
+	/**
  79
+	 * @return the tech
  80
+	 */
  81
+	public int getTech() {
  82
+		return tech;
  83
+	}
  84
+
  85
+	/**
  86
+	 * @param pointsTo the pointsTo to set
  87
+	 */
  88
+	public void setPointsTo(ArrayList<Integer> pointsTo) {
  89
+		this.pointsTo = pointsTo;
  90
+	}
  91
+
  92
+	/**
  93
+	 * @return the pointsTo
  94
+	 */
  95
+	public ArrayList<Integer> getPointsTo() {
  96
+		return pointsTo;
  97
+	}
  98
+
  99
+	/**
  100
+	 * @param pointedBy the pointedBy to set
  101
+	 */
  102
+	public void setPointedBy(ArrayList<Integer> pointedBy) {
  103
+		this.pointedBy = pointedBy;
  104
+	}
  105
+
  106
+	/**
  107
+	 * @return the pointedBy
  108
+	 */
  109
+	public ArrayList<Integer> getPointedBy() {
  110
+		return pointedBy;
  111
+	}
  112
+	
  113
+}
229  src/org/lambertini/structures/providers/AspectProvider.java
... ...
@@ -0,0 +1,229 @@
  1
+package org.lambertini.structures.providers;
  2
+
  3
+import java.util.ArrayList;
  4
+import java.util.Collection;
  5
+import java.util.Collections;
  6
+import java.util.concurrent.locks.ReentrantLock;
  7
+
  8
+import org.lambertini.structures.Aspect;
  9
+import org.lambertini.structures.Cluster;
  10
+import org.lambertini.structures.ClusterNode;
  11
+import org.lambertini.structures.Dice;
  12
+
  13
+
  14
+public class AspectProvider {
  15
+	
  16
+	static String[] ASPECT_LIST = {
  17
+		"Spacemen of all Orbitals, unite! | MAXENV=-2 | MINTECH=1",
  18
+		"This land is our land",
  19
+		"Licensed to kill",
  20
+		"Soylent Green",
  21
+		"We survived doomsday | MAXENV = -1 | MAXTECH=0",
  22
+		"Tactical Neural Implants | MINTECH = 1",
  23
+		"Green and pleasant land | MINRES=1",
  24
+		"A system made of steel | MAXTECH=1 | MAXENV=-1",
  25
+		"Heavily balkanized",
  26
+		"Computers are everywhere | MINTECH=0",
  27
+		"We are alone",
  28
+		"We are NOT alone",
  29
+		"Gods walk among us",
  30
+		"You can pry my weapon from my cold, dead hand",
  31
+		"We only live thrice",
  32
+		"Diamonds and dust | MAXTECH=-2 | MAXENV = -2",
  33
+		"No longer what we were once | MINTECH=3",
  34
+		"Bored to death",
  35
+		"The rich gets richer, the poor is getting poorer",
  36
+		"Appeasement",
  37
+		"Lebensraum!",
  38
+		"Vive la resistance!",
  39
+		"We live in the shadow of our former glory",
  40
+		"Freedom has a price we are willing to pay",
  41
+		"Waterworld",
  42
+		"Best and bravest space pilots in the cluster, period.",
  43
+		"Prison World",
  44
+		"There is something lurking in the mines",
  45
+		"This is the place in for dissent | MAXENV=-2 | MAXTECH=-1",
  46
+		"We are about to strike it big",
  47
+		"Commerce is Everything",
  48
+		"Casablanca",
  49
+		"Quarantined World | MAXENV=-2",
  50
+		"We're here on parole",
  51
+		"Soylent Green | MAXENV=-1 | MINTECH=1",
  52
+		"My cousin and I against the Stranger",
  53
+		"Freedom must be exported",
  54
+		"Trigger-happy",
  55
+		"Global Nuclear Incident | MAXENV=-1",
  56
+		"We are a warning for the universe",
  57
+		"Active militant mutant minority | MAXENV=0",
  58
+		"Remoulding ourselves in a godlike way | MINTECH=4",
  59
+		"Our Gods failed | MAXTECH=-3",
  60
+		"Tomorrow is another day",
  61
+		"Metal made flesh",
  62
+		"Life started here",
  63
+		"Moving to the stars",
  64
+		"Scared by aliens",
  65
+		"Weird animals",
  66
+		"Government hides the truth",
  67
+		"An ocean ready to explore | MAXENV=-2",
  68
+		"Untolerably high background radiation | MAXENV=-2",
  69
+		"Style over substance",
  70
+		"Drain you of your sanity / face the thing that should not be | MAXTECH=-2",
  71
+		"Sworn enemy of [[SYSTEM]]",
  72
+		"Coveted by [[SYSTEM]] and [[SYSTEM2]]",
  73
+		"We balance between [[SYSTEM]] and [[SYSTEM2]]",
  74
+		"[[SYSTEM]]'s inhabitants are our long lost brothers",
  75
+		"Living in [[SYSTEM]]'shade",
  76
+		"[[SYSTEM]] is a living example to us",
  77
+		"Them [[SYSTEM]]-ians are really depravates",
  78
+		"Be aware that [[PERSON]] is worshipped as a living deity, here.",
  79
+		"[[PERSON]] made this planet the place it is now.",
  80
+		"Little Brother [[PERSON]] runs this world with an iron fist.",
  81
+		"Never, ever mention [[PERSON]] or [[HOME]]-ians will kill you on the spot",
  82
+		"Cult of [[PERSON]]",
  83
+		"Led by that traitor named [[PERSON]]",
  84
+		"[[NAME]]-ians clergy holds all power.",
  85
+		"The Church of [[NAME]] consider this planet as its own sacred land.",
  86
+		"Land of [[CRIME]]",
  87
+		"Land of [[VICE]]",
  88
+		"Prophet [[PERSON]] left [[SYSTEM]] to preach here",
  89
+		"Land of [[GOOD]]",
  90
+		"[[CRIME]] is something of a national sport here.",
  91
+		"I warn you, these folks adore [[VICE]]",
  92
+		"Land of [[VALUABLE]]",
  93
+		"We provide [[VALUABLE]] to the whole cluster | MINTECH=2",
  94
+		"We provide [[GOOD]] to the whole cluster | MINTECH=2",
  95
+		"[[VICE]] is perfectly legal here.",
  96
+		"Don't ever think to indulge in [[VICE]]!",
  97
+		"[[PERSON]] is the king of [[VICE]]",
  98
+		"[[PERSON]] is the name to look for if you want [[GOOD]]" };
  99
+	
  100
+	
  101
+	static String[] CRIMES = 
  102
+	{
  103
+		"prostitution" , "slavery" , "drug dealing", "loansharking" , "polluting the environment" , 
  104
+		"sex" , "gluttony" , "binge drinking", "duelling", "ritual killing",
  105
+		"ritual kidnapping","moneylaundering","cheating","rigging the elections",
  106
+		"corruption","sex with foreigners","dodging taxes","orgies","binge eating"
  107
+		, "recreational drugs use" , "trash food eating parties" , "poligamy"
  108
+	};
  109
+
  110
+	static String[] VICES = {
  111
+		"dishonesty" , 
  112
+		"greed" , 
  113
+		"gluttony" , 
  114
+		"dishonor" , 
  115
+		"lying" , 
  116
+		"avarice"};
  117
+
  118
+	static String[] VIRTUES = {
  119
+		"abstinence" , 
  120
+		"courage" , 
  121
+		"stubborness" , 
  122
+		"self-sacrifice" , 
  123
+		"honor" , 
  124
+		"patriotism" , 
  125
+		"love" , 
  126
+		"friendship" , 
  127
+		"honesty"};
  128
+
  129
+	static String[] VALUABLES = {
  130
+		"gold" , "silver" , 
  131
+		"platinum" , "tantalium", 
  132
+		"rare metals" , "radioactives" , 
  133
+		"heavy metals", "methane" , 
  134
+		"brains","slaves",
  135
+		"livestock","food"};
  136
+
  137
+	static String[] GOODS = {"delikatessen" , "starships" , "weapons"
  138
+	                     , "miniaturized hi-tec products" , "cutting-edge electronical devices"
  139
+	                     , "haute-couture suits" , "liquors" , "beers" , "fusion reactors" };
  140
+
  141
+	private static AspectProvider instance;
  142
+	
  143
+	ArrayList<Aspect> aspects;
  144
+	
  145
+	private AspectProvider() {
  146
+		aspects = new ArrayList<Aspect>();
  147
+		for (int h = 0; h < ASPECT_LIST.length; h++) 
  148
+		{
  149
+			Aspect a = new Aspect(ASPECT_LIST[h]);
  150
+			aspects.add(a);
  151
+		}
  152
+	}
  153
+	
  154
+	public void populateCluster (Cluster cluster) {
  155
+		ArrayList<Integer> aDraw = new ArrayList<Integer>();
  156
+		for (int h = 0; h < ASPECT_LIST.length; h++) 
  157
+			aDraw.add(h);
  158
+		Collections.shuffle(aDraw);
  159
+		int nStart = 0;
  160
+		
  161
+		for (int h = 0; h < cluster.getNodes().size(); h++) {
  162
+			ClusterNode cn = cluster.getNodes().get(h);
  163
+			ArrayList<Integer> aList = new ArrayList<Integer>();
  164
+			for (int x = 0; x < cluster.getNodes().size(); x++)
  165
+				aList.add(x);
  166
+			aList.remove(new Integer(h));
  167
+			Collections.shuffle(aList);
  168
+			cn.resetAspectList();
  169
+			for (int w = 0; w < 3; w++) {
  170
+				Aspect a = aspects.get(aDraw.get(nStart));
  171
+				while (!a.canApplyToClusterNode(cn)) {
  172
+					nStart++;
  173
+					a = aspects.get(aDraw.get(nStart));
  174
+				}
  175
+				expandAspectTags(a,cn, cluster, aList);
  176
+				cn.getAspectList().add(a);
  177
+				nStart++;
  178
+				
  179
+			}			
  180
+		}
  181
+	}
  182
+
  183
+	private void expandAspectTags(Aspect a, ClusterNode cn, Cluster cluster, ArrayList<Integer> aList) {
  184
+		String sAspect = a.getAspect();
  185
+		sAspect = changePlaceholder(sAspect, "CRIME", CRIMES);
  186
+		sAspect = changePlaceholder(sAspect, "VICE", VICES);
  187
+		sAspect = changePlaceholder(sAspect, "VIRTUE", VIRTUES);
  188
+		sAspect = changePlaceholder(sAspect, "VALUABLE", VALUABLES);
  189
+		sAspect = changePlaceholder(sAspect, "GOOD", GOODS);
  190
+		sAspect = changePlaceholder(sAspect, "PERSON", new String[] { getPerson() });
  191
+		sAspect = changePlaceholder(sAspect, "NAME", new String[] { getName() });
  192
+		sAspect = changePlaceholder(sAspect, "HOME", new String[] { cn.getName() });
  193
+		sAspect = changePlaceholder(sAspect, "SYSTEM", new String[] { cluster.getNodes().get(aList.get(0)).getName() });
  194
+		sAspect = changePlaceholder(sAspect, "SYSTEM2", new String[] { cluster.getNodes().get(aList.get(1)).getName() });
  195
+		a.setAspect(sAspect);
  196
+	}
  197
+	
  198
+	public String getCrime() { return CRIMES[Dice.getInstance().roll(CRIMES.length)]; }
  199
+	public String getVice() { return VICES[Dice.getInstance().roll(VICES.length)]; }
  200
+	public String getVirtues() { return VIRTUES[Dice.getInstance().roll(VIRTUES.length)]; }
  201
+	public String getValuables() { return VALUABLES[Dice.getInstance().roll(VALUABLES.length)]; }
  202
+	public String getGoods() { return GOODS[Dice.getInstance().roll(GOODS.length)]; }
  203
+	public String getPerson() { 
  204
+		return PlaceProvider.getInstance().makeWord() + 
  205
+		" " + PlaceProvider.getInstance().makeWord();  
  206
+	}
  207
+	
  208
+	public String getName() { 
  209
+		return PlaceProvider.getInstance().makeWord();  
  210
+	}	
  211
+	
  212
+	private String changePlaceholder (String src, String placeHolder, String[] data) {
  213
+		return  src.replace("[["+ placeHolder.trim() + "]]", data[Dice.getInstance().roll(data.length)] ); 
  214
+	}
  215
+
  216
+	public static AspectProvider getInstance() {
  217
+		ReentrantLock lock = new ReentrantLock();
  218
+		lock.lock();
  219
+		try {
  220
+			if (instance == null)
  221
+				instance = new AspectProvider();
  222
+		}
  223
+		finally {
  224
+			lock.unlock();
  225
+		}
  226
+		return instance;
  227
+	}
  228
+	
  229
+}
98  src/org/lambertini/structures/providers/PlaceProvider.java
... ...
@@ -0,0 +1,98 @@
  1
+package org.lambertini.structures.providers;
  2
+
  3
+import java.util.concurrent.locks.ReentrantLock;
  4
+import org.lambertini.structures.Dice;
  5
+
  6
+public class PlaceProvider {
  7
+
  8
+	private static PlaceProvider instance;
  9
+	private String[] vowels = null;
  10
+	private String[] consonants = null;
  11
+	private String[] s_vowels = null;
  12
+	private String[] s_consonants = null;
  13
+	
  14
+	private PlaceProvider() {
  15
+		vowels = VOWELS.split("\\,"); 
  16
+		consonants = CONSONANTS.split("\\,");
  17
+		s_vowels = S_VOWELS.split("\\,"); 
  18
+		s_consonants = S_CONSONANTS.split("\\,");
  19
+	}
  20
+
  21
+	private static String S_CONSONANTS = "b,c,d,f,g,k,l,m,n,p,r,s,t,v,x,z";
  22
+	private static String S_VOWELS = "a,e,i,o,u";
  23
+	private static String CONSONANTS = "br,b,c,b,c,b,c,cr,d,d,d,d,d,dr,f,f,f,f,f,fr,g,g,g,gr,j,k,kh,kr,l,m,n,p,r,s,t,l,m,n,p,r,s,t,l,m,n,p,r,s,t,ts,tz,th,v,vr,x,z";
  24
+	private static String VOWELS = "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,ae,ai,au,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,ei,ea,eu,i,o,i,o,i,o,i,o,i,o,i,o,i,o,i,o,i,o,i,o,ia,ie,io,iu,oa,oe,oi,oy,ou,ua,ue,uy,y,u,u";
  25
+	
  26
+	private String getCons() {
  27
+		return consonants[Dice.getInstance().roll(consonants.length)];
  28
+	}
  29
+	
  30
+	private String getVows() {
  31
+		return vowels[Dice.getInstance().roll(vowels.length)];
  32
+	}
  33
+	
  34
+	private String getSCons() {
  35
+		return s_consonants[Dice.getInstance().roll(s_consonants.length)];
  36
+	}
  37
+	
  38
+	private String getSVows() {
  39
+		return s_vowels[Dice.getInstance().roll(s_vowels.length)];
  40
+	}
  41
+	
  42
+	private String makeSyllable() {
  43
+		String res = getCons()+ getVows();
  44
+		return res;
  45
+	}
  46
+	
  47
+	public String makeWord() {
  48
+		int x = 1+Dice.getInstance().roll(3);
  49
+		String res = "";
  50
+		for (int h = 0; h < x; h++)
  51
+			res += makeSyllable();
  52
+		if (res.length() < 3)
  53
+			res += makeSyllable();
  54
+		int df = Dice.getInstance().fudgeDice(4);
  55
+		switch (df) {
  56
+		case -4:
  57
+			res = getSVows()+res;
  58
+			break;
  59
+		case -3:
  60
+			res = getSVows()+res;
  61
+			break;
  62
+		case -2:
  63
+			res = getSVows()+res;
  64
+			break;
  65
+		case 2:
  66
+			res = res+getSCons();
  67
+			break;
  68
+		case 3:
  69
+			res = res+getSCons();
  70
+			break;
  71
+		case 4:
  72
+			res = res+getSCons();
  73
+			break;
  74
+		default:
  75
+			break;
  76
+		}
  77
+		return res.substring(0,1).toUpperCase() + res.substring(1,res.length());
  78
+			
  79
+	}
  80
+	
  81
+
  82
+	public static PlaceProvider getInstance() {
  83
+		ReentrantLock lock = new ReentrantLock();
  84
+		lock.lock();
  85
+		try {
  86
+			if (instance == null)
  87
+				instance = new PlaceProvider();
  88
+		}
  89
+		finally {
  90
+			lock.unlock();
  91
+		}
  92
+		return instance;
  93
+	}
  94
+	
  95
+	public String getPlace() {
  96
+		return "";
  97
+	}
  98
+}

No commit comments for this range

Something went wrong with that request. Please try again.