Author: mes
Date: 2008-09-12 22:52:31 -0700 (Fri, 12 Sep 2008)
New Revision: 14905
Added:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyDataTable.java
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyDataTableFactory.java
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyFunction.java
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyRow.java
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/impl/CyDataTableImpl.java
Modified:
csplugins/trunk/ucsd/mes/api/pom.xml
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/network/CyNetwork.java
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/network/CyNode.java
Log:
added CyDataTable and initial impl
Modified: csplugins/trunk/ucsd/mes/api/pom.xml
===================================================================
--- csplugins/trunk/ucsd/mes/api/pom.xml 2008-09-12 17:01:25 UTC (rev
14904)
+++ csplugins/trunk/ucsd/mes/api/pom.xml 2008-09-13 05:52:31 UTC (rev
14905)
@@ -105,7 +105,8 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
- <threshold>Normal</threshold>
+ <threshold>Low</threshold>
+ <effort>Max</effort>
</configuration>
</plugin>
<plugin>
Added:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyDataTable.java
===================================================================
---
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyDataTable.java
2008-09-12 17:01:25 UTC (rev 14904)
+++
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyDataTable.java
2008-09-13 05:52:31 UTC (rev 14905)
@@ -0,0 +1,41 @@
+package org.cytoscape.model.attrs;
+
+import java.util.Map;
+import java.util.List;
+
+/**
+ *
+ */
+public interface CyDataTable {
+
+ public boolean isPublic();
+
+ public String getName();
+
+ /**
+ */
+ public Map<String,Class<?>> getColumnTypeMap();
+
+
+ /**
+ * @param attributeName The name identifying the attribute.
+ */
+ public void deleteColumn(String attributeName);
+
+ /**
+ * @param attributeName The name identifying the column.
+ * @param type The type associated with the column.
+ * @param unique Whether the entries in the column are unique.
+ */
+ public <T> void createColumn(String attributeName, Class<? extends T>
type, boolean unique);
+
+ public List<String> getUniqueColumns();
+
+ public <T> List<? extends T> getColumnValues(String columnName, Class<?
extends T> type);
+
+ public CyRow getRow(long index);
+
+ public CyRow addRow();
+
+ public static final String PRIMARY_KEY = "AID";
+}
Added:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyDataTableFactory.java
===================================================================
---
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyDataTableFactory.java
2008-09-12 17:01:25 UTC (rev 14904)
+++
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyDataTableFactory.java
2008-09-13 05:52:31 UTC (rev 14905)
@@ -0,0 +1,9 @@
+package org.cytoscape.model.attrs;
+
+import java.util.List;
+
+public interface CyDataTableFactory {
+ CyDataTable createTable(String name, boolean pub);
+ List<String> getAllTableNames(boolean includePrivate);
+}
+
Added:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyFunction.java
===================================================================
---
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyFunction.java
2008-09-12 17:01:25 UTC (rev 14904)
+++
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyFunction.java
2008-09-13 05:52:31 UTC (rev 14905)
@@ -0,0 +1,8 @@
+package org.cytoscape.model.attrs;
+
+public interface CyFunction<T> {
+ Class<T> getBaseType();
+ T getValue();
+ String getFunction();
+ void setFunction(String s);
+}
Added:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyRow.java
===================================================================
---
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyRow.java
2008-09-12 17:01:25 UTC (rev 14904)
+++
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/CyRow.java
2008-09-13 05:52:31 UTC (rev 14905)
@@ -0,0 +1,12 @@
+package org.cytoscape.model.attrs;
+
+import java.util.Map;
+
+public interface CyRow {
+ public <T> T get(String columnName, Class<? extends T> type);
+ public <T> void set(String columnName, T value);
+ public Class<?> contains(String columnName);
+ public <T> boolean contains(String columnName,Class<? extends T> type);
+ public Map<String,Object> getAllValues();
+}
+
Added:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/impl/CyDataTableImpl.java
===================================================================
---
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/impl/CyDataTableImpl.java
2008-09-12 17:01:25 UTC (rev 14904)
+++
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/impl/CyDataTableImpl.java
2008-09-13 05:52:31 UTC (rev 14905)
@@ -0,0 +1,252 @@
+package org.cytoscape.model.attrs.impl;
+
+import java.util.*;
+import org.cytoscape.model.attrs.CyRow;
+import org.cytoscape.model.attrs.CyDataTable;
+
+public class CyDataTableImpl implements CyDataTable {
+
+ private Map<String, Map<Long, Object>> attributes;
+ private Map<String, Class<?>> types;
+ private Map<String, Boolean> unique;
+ private String name;
+ private boolean pub;
+
+ public boolean isPublic() {
+ return pub;
+ }
+ public String getName() {
+ return name;
+ }
+
+ public CyDataTableImpl(Map<String,Class<?>> typeMap, String name,
boolean pub) {
+ this.name = name;
+ this.pub = pub;
+ attributes = new HashMap<String,Map<Long,Object>>();
+ if ( typeMap == null )
+ types = new HashMap<String,Class<?>>();
+ else {
+ types = new HashMap<String,Class<?>>(typeMap);
+ for ( String key : typeMap.keySet() )
+ attributes.put( key, new HashMap<Long,Object>()
);
+ }
+ }
+
+ public Map<String,Class<?>> getColumnTypeMap() {
+ return new HashMap<String,Class<?>>(types);
+ }
+
+
+ public void deleteColumn(String attributeName) {
+ if ( attributes.containsKey(attributeName) ) {
+ attributes.remove( attributeName );
+ types.remove( attributeName );
+ }
+ }
+
+ public <T> void createColumn(String attributeName, Class<? extends T>
type, boolean u) {
+ if ( attributeName == null )
+ throw new NullPointerException("attribute name is
null");
+ if ( type == null )
+ throw new NullPointerException("type is null");
+
+ Class cls = getClass(type);
+
+ Class curr = types.get( attributeName );
+ if ( curr == null ) {
+ types.put( attributeName, cls );
+ attributes.put( attributeName, new
HashMap<Long,Object>() );
+ unique.put(attributeName, u);
+ } else {
+ if ( !curr.equals( cls ) )
+ throw new IllegalArgumentException("attribute
already exists for name: " +
+
attributeName + " with type: " + cls.getName());
+ }
+ }
+
+ public List<String> getUniqueColumns() {
+ List<String> l = new ArrayList<String>();
+ for ( String s : unique.keySet() ) {
+ if ( unique.get(s) )
+ l.add(s);
+ }
+ return l;
+ }
+
+ public <T> List<? extends T> getColumnValues(String columnName, Class<?
extends T> type) {
+ if ( columnName == null )
+ throw new NullPointerException("column name is null");
+ Map<Long,Object> vals = attributes.get(columnName);
+ if ( vals == null )
+ throw new NullPointerException("attribute does not
exist");
+
+ List<T> l = new ArrayList<T>( vals.size() );
+ for ( Object o : vals.values() )
+ l.add( type.cast(o) );
+
+ return l;
+ }
+
+ public CyRow getRow(final long suid) {
+ return new Access(suid);
+ }
+
+ public CyRow addRow() {
+ return null;
+ }
+
+ // internal methods
+
+ private void removeX(long suid, String attributeName) {
+ if ( attributes.containsKey(attributeName) ) {
+ Map<Long,Object> map = attributes.get(attributeName);
+ if ( map.containsKey( suid ) )
+ map.remove( suid );
+ }
+ }
+
+ private void setX(long suid, String attrName, Object value) {
+ if ( value == null )
+ throw new NullPointerException("value is null");
+
+ if ( !types.containsKey(attrName) ||
!attributes.containsKey(attrName) )
+ throw new IllegalArgumentException("attribute does not
yet exist!");
+
+ checkType(value);
+
+ Map<Long,Object> vls = attributes.get(attrName);
+
+ if ( types.get( attrName ).isAssignableFrom( value.getClass() )
)
+ vls.put(suid,value);
+ else
+ throw new IllegalArgumentException("value is not of
type: " + types.get(attrName));
+ }
+
+ private <T> T getX(long suid, String attrName, Class<? extends T> type)
{
+ Map<Long,Object> vls = attributes.get(attrName);
+
+ if (vls == null)
+ return null;
+
+ Object vl = vls.get(suid);
+
+ if (vl == null)
+ return null;
+
+ return type.cast(vl);
+ }
+
+ private <T> boolean containsX(long suid, String attrName, Class<?
extends T> type) {
+ Map<Long,Object> vls = attributes.get(attrName);
+
+ if (vls == null)
+ return false;
+
+ Object vl = vls.get(suid);
+
+ if (vl == null)
+ return false;
+
+ if ( types.get(attrName).isAssignableFrom(type) )
+ return true;
+ else
+ return false;
+ }
+
+ private Class<?> containsX(long suid, String attrName) {
+ Map<Long,Object> vls = attributes.get(attrName);
+
+ if (vls == null)
+ return null;
+
+ Object vl = vls.get(suid);
+
+ if (vl == null)
+ return null;
+ else
+ return types.get(attrName);
+ }
+
+ private Class<?> getClass(Class<?> c) {
+ if ( Integer.class.isAssignableFrom( c ) )
+ return Integer.class;
+ else if ( Double.class.isAssignableFrom( c ) )
+ return Double.class;
+ else if ( Boolean.class.isAssignableFrom( c ) )
+ return Boolean.class;
+ else if ( String.class.isAssignableFrom( c ) )
+ return String.class;
+ else if ( List.class.isAssignableFrom( c ) )
+ return List.class;
+ else if ( Map.class.isAssignableFrom( c ) )
+ return Map.class;
+ else
+ throw new IllegalArgumentException("invalid class: " +
c.getName());
+ }
+
+
+ private void checkType(Object o) {
+ if ( o instanceof String )
+ return;
+ else if ( o instanceof Integer )
+ return;
+ else if ( o instanceof Boolean )
+ return;
+ else if ( o instanceof Double )
+ return;
+ else if ( o instanceof List ) {
+ List l = (List)o;
+ if ( l.size() <= 0 )
+ throw new RuntimeException("empty list");
+ else
+ checkType(l.get(0));
+ } else if ( o instanceof Map ) {
+ Map m = (Map)o;
+ Object[] keys = m.keySet().toArray();
+ if ( keys.length <= 0 ) {
+ throw new RuntimeException("empty map");
+ } else {
+ checkType(m.get(keys[0]));
+ checkType(keys[0]);
+ }
+ } else
+ throw new RuntimeException("invalid type: " +
o.getClass().toString() );
+ }
+
+
+ private class Access implements CyRow {
+
+ private final long suid;
+
+ Access(long suid) {
+ this.suid = suid;
+ }
+
+ public void set(String attributeName, Object value) {
+ setX(suid,attributeName,value);
+ }
+
+ public <T> T get(String attributeName, Class<? extends T> c) {
+ return getX(suid,attributeName,c);
+ }
+
+ public <T> boolean contains(String attributeName, Class<?
extends T> c) {
+ return containsX(suid,attributeName,c);
+ }
+
+ public Class<?> contains(String attributeName) {
+ return containsX(suid,attributeName);
+ }
+
+ public void remove(String attributeName) {
+ removeX(suid,attributeName);
+ }
+
+ public Map<String,Object> getAllValues() {
+ Map<String,Object> m = new HashMap<String,Object>(
attributes.size() );
+ for ( String attr : attributes.keySet() )
+ m.put( attr, attributes.get(attr).get(suid) );
+ return m;
+ }
+ }
+}
Modified:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/network/CyNetwork.java
===================================================================
---
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/network/CyNetwork.java
2008-09-12 17:01:25 UTC (rev 14904)
+++
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/network/CyNetwork.java
2008-09-13 05:52:31 UTC (rev 14905)
@@ -4,7 +4,20 @@
import java.util.Map;
import org.cytoscape.model.attrs.CyAttributes;
import org.cytoscape.model.attrs.CyAttributesManager;
+/*
+public interface CyRootNetwork extends CyNetwork {
+ public List<CyNode> getAllNodes();
+ public List<CyEdge> getAllEdges();
+ public CyNode createMetaNode( List<CyNode> nodes );
+ public List<CySubNetwork> getAllSubNetworks();
+}
+public interface CySubNetwork extends CyNetwork {
+ public CyNode getParentNode();
+ public void copyToNetwork( CyNode node );
+ public void removeFromNetwork( CyNode node );
+}
+*/
public interface CyNetwork extends Identifiable, GraphObject {
public CyNode addNode();
@@ -34,19 +47,24 @@
* Access to network specific attributes.
*/
public CyAttributes getCyAttributes(String namespace);
+// public CyRow getCyRow(String namespace);
+// public CyRow attrs(); // same as getCyRow("USERS")
/**
* Defines the attributes available for the CyNetwork.
*/
+ //public Map<String,? extends CyDataTable> getNetworkCyDataTables();
public Map<String,? extends CyAttributesManager>
getNetworkCyAttributesManagers();
/**
* Defines the attributes available for all of the CyNode objects in
the CyNetwork.
*/
+// public Map<String,? extends CyDataTable> getNodeCyDataTables();
public Map<String,? extends CyAttributesManager>
getNodeCyAttributesManagers();
/**
* Defines the attributes available for all of the CyEdge objects in
the CyNetwork.
*/
+// public Map<String,? extends CyDataTable> getEdgeCyDataTables();
public Map<String,? extends CyAttributesManager>
getEdgeCyAttributesManagers();
}
Modified:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/network/CyNode.java
===================================================================
---
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/network/CyNode.java
2008-09-12 17:01:25 UTC (rev 14904)
+++
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/network/CyNode.java
2008-09-13 05:52:31 UTC (rev 14905)
@@ -2,7 +2,11 @@
package org.cytoscape.model.network;
import java.util.List;
-
+/*
+public interface CyMetaNode extends CyNode {
+ public CyNetwork getChildNetwork();
+}
+*/
public interface CyNode extends GraphObject {
public int getIndex();
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---