Author: mes
Date: 2010-10-01 17:10:43 -0700 (Fri, 01 Oct 2010)
New Revision: 22133

Added:
   
core3/session-api/trunk/src/test/java/org/cytoscape/session/CySessionTest.java
Removed:
   
core3/session-api/trunk/src/test/java/org/cytoscape/session/AbstractCySessionTest.java
Modified:
   core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java
Log:
made CySession a final class constructed using the Builder pattern rather than 
an interface

Modified: 
core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java
===================================================================
--- core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java  
2010-10-01 23:56:15 UTC (rev 22132)
+++ core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java  
2010-10-02 00:10:43 UTC (rev 22133)
@@ -1,39 +1,161 @@
+
+/*
+ Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
 package org.cytoscape.session;
 
-import java.util.Map;
+import org.cytoscape.session.CySession;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.vizmap.VisualStyle;
 import java.util.Properties;
 import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
 import java.util.List;
 import java.io.File;
 
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyTable;
-import org.cytoscape.view.model.CyNetworkView;
-import org.cytoscape.view.vizmap.VisualStyle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-/**
- * A session is an immutable snapshot of the data contents of Cytoscape.
- * Sessions are only meant for saving and restoring the state of Cytoscape
- * and are not meant to be used interactively for anything besides 
- * writing, reading, and restoring from session files.
- * <br/>
- * Using the data returned from the various methods in a CySession object
- * should be sufficient to recreate all aspects of Cytoscape at the time
- * the session was created.
- */
-public interface CySession {
 
-    Set<CyNetworkView> getNetworkViews();
+public final class CySession {
 
-    Set<CyTable> getTables();
+       private final Set<CyNetworkView> netViews;
+       private final Set<CyTable> tables;
+       private final Map<CyNetworkView,String> vsMap;
+       private final Properties cyProps;
+       private final Properties vProps;
+       private final Properties dProps;
+       private final Map<String, List<File>> pluginFiles;
 
-       Map<CyNetworkView,String> getViewVisualStyleMap();
+       private static final Logger logger = 
LoggerFactory.getLogger(CySession.class);
 
-    Properties getCytoscapeProperties();
+       private CySession(Builder b) {
+               // TODO consider making defensive copies of objects...
 
-    Properties getVizmapProperties();
+               if ( b.netViews == null )
+                       netViews = new HashSet<CyNetworkView>();
+               else
+                       netViews = b.netViews;
 
-    Properties getDesktopProperties();
+               if ( b.tables == null )
+                       tables = new HashSet<CyTable>();
+               else 
+                       tables = b.tables;
 
-       Map<String, List<File>> getPluginFileListMap();
+               if ( b.vsMap == null )
+                       vsMap = new HashMap<CyNetworkView,String>();
+               else
+                       vsMap = b.vsMap;
+
+               if ( b.cyProps == null )
+                       cyProps = new Properties();
+               else
+                       cyProps = b.cyProps;
+
+               if ( b.vProps == null )
+                       vProps = new Properties();
+               else
+                       vProps = b.vProps;
+
+               if ( b.dProps == null )
+                       dProps = new Properties();
+               else
+                       dProps = b.dProps;
+
+               if ( b.pluginFiles == null )
+                       pluginFiles = new HashMap<String, List<File>>(); 
+               else
+                       pluginFiles = b.pluginFiles;
+       }
+
+       public static class Builder {
+
+               private Set<CyNetworkView> netViews; 
+               private Set<CyTable> tables;
+               private Map<CyNetworkView,String> vsMap; 
+               private Properties cyProps;
+               private Properties vProps; 
+               private Properties dProps;
+               private Map<String, List<File>> pluginFiles; 
+
+               public CySession build() { return new CySession(this); }
+
+               public Builder networkViews(final Set<CyNetworkView> views) { 
+                       netViews = views; 
+                       return this;
+               }
+
+       public Builder tables(final Set<CyTable> t) { 
+                       tables = t; 
+                       return this;
+               }
+
+       public Builder viewVisualStyleMap(final  Map<CyNetworkView,String> vs) 
{ 
+                       vsMap = vs; 
+                       return this;
+               }
+
+       public Builder cytoscapeProperties(final Properties p) { 
+                       cyProps = p; 
+                       return this;
+               }
+
+       public Builder vizmapProperties(final Properties p) { 
+                       vProps = p; 
+                       return this;
+               }
+
+       public Builder desktopProperties(final Properties p) { 
+                       dProps = p; 
+                       return this;
+               }
+
+               public Builder pluginFileListMap(final Map<String, List<File>> 
p) { 
+                       this.pluginFiles = p; 
+                       return this;
+               }
+       }
+
+    public Set<CyNetworkView> getNetworkViews() { return netViews; }
+
+    public Set<CyTable> getTables() { return tables; }
+
+    public Map<CyNetworkView,String> getViewVisualStyleMap() { return vsMap; }
+
+    public Properties getCytoscapeProperties() { return cyProps; }
+
+    public Properties getVizmapProperties() { return vProps; }
+
+    public Properties getDesktopProperties() { return dProps; }
+
+       public Map<String, List<File>> getPluginFileListMap() { return 
pluginFiles; }
 }
+
+

Deleted: 
core3/session-api/trunk/src/test/java/org/cytoscape/session/AbstractCySessionTest.java
===================================================================
--- 
core3/session-api/trunk/src/test/java/org/cytoscape/session/AbstractCySessionTest.java
      2010-10-01 23:56:15 UTC (rev 22132)
+++ 
core3/session-api/trunk/src/test/java/org/cytoscape/session/AbstractCySessionTest.java
      2010-10-02 00:10:43 UTC (rev 22133)
@@ -1,55 +0,0 @@
-package org.cytoscape.session;
-
-import static org.junit.Assert.*;
-
-import org.cytoscape.session.CySession;
-import org.junit.Before;
-import org.junit.Test;
-
-public abstract class AbstractCySessionTest {
-
-
-       protected CySession session;
-
-       @Test
-       public void testGetNetworkViews() {
-               assertNotNull(session);
-               assertNotNull(session.getNetworkViews());
-       }
-
-       @Test
-       public void testGetTables() {
-               assertNotNull(session);
-               assertNotNull(session.getTables());
-       }
-       
-       @Test
-       public void testGetViewVisualStyleMap() {
-               assertNotNull(session);
-               assertNotNull(session.getViewVisualStyleMap());
-       }
-       
-       @Test
-       public void testGetCytoscapeProperties() {
-               assertNotNull(session);
-               assertNotNull(session.getCytoscapeProperties());
-       }
-
-       @Test
-       public void testGetVizmapProperties() {
-               assertNotNull(session);
-               assertNotNull(session.getVizmapProperties());
-       }
-
-       @Test
-       public void testGetDesktopProperties() {
-               assertNotNull(session);
-               assertNotNull(session.getDesktopProperties());
-       }
-
-       @Test
-       public void testGetPluginFileListMap() {
-               assertNotNull(session);
-               assertNotNull(session.getPluginFileListMap());
-       }
-}

Copied: 
core3/session-api/trunk/src/test/java/org/cytoscape/session/CySessionTest.java 
(from rev 22120, 
core3/session-api/trunk/src/test/java/org/cytoscape/session/AbstractCySessionTest.java)
===================================================================
--- 
core3/session-api/trunk/src/test/java/org/cytoscape/session/CySessionTest.java  
                            (rev 0)
+++ 
core3/session-api/trunk/src/test/java/org/cytoscape/session/CySessionTest.java  
    2010-10-02 00:10:43 UTC (rev 22133)
@@ -0,0 +1,60 @@
+package org.cytoscape.session;
+
+import static org.junit.Assert.*;
+
+import org.cytoscape.session.CySession;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CySessionTest {
+
+
+       protected CySession session;
+
+       @Before
+       public void setUp() {
+               session = new CySession.Builder().build();
+       }
+
+       @Test
+       public void testGetNetworkViews() {
+               assertNotNull(session);
+               assertNotNull(session.getNetworkViews());
+       }
+
+       @Test
+       public void testGetTables() {
+               assertNotNull(session);
+               assertNotNull(session.getTables());
+       }
+       
+       @Test
+       public void testGetViewVisualStyleMap() {
+               assertNotNull(session);
+               assertNotNull(session.getViewVisualStyleMap());
+       }
+       
+       @Test
+       public void testGetCytoscapeProperties() {
+               assertNotNull(session);
+               assertNotNull(session.getCytoscapeProperties());
+       }
+
+       @Test
+       public void testGetVizmapProperties() {
+               assertNotNull(session);
+               assertNotNull(session.getVizmapProperties());
+       }
+
+       @Test
+       public void testGetDesktopProperties() {
+               assertNotNull(session);
+               assertNotNull(session.getDesktopProperties());
+       }
+
+       @Test
+       public void testGetPluginFileListMap() {
+               assertNotNull(session);
+               assertNotNull(session.getPluginFileListMap());
+       }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to