From 757f42e63a33c5935b68af1d02a02c76d475fe79 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Mon, 13 Feb 2012 20:43:04 +0000 Subject: [PATCH] could be bad (memory things) --- .../AdjactantDirectedBinaryDomainCombination.java | 4 +-- .../surfacing/BasicBinaryDomainCombination.java | 35 ++++++++++-------- .../surfacing/DirectedBinaryDomainCombination.java | 4 +-- .../src/org/forester/surfacing/SurfacingUtil.java | 37 ++++++++++++++------ .../src/org/forester/surfacing/TestSurfacing.java | 1 + 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/forester/java/src/org/forester/surfacing/AdjactantDirectedBinaryDomainCombination.java b/forester/java/src/org/forester/surfacing/AdjactantDirectedBinaryDomainCombination.java index bb3a8a9..4675e17 100644 --- a/forester/java/src/org/forester/surfacing/AdjactantDirectedBinaryDomainCombination.java +++ b/forester/java/src/org/forester/surfacing/AdjactantDirectedBinaryDomainCombination.java @@ -33,8 +33,8 @@ public class AdjactantDirectedBinaryDomainCombination extends BasicBinaryDomainC if ( ( n_terminal == null ) || ( c_terminal == null ) ) { throw new IllegalArgumentException( "attempt to create binary domain combination using null" ); } - _id_0 = n_terminal; - _id_1 = c_terminal; + _id_0 = n_terminal.getId(); + _id_1 = c_terminal.getId(); } public AdjactantDirectedBinaryDomainCombination( final String n_terminal, final String c_terminal ) { diff --git a/forester/java/src/org/forester/surfacing/BasicBinaryDomainCombination.java b/forester/java/src/org/forester/surfacing/BasicBinaryDomainCombination.java index 6861942..92f2d3c 100644 --- a/forester/java/src/org/forester/surfacing/BasicBinaryDomainCombination.java +++ b/forester/java/src/org/forester/surfacing/BasicBinaryDomainCombination.java @@ -30,30 +30,34 @@ import org.forester.util.ForesterUtil; public class BasicBinaryDomainCombination implements BinaryDomainCombination { - DomainId _id_0; - DomainId _id_1; + String _id_0; + String _id_1; + //DomainId _id_0; + //DomainId _id_1; BasicBinaryDomainCombination() { _id_0 = null; _id_1 = null; } - public BasicBinaryDomainCombination( final DomainId id_0, final DomainId id_1 ) { + public BasicBinaryDomainCombination( final String id_0, final String id_1 ) { if ( ( id_0 == null ) || ( id_1 == null ) ) { throw new IllegalArgumentException( "attempt to create binary domain combination using null" ); } - if ( id_0.compareTo( id_1 ) < 0 ) { - _id_0 = id_0; - _id_1 = id_1; + final String my_id_0 = id_0.trim(); + final String my_id_1 = id_1.trim(); + if ( my_id_0.toLowerCase().compareTo( my_id_1.toLowerCase() ) < 0 ) { + _id_0 = my_id_0; + _id_1 = my_id_1; } else { - _id_0 = id_1; - _id_1 = id_0; + _id_0 = my_id_1; + _id_1 = my_id_0; } } - public BasicBinaryDomainCombination( final String id_0, final String id_1 ) { - this( new DomainId( id_0 ), new DomainId( id_1 ) ); + public BasicBinaryDomainCombination( final DomainId id_0, final DomainId id_1 ) { + this( id_0.getId(), id_1.getId() ); } @Override @@ -94,17 +98,18 @@ public class BasicBinaryDomainCombination implements BinaryDomainCombination { @Override public DomainId getId0() { - return _id_0; + return new DomainId( _id_0 ); } @Override public DomainId getId1() { - return _id_1; + return new DomainId( _id_1 ); } @Override public int hashCode() { - return getId0().hashCode() + ( 19 * getId1().hashCode() ); + // return getId0().hashCode() + ( 19 * getId1().hashCode() ); + return ( _id_0 + _id_1 ).hashCode(); } @Override @@ -154,9 +159,9 @@ public class BasicBinaryDomainCombination implements BinaryDomainCombination { @Override public String toString() { final StringBuffer sb = new StringBuffer(); - sb.append( getId0() ); + sb.append( _id_0 ); sb.append( BinaryDomainCombination.SEPARATOR ); - sb.append( getId1() ); + sb.append( _id_1 ); return sb.toString(); } diff --git a/forester/java/src/org/forester/surfacing/DirectedBinaryDomainCombination.java b/forester/java/src/org/forester/surfacing/DirectedBinaryDomainCombination.java index c47a278..8ec5a74 100644 --- a/forester/java/src/org/forester/surfacing/DirectedBinaryDomainCombination.java +++ b/forester/java/src/org/forester/surfacing/DirectedBinaryDomainCombination.java @@ -33,8 +33,8 @@ public class DirectedBinaryDomainCombination extends BasicBinaryDomainCombinatio if ( ( n_terminal == null ) || ( c_terminal == null ) ) { throw new IllegalArgumentException( "attempt to create binary domain combination using null" ); } - _id_0 = n_terminal; - _id_1 = c_terminal; + _id_0 = n_terminal.getId(); + _id_1 = c_terminal.getId(); } public DirectedBinaryDomainCombination( final String n_terminal, final String c_terminal ) { diff --git a/forester/java/src/org/forester/surfacing/SurfacingUtil.java b/forester/java/src/org/forester/surfacing/SurfacingUtil.java index 3a9d10e..c6df0b2 100644 --- a/forester/java/src/org/forester/surfacing/SurfacingUtil.java +++ b/forester/java/src/org/forester/surfacing/SurfacingUtil.java @@ -2437,17 +2437,32 @@ public final class SurfacingUtil { try { writer.write( genome ); writer.write( "\t" ); - writer.write( stats.arithmeticMean() + "" ); - writer.write( "\t" ); - writer.write( stats.sampleStandardDeviation() + "" ); - writer.write( "\t" ); - writer.write( stats.median() + "" ); - writer.write( "\t" ); - writer.write( stats.getN() + "" ); - writer.write( "\t" ); - writer.write( stats.getMin() + "" ); - writer.write( "\t" ); - writer.write( stats.getMax() + "" ); + if ( stats.getN() >= 1 ) { + writer.write( stats.arithmeticMean() + "" ); + writer.write( "\t" ); + if ( stats.getN() >= 2 ) { + writer.write( stats.sampleStandardDeviation() + "" ); + } + else { + writer.write( "" ); + } + writer.write( "\t" ); + writer.write( stats.median() + "" ); + writer.write( "\t" ); + writer.write( stats.getN() + "" ); + writer.write( "\t" ); + writer.write( stats.getMin() + "" ); + writer.write( "\t" ); + writer.write( stats.getMax() + "" ); + } + else { + writer.write( "\t" ); + writer.write( "\t" ); + writer.write( "\t" ); + writer.write( "0" ); + writer.write( "\t" ); + writer.write( "\t" ); + } writer.write( "\n" ); } catch ( final IOException e ) { diff --git a/forester/java/src/org/forester/surfacing/TestSurfacing.java b/forester/java/src/org/forester/surfacing/TestSurfacing.java index 56bb6fa..8301b9b 100644 --- a/forester/java/src/org/forester/surfacing/TestSurfacing.java +++ b/forester/java/src/org/forester/surfacing/TestSurfacing.java @@ -1594,6 +1594,7 @@ public class TestSurfacing { final BasicBinaryDomainCombination s8 = new BasicBinaryDomainCombination( "b", "d" ); final BinaryDomainCombination s9 = BasicBinaryDomainCombination.createInstance( " z-z=a-aa " ); if ( !s9.toString().equals( "a-aa=z-z" ) ) { + System.out.println( s9.toString() ); return false; } if ( !s0.equals( s0 ) ) { -- 1.7.10.2