Author: ruschein
Date: 2011-07-26 09:20:59 -0700 (Tue, 26 Jul 2011)
New Revision: 26267
Modified:
core3/model-api/trunk/src/main/java/org/cytoscape/model/CyTable.java
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
Log:
Added a swap() method to CyTable.
Modified: core3/model-api/trunk/src/main/java/org/cytoscape/model/CyTable.java
===================================================================
--- core3/model-api/trunk/src/main/java/org/cytoscape/model/CyTable.java
2011-07-26 13:48:18 UTC (rev 26266)
+++ core3/model-api/trunk/src/main/java/org/cytoscape/model/CyTable.java
2011-07-26 16:20:59 UTC (rev 26267)
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2008, 2010, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2008, 2010-2011, 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
@@ -219,4 +219,11 @@
* @param policy the policy to follow during the lifecycle of the
CyTable.
*/
void setSavePolicy(SavePolicy policy);
+
+ /** Swaps the contents and properties, like mutability etc. of
"otherTable" with this table.
+ * @param otherTable the table that we're being swapped with.
+ * Note: the one "property" that is not being swapped is the SUID!
Also, no events are being
+ * fired to give any listners a chance to react to the exchange!
+ */
+ void swap(CyTable otherTable);
}
Modified:
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
===================================================================
---
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
2011-07-26 13:48:18 UTC (rev 26266)
+++
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
2011-07-26 16:20:59 UTC (rev 26267)
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2008, 2010, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2008, 2010-2011, 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
@@ -864,4 +864,17 @@
List res = attrs.get("simpson",List.class);
assertEquals(ls,res);
}
+
+ @Test
+ public void testSwap() {
+ table.createColumn("someInt", Integer.class, false);
+ table2.createColumn("someOtherInt", Integer.class, false);
+ final String title = table.getTitle();
+ final String title2 = table2.getTitle();
+ table.swap(table2);
+ assertEquals(title, table2.getTitle());
+ assertEquals(title2, table.getTitle());
+ assertNotNull(table.getColumn("someOtherInt"));
+ assertNotNull(table2.getColumn("someInt"));
+ }
}
Modified:
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
---
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2011-07-26 13:48:18 UTC (rev 26266)
+++
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2011-07-26 16:20:59 UTC (rev 26267)
@@ -57,33 +57,33 @@
public final class CyTableImpl implements CyTable {
private static final Logger logger =
LoggerFactory.getLogger(CyTableImpl.class);
- private final Set<String> currentlyActiveAttributes;
- private final Map<String, Map<Object, Object>> attributes; // Maps
column names to (key,value) pairs, where "key" is the primary key.
- private final Map<String, Map<Object, Set<Object>>> reverse;
- private final Map<Object, CyRow> rows; // Maps the primary key to CyRow.
+ private Set<String> currentlyActiveAttributes;
+ private Map<String, Map<Object, Object>> attributes; // Maps column
names to (key,value) pairs, where "key" is the primary key.
+ private Map<String, Map<Object, Set<Object>>> reverse;
+ private Map<Object, CyRow> rows; // Maps the primary key to CyRow.
- private final Map<String, CyColumn> types;
+ private Map<String, CyColumn> types;
// This is not unique and might be changed by user.
private String title;
// Visibility value is immutable.
- private final boolean pub;
+ private boolean pub;
- private final boolean isImmutable;
+ private boolean isImmutable;
// Unique ID.
private final long suid;
// name of the primary key column
- private final String primaryKey;
+ private String primaryKey;
private final CyEventHelper eventHelper;
private final Interpreter interpreter;
String lastInternalError = null;
- private final Map<String, VirtualColumn> virtualColumnMap;
+ private Map<String, VirtualColumn> virtualColumnMap;
private int virtualColumnReferenceCount;
private SavePolicy savePolicy;
@@ -125,6 +125,63 @@
virtualColumnReferenceCount = 0;
}
+ @Override
+ public synchronized void swap(final CyTable otherTable) {
+ final CyTableImpl other = (CyTableImpl)otherTable;
+
+ final Set<String> tempCurrentlyActiveAttributes =
currentlyActiveAttributes;
+ currentlyActiveAttributes = other.currentlyActiveAttributes;
+ other.currentlyActiveAttributes = tempCurrentlyActiveAttributes;
+
+ final Map<String, Map<Object, Object>> tempAttributes =
attributes;
+ attributes = other.attributes;
+ other.attributes = attributes;
+
+ final Map<String, Map<Object, Set<Object>>> tempReverse =
reverse;
+ reverse = other.reverse;
+ other.reverse = tempReverse;
+
+ final Map<Object, CyRow> tempRows = rows;
+ rows = other.rows;
+ other.rows = tempRows;
+
+ final Map<String, CyColumn> tempTypes = types;
+ types = other.types;
+ other.types = tempTypes;
+
+ final String tempTitle = title;
+ title = other.title;
+ other.title = tempTitle;
+
+ final boolean tempPub = pub;
+ pub = other.pub;
+ other.pub = tempPub;
+
+ final boolean tempIsImmutable = isImmutable;
+ isImmutable = other.isImmutable;
+ other.isImmutable = tempIsImmutable;
+
+ final String tempPrimaryKey = primaryKey;
+ primaryKey = other.primaryKey;
+ other.primaryKey = tempPrimaryKey;
+
+ final String tempLastInternalError= lastInternalError;
+ lastInternalError = other.lastInternalError;
+ other.lastInternalError = tempLastInternalError;
+
+ final Map<String, VirtualColumn> tempVirtualColumnMap =
virtualColumnMap;
+ virtualColumnMap = other.virtualColumnMap;
+ other.virtualColumnMap = tempVirtualColumnMap;
+
+ final int tempVirtualColumnReferenceCount =
virtualColumnReferenceCount;
+ virtualColumnReferenceCount = other.virtualColumnReferenceCount;
+ other.virtualColumnReferenceCount =
tempVirtualColumnReferenceCount;
+
+ final SavePolicy tempSavePolicy = savePolicy;
+ savePolicy = other.savePolicy;
+ other.savePolicy = tempSavePolicy;
+ }
+
void updateColumnName(final String oldColumnName, final String
newColumnName) {
if (oldColumnName.equals(newColumnName))
return;
--
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.