AMAPstudio

User Tools


How to use Capsis groupers in source code (e.g. to group trees)

Capsis comes with a grouping system, mainly used from the graphical user interface, to make groups of trees cells, to track some properties of a specific set of elements. Groups can be prepared with the Group Definer, they are stored in the Group Catalog, then can be used in the graphs and viewers.

The capsis groupers may also be used in the source code.

An overview of the Capsis grouper framework

Here is an example showing how to use a grouper to select a subset of elements with a given list of ids.

package sandbox;
 
import java.util.ArrayList;
import java.util.Collection;
 
import jeeb.lib.util.AmapTools;
import jeeb.lib.util.Identifiable;
import capsis.extension.filter.general.FIndividualSelector;
import capsis.extensiontype.Filter;
import capsis.util.Filtrer;
import capsis.util.Identifier;
 
/**
 * A test class for the Capsis groupers
 * 
 * <pre>
 * # Under Linux, from the Capsis4 install dir:
 * java -cp class:ext/* sandbox.GrouperTest
 * </pre>
 * 
 * @author F. de Coligny - August 2014
 */
public class GrouperTest {
 
	// An identifiable element
	static private class Element implements Identifiable {
		private int id;
 
		public Element(int id) {
			this.id = id;
		}
 
		@Override
		public int getId() {
			return id;
		}
 
		public String toString() {
			return "Element:" + id;
		}
	}
 
	// Test method
	public static void main(String[] args) {
 
		// A collection of elements
		Collection<Element> elements = new ArrayList<Element>();
		elements.add(new Element(1));
		elements.add(new Element(2));
		elements.add(new Element(3));
		elements.add(new Element(4));
		elements.add(new Element(5));
 
		// A collection of ids
		Collection ids = new ArrayList();
		ids.add(2);
		ids.add(4);
		ids.add(5);
 
		// 1. A grouper
		Identifier g1 = new Identifier("g1", "Integer", ids);
 
		// Use the grouper
		System.out.println("g1: " + AmapTools.toString(g1.apply(elements)));
 
		// Get the complementary
		boolean complementary = true;
		System.out.println("not(g1): " + AmapTools.toString(g1.apply(elements, complementary)));
 
		// 2. Alternative use, with a Filter
		Filter f1 = new FIndividualSelector(ids);
		Filtrer g2 = new Filtrer("g2", "Integer", f1);
 
		// Use the grouper
		System.out.println("g2: " + AmapTools.toString(g2.apply(elements)));
 
	}
 
}
coligny@marvin-13:~/workspace/capsis4$ sh ant compile
Buildfile: build.xml

revision:
     [echo] Capsis revision 8605
     [echo] os.name: Linux
     [echo] os.arch: amd64
     [echo] java.version: Java HotSpot(TM) 64-Bit Server VM 1.7.0_51

filter:

copy-resources:

compile:

BUILD SUCCESSFUL
Total time: 2 seconds
coligny@marvin-13:~/workspace/capsis4$ java -cp class:ext/* sandbox.GrouperTest 
g1: Element:2, Element:4, Element:5
not(g1): Element:1, Element:3
g2: Element:2, Element:4, Element:5
coligny@marvin-13:~/workspace/capsis4$ 
how_to_use_capsis_groupers_in_source_code_e.g._to_group_trees.txt ยท Last modified: 2014/08/11 10:09 by coligny