]> source.dussan.org Git - jackcess.git/commitdiff
revamp tostring output
authorJames Ahlborn <jtahlborn@yahoo.com>
Mon, 9 Sep 2013 03:06:40 +0000 (03:06 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Mon, 9 Sep 2013 03:06:40 +0000 (03:06 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@794 f203690c-595d-4dc9-a70b-905162fa7fd2

12 files changed:
src/main/java/com/healthmarketscience/jackcess/impl/ByteUtil.java
src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java
src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java [new file with mode: 0644]
src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java
src/main/java/com/healthmarketscience/jackcess/impl/IndexImpl.java
src/main/java/com/healthmarketscience/jackcess/impl/IndexPageCache.java
src/main/java/com/healthmarketscience/jackcess/impl/PropertyMaps.java
src/main/java/com/healthmarketscience/jackcess/impl/RelationshipImpl.java
src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java
src/main/java/com/healthmarketscience/jackcess/impl/UsageMap.java
src/main/java/com/healthmarketscience/jackcess/impl/complex/ComplexColumnInfoImpl.java
src/main/java/com/healthmarketscience/jackcess/util/MemFileChannel.java

index 857c6319d44b261e4bb25a2ce5520b2b7d95aff4..f851788e4e4c5e29ae21a16c8ec2d2292b70b450 100644 (file)
@@ -451,6 +451,7 @@ public final class ByteUtil {
     StringBuilder rtn = new StringBuilder();
     int position = buffer.position();
     buffer.position(offset);
+    size = Math.min(size, buffer.remaining());
 
     for (int i = 0; i < size; i++) {
       byte b = buffer.get();
index 13eb3706f859fb5e7fff437d7702409b2086f51f..1a71d95329140b8e3238683ea501243afc6ca859 100644 (file)
@@ -65,6 +65,7 @@ import com.healthmarketscience.jackcess.impl.scsu.Compress;
 import com.healthmarketscience.jackcess.impl.scsu.EndOfInputException;
 import com.healthmarketscience.jackcess.impl.scsu.Expand;
 import com.healthmarketscience.jackcess.impl.scsu.IllegalInputException;
+import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -1524,38 +1525,37 @@ public class ColumnImpl implements Column, Comparable<ColumnImpl> {
   
   @Override
   public String toString() {
-    StringBuilder rtn = new StringBuilder();
-    rtn.append("\tName: (" + _table.getName() + ") " + _name);
+    ToStringBuilder sb = CustomToStringStyle.builder(this)
+      .append("name", "(" + _table.getName() + ") " + _name);
     byte typeValue = _type.getValue();
     if(_type.isUnsupported()) {
       typeValue = getUnknownDataType();
     }
-    rtn.append("\n\tType: 0x" + Integer.toHexString(typeValue) +
-               " (" + _type + ")");
-    rtn.append("\n\tNumber: " + _columnNumber);
-    rtn.append("\n\tLength: " + _columnLength);
-    rtn.append("\n\tVariable length: " + _variableLength);
+    sb.append("type", "0x" + Integer.toHexString(typeValue) +
+              " (" + _type + ")")
+      .append("number", _columnNumber)
+      .append("length", _columnLength)
+      .append("variableLength", _variableLength);
     if(_type.isTextual()) {
-      rtn.append("\n\tCompressed Unicode: " + _textInfo._compressedUnicode);
-      rtn.append("\n\tText Sort order: " + _textInfo._sortOrder);
+      sb.append("compressedUnicode", _textInfo._compressedUnicode)
+        .append("textSortOrder", _textInfo._sortOrder);
       if(_textInfo._codePage > 0) {
-        rtn.append("\n\tText Code Page: " + _textInfo._codePage);
+        sb.append("textCodePage", _textInfo._codePage);
       }
       if(isAppendOnly()) {
-        rtn.append("\n\tAppend only: " + isAppendOnly());
+        sb.append("appendOnly", isAppendOnly());
       } 
       if(isHyperlink()) {
-        rtn.append("\n\tHyperlink: " + isHyperlink());
+        sb.append("hyperlink", isHyperlink());
       } 
     }      
     if(_autoNumber) {
-      rtn.append("\n\tLast AutoNumber: " + _autoNumberGenerator.getLast());
+      sb.append("lastAutoNumber", _autoNumberGenerator.getLast());
     }
     if(_complexInfo != null) {
-      rtn.append("\n\tComplexInfo: " + _complexInfo);
+      sb.append("complexInfo", _complexInfo);
     }
-    rtn.append("\n\n");
-    return rtn.toString();
+    return sb.toString();
   }
   
   /**
@@ -1943,7 +1943,9 @@ public class ColumnImpl implements Column, Comparable<ColumnImpl> {
 
     @Override
     public String toString() {
-      return "RawData: " + ByteUtil.toHexString(getBytes());
+      return CustomToStringStyle.valueBuilder(this)
+        .append(null, getBytes())
+        .toString();
     }
 
     private Object writeReplace() throws ObjectStreamException {
@@ -2116,7 +2118,9 @@ public class ColumnImpl implements Column, Comparable<ColumnImpl> {
 
     @Override
     public String toString() {
-      return _value + "(" + _version + ")";
+      return CustomToStringStyle.valueBuilder(this)
+        .append(null, _value + "(" + _version + ")")
+        .toString();
     }
   }
 
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java b/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java
new file mode 100644 (file)
index 0000000..d909f96
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+Copyright (c) 2013 James Ahlborn
+
+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 (at your option) 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.  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 com.healthmarketscience.jackcess.impl;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.lang.builder.StandardToStringStyle;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+/**
+ * Custom ToStringStyle for use with ToStringBuilder.
+ *
+ * @author James Ahlborn
+ */
+public class CustomToStringStyle extends StandardToStringStyle 
+{
+  private static final long serialVersionUID = 0L;
+
+  private static final String FIELD_SEP = SystemUtils.LINE_SEPARATOR + "  ";
+  private static final String IMPL_SUFFIX = "Impl";
+  private static final int MAX_BYTE_DETAIL_LEN = 20;
+  
+  public static final CustomToStringStyle INSTANCE = new CustomToStringStyle() {
+    private static final long serialVersionUID = 0L;
+    {
+      setContentStart("[");
+      setFieldSeparator(FIELD_SEP);
+      setFieldSeparatorAtStart(true);
+      setFieldNameValueSeparator(": ");
+      setContentEnd(SystemUtils.LINE_SEPARATOR + "]");
+      setUseShortClassName(true);
+    }
+  };
+
+  public static final CustomToStringStyle VALUE_INSTANCE = new CustomToStringStyle() {
+    private static final long serialVersionUID = 0L;
+    {
+      setUseShortClassName(true);
+      setUseIdentityHashCode(false);
+    }
+  };
+
+  private CustomToStringStyle() {    
+  }
+
+  public static ToStringBuilder builder(Object obj) {
+    return new ToStringBuilder(obj, INSTANCE);
+  }
+
+  public static ToStringBuilder valueBuilder(Object obj) {
+    return new ToStringBuilder(obj, VALUE_INSTANCE);
+  }
+
+  @Override
+  protected void appendClassName(StringBuffer buffer, Object obj) {
+    if(obj instanceof String) {
+      // the caller gave an "explicit" class name
+      buffer.append(obj);
+    } else {
+      super.appendClassName(buffer, obj);
+    }
+  }
+
+  @Override
+  protected String getShortClassName(Class clss) {
+    String shortName = super.getShortClassName(clss);
+    if(shortName.endsWith(IMPL_SUFFIX)) {
+      shortName = shortName.substring(0, 
+                                      shortName.length() - IMPL_SUFFIX.length());
+    }
+    int idx = shortName.lastIndexOf('.');
+    if(idx >= 0) {
+      shortName = shortName.substring(idx + 1);
+    }
+    return shortName;
+  }
+
+  @Override
+  protected void appendDetail(StringBuffer buffer, String fieldName, 
+                              Object value) {
+    if(value instanceof ByteBuffer) {
+      appendDetail(buffer, (ByteBuffer)value);
+    } else {
+      buffer.append(indent(value));
+    }
+  }
+
+  @Override
+  protected void appendDetail(StringBuffer buffer, String fieldName, 
+                              Collection value) {
+    buffer.append("[");
+
+    // gather contents of list in a new StringBuffer
+    StringBuffer sb = new StringBuffer();
+    Iterator<?> iter = value.iterator();
+    if(iter.hasNext()) {
+      if(isFieldSeparatorAtStart()) {
+        appendFieldSeparator(sb);
+      }
+      appendInternal(sb, fieldName, iter.next(), true);
+    }
+    while(iter.hasNext()) {
+      sb.append(",");
+      appendFieldSeparator(sb);
+      appendInternal(sb, fieldName, iter.next(), true);
+    }
+
+    // indent entire list contents another level
+    buffer.append(indent(sb));
+
+    if(isFieldSeparatorAtStart()) {
+      appendFieldSeparator(buffer);
+    }
+    buffer.append("]");
+  }
+
+
+  @Override
+  protected void appendDetail(StringBuffer buffer, String fieldName,
+                              Map value) {
+    buffer.append("{");
+
+    // gather contents of map in a new StringBuffer
+    StringBuffer sb = new StringBuffer();
+    @SuppressWarnings("unchecked")
+    Iterator<Map.Entry<?,?>> iter = value.entrySet().iterator();
+    if(iter.hasNext()) {
+      if(isFieldSeparatorAtStart()) {
+        appendFieldSeparator(sb);
+      }
+      Map.Entry<?,?> e = iter.next();
+      sb.append(e.getKey()).append("=");
+      appendInternal(sb, fieldName, e.getValue(), true);
+    }
+    while(iter.hasNext()) {
+      sb.append(",");
+      appendFieldSeparator(sb);
+      Map.Entry<?,?> e = iter.next();
+      sb.append(e.getKey()).append("=");
+      appendInternal(sb, fieldName, e.getValue(), true);
+    }
+    if(isFieldSeparatorAtStart()) {
+      appendFieldSeparator(sb);
+    }
+
+    // indent entire map contents another level
+    buffer.append(indent(sb));
+
+    buffer.append("}");
+  }
+
+  @Override
+  protected void appendDetail(StringBuffer buffer, String fieldName, 
+                              byte[] array) {
+    appendDetail(buffer, PageChannel.wrap(array));
+  }
+
+  private static void appendDetail(StringBuffer buffer, ByteBuffer bb) {
+    int len = bb.remaining();
+    buffer.append("(").append(len).append(") ");
+    if(len > MAX_BYTE_DETAIL_LEN) {
+      buffer.append(ByteUtil.toHexString(bb, len, MAX_BYTE_DETAIL_LEN))
+        .append(" ...");
+    } else {
+      buffer.append(ByteUtil.toHexString(bb, len));
+    }      
+  }
+
+  private static String indent(Object obj) {
+    return ((obj != null) ? obj.toString().replaceAll(
+                SystemUtils.LINE_SEPARATOR, FIELD_SEP) : null);
+  }
+}
index a1e945bcd968ef0141364f57e977dc35532891a8..047939583361de170f7da43ba2b47fa38cbbedeb 100644 (file)
@@ -42,6 +42,7 @@ import com.healthmarketscience.jackcess.Index;
 import com.healthmarketscience.jackcess.IndexBuilder;
 import static com.healthmarketscience.jackcess.impl.ByteUtil.ByteStream;
 import static com.healthmarketscience.jackcess.impl.IndexCodes.*;
+import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -850,23 +851,23 @@ public class IndexData {
 
   @Override
   public String toString() {
-    StringBuilder rtn = new StringBuilder();
-    rtn.append("\n\tData number: ").append(_number);
-    rtn.append("\n\tPage number: ").append(_rootPageNumber);
-    rtn.append("\n\tIs Backing Primary Key: ").append(isBackingPrimaryKey());
-    rtn.append("\n\tIs Unique: ").append(isUnique());
-    rtn.append("\n\tIgnore Nulls: ").append(shouldIgnoreNulls());
-    rtn.append("\n\tColumns: ").append(_columns);
-    rtn.append("\n\tInitialized: ").append(_initialized);
+    ToStringBuilder sb = CustomToStringStyle.builder(this)
+      .append("dataNumber", _number)
+      .append("pageNumber", _rootPageNumber)
+      .append("isBackingPrimaryKey", isBackingPrimaryKey())
+      .append("isUnique", isUnique())
+      .append("ignoreNulls", shouldIgnoreNulls())
+      .append("columns", _columns)
+      .append("initialized", _initialized);
     if(_initialized) {
       try {
-        rtn.append("\n\tEntryCount: ").append(getEntryCount());
+        sb.append("entryCount", getEntryCount());
       } catch(IOException e) {
         throw new RuntimeException(e);
       }
     }
-    rtn.append("\n").append(_pageCache.toString());
-    return rtn.toString();
+    sb.append("pageCache", _pageCache);
+    return sb.toString();
   }
   
   /**
@@ -1328,7 +1329,10 @@ public class IndexData {
     
     @Override
     public String toString() {
-      return "ColumnDescriptor " + getColumn() + "\nflags: " + getFlags();
+      return CustomToStringStyle.builder(this)
+        .append("column", getColumn())
+        .append("flags", getFlags())
+        .toString();
     }
   }
 
@@ -1770,15 +1774,20 @@ public class IndexData {
       buffer.put((byte)getRowId().getRowNumber());
     }
 
-    protected final String entryBytesToString() {
-      return (isValid() ? ", Bytes = " + ByteUtil.toHexString(
-                  ByteBuffer.wrap(_entryBytes), _entryBytes.length) :
-              "");
+    protected final ToStringBuilder entryBytesToStringBuilder(
+        ToStringBuilder sb) {
+      if(isValid()) {
+        sb.append("bytes", _entryBytes);
+      }
+      return sb;
     }
     
     @Override
     public String toString() {
-      return "RowId = " + _rowId + entryBytesToString() + "\n";
+      return entryBytesToStringBuilder(
+          CustomToStringStyle.valueBuilder(this)
+          .append("rowId", _rowId))
+        .toString();
     }
 
     @Override
@@ -1904,10 +1913,12 @@ public class IndexData {
 
     @Override
     public String toString() {
-      return ("Node RowId = " + getRowId() +
-              ", SubPage = " + _subPageNumber + entryBytesToString() + "\n");
-    }
-        
+      return entryBytesToStringBuilder(
+          CustomToStringStyle.valueBuilder(this)
+          .append("rowId", getRowId())
+          .append("subPage", _subPageNumber))
+        .toString();
+    }        
   }
 
   /**
@@ -2140,8 +2151,10 @@ public class IndexData {
         
     @Override
     public String toString() {
-      return getClass().getSimpleName() + " CurPosition " + _curPos +
-        ", PrevPosition " + _prevPos;
+      return CustomToStringStyle.valueBuilder(this)
+        .append("curPosition", _curPos)
+        .append("prevPosition", _prevPos)
+        .toString();
     }
     
     /**
@@ -2300,8 +2313,12 @@ public class IndexData {
 
     @Override
     public String toString() {
-      return "Page = " + _dataPage.getPageNumber() + ", Idx = " + _idx +
-        ", Entry = " + _entry + ", Between = " + _between;
+      return CustomToStringStyle.valueBuilder(this)
+        .append("page", _dataPage.getPageNumber())
+        .append("idx", _idx)
+        .append("entry", _entry)
+        .append("between", _between)
+        .toString();
     }
   }
 
@@ -2366,13 +2383,20 @@ public class IndexData {
     @Override
     public final String toString() {
       List<Entry> entries = getEntries();
-      return (isLeaf() ? "Leaf" : "Node") + "DataPage[" + getPageNumber() +
+
+      String objName = 
+        (isLeaf() ? "Leaf" : "Node") + "DataPage[" + getPageNumber() +
         "] " + getPrevPageNumber() + ", " + getNextPageNumber() + ", (" +
-        getChildTailPageNumber() + "), " +
-        ((isLeaf() && !entries.isEmpty()) ?
-         ("[" + entries.get(0) + ", " +
-          entries.get(entries.size() - 1) + "]") :
-         entries);
+        getChildTailPageNumber() + ")";
+      ToStringBuilder sb = CustomToStringStyle.valueBuilder(objName);
+
+      if((isLeaf() && !entries.isEmpty())) {
+        sb.append("entryRange", "[" + entries.get(0) + ", " +
+                  entries.get(entries.size() - 1) + "]");
+      } else {
+        sb.append("entries", entries);
+      }
+      return sb.toString();
     }
   }
 
index db762943f90868a03a245382d5e96e92351ae23c..083fd5a294a269d38cad24fe73793a46e0875e04 100644 (file)
@@ -36,7 +36,7 @@ import java.util.Map;
 import com.healthmarketscience.jackcess.CursorBuilder;
 import com.healthmarketscience.jackcess.Index;
 import com.healthmarketscience.jackcess.IndexBuilder;
-import com.healthmarketscience.jackcess.RowId;
+import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -348,18 +348,16 @@ public class IndexImpl implements Index, Comparable<IndexImpl>
 
   @Override
   public String toString() {
-    StringBuilder rtn = new StringBuilder();
-    rtn.append("\tName: (").append(getTable().getName()).append(") ")
-      .append(_name);
-    rtn.append("\n\tNumber: ").append(_indexNumber);
-    rtn.append("\n\tIs Primary Key: ").append(isPrimaryKey());
-    rtn.append("\n\tIs Foreign Key: ").append(isForeignKey());
+    ToStringBuilder sb = CustomToStringStyle.builder(this)
+      .append("name", "(" + getTable().getName() + ") " + _name)
+      .append("number", _indexNumber)
+      .append("isPrimaryKey", isPrimaryKey())
+      .append("isForeignKey", isForeignKey());
     if(_reference != null) {
-      rtn.append("\n\tForeignKeyReference: ").append(_reference);
+      sb.append("foreignKeyReference", _reference);
     }
-    rtn.append(_data.toString());
-    rtn.append("\n\n");
-    return rtn.toString();
+    sb.append("data", _data);
+    return sb.toString();
   }
   
   public int compareTo(IndexImpl other) {
@@ -451,12 +449,12 @@ public class IndexImpl implements Index, Comparable<IndexImpl>
 
     @Override
     public String toString() {
-      return new StringBuilder()
-        .append("\n\t\tOther Index Number: ").append(_otherIndexNumber)
-        .append("\n\t\tOther Table Page Num: ").append(_otherTablePageNumber)
-        .append("\n\t\tIs Primary Table: ").append(isPrimaryTable())
-        .append("\n\t\tIs Cascade Updates: ").append(isCascadeUpdates())
-        .append("\n\t\tIs Cascade Deletes: ").append(isCascadeDeletes())
+      return CustomToStringStyle.builder(this)
+        .append("otherIndexNumber", _otherIndexNumber)
+        .append("otherTablePageNum", _otherTablePageNumber)
+        .append("isPrimaryTable", isPrimaryTable())
+        .append("isCascadeUpdates", isCascadeUpdates())
+        .append("isCascadeDeletes", isCascadeDeletes())
         .toString();
     }
   }
index 325e1782b94003adb8785efef4c1bb4001d678f8..f6b4ade55fd10497eac3f9c80b206c4ea9ce92d7 100644 (file)
@@ -40,6 +40,7 @@ import java.util.Map;
 import java.util.RandomAccess;
 
 import static com.healthmarketscience.jackcess.impl.IndexData.*;
+import org.apache.commons.lang.builder.ToStringBuilder;
 
 /**
  * Manager of the index pages for a IndexData.
@@ -1108,24 +1109,25 @@ public class IndexPageCache
   }
   
   /**
-   * Dumps the given index page to a StringBuilder
+   * Collects all the cache pages in the cache.
    *
-   * @param rtn the StringBuilder to update
-   * @param dpMain the index page to dump
+   * @param paages the List to update
+   * @param dpMain the index page to collect
    */
-  private void dumpPage(StringBuilder rtn, DataPageMain dpMain) {
+  private List<Object> collectPages(List<Object> pages, DataPageMain dpMain) {
     try {
       CacheDataPage cacheDataPage = new CacheDataPage(dpMain);
-      rtn.append(cacheDataPage).append("\n");
+      pages.add(cacheDataPage);
       if(!dpMain._leaf) {
         for(Entry e : cacheDataPage._extra._entryView) {
           DataPageMain childMain = dpMain.getChildPage(e);
-          dumpPage(rtn, childMain);
+          collectPages(pages, childMain);
         }
       }
     } catch(IOException e) {
-      rtn.append("Page[" + dpMain._pageNumber + "]: " + e);
+      pages.add("DataPage[" + dpMain._pageNumber + "]: " + e);
     }
+    return pages;
   }
 
   /**
@@ -1148,13 +1150,13 @@ public class IndexPageCache
   
   @Override
   public String toString() {
+    ToStringBuilder sb = CustomToStringStyle.builder(this);
     if(_rootPage == null) {
-      return "Cache: (uninitialized)";
+      sb.append("pages", "(uninitialized)");
+    } else {    
+      sb.append("pages", collectPages(new ArrayList<Object>(), _rootPage));
     }
-    
-    StringBuilder rtn = new StringBuilder("Cache: \n");
-    dumpPage(rtn, _rootPage);
-    return rtn.toString();
+    return sb.toString();
   }
 
   /**
@@ -1320,8 +1322,10 @@ public class IndexPageCache
     
     @Override
     public String toString() {
-      return "DPExtra: " + _entryView;
-    }    
+      return CustomToStringStyle.builder("DPExtra")
+        .append(null, _entryView)
+        .toString();
+    }
   }
 
   /**
index adc556bbdf1417ec3e987af4176e85e14932056a..b0d55672f15647fba1c62b55528009fa3da10747 100644 (file)
@@ -111,14 +111,9 @@ public class PropertyMaps implements Iterable<PropertyMapImpl>
 
   @Override
   public String toString() {
-    StringBuilder sb = new StringBuilder();
-    for(Iterator<PropertyMapImpl> iter = iterator(); iter.hasNext(); ) {
-      sb.append(iter.next());
-      if(iter.hasNext()) {
-        sb.append("\n");
-      }
-    }
-    return sb.toString();
+    return CustomToStringStyle.builder(this)
+      .append(null, _maps.values())
+      .toString();
   }
 
   /**
index 8424610a91888a74b4995719b83099a19f36e395..cdf9700d11b8fc9bc6cd05d269327e8686b9150b 100644 (file)
@@ -138,15 +138,14 @@ public class RelationshipImpl implements Relationship
 
   @Override
   public String toString() {
-    StringBuilder rtn = new StringBuilder();
-    rtn.append("\tName: " + _name);
-    rtn.append("\n\tFromTable: " + _fromTable.getName());
-    rtn.append("\n\tFromColumns: " + _fromColumns);
-    rtn.append("\n\tToTable: " + _toTable.getName());
-    rtn.append("\n\tToColumns: " + _toColumns);
-    rtn.append("\n\tFlags: " + Integer.toHexString(_flags));
-    rtn.append("\n\n");
-    return rtn.toString();
+    return CustomToStringStyle.builder(this)
+      .append("name", _name)
+      .append("fromTable", _fromTable.getName())
+      .append("fromColumns", _fromColumns)
+      .append("toTable", _toTable.getName())
+      .append("toColumns", _toColumns)
+      .append("flags", Integer.toHexString(_flags))
+      .toString();
   }
   
 }
index 125508ed15b14a132cf6749d42568210d3c067d6..4cd33650cc3b787a1f0b596b945e546a994af3e3 100644 (file)
@@ -2085,24 +2085,18 @@ public class TableImpl implements Table
   
   @Override
   public String toString() {
-    StringBuilder rtn = new StringBuilder();
-    rtn.append("Type: " + _tableType + 
-               ((_tableType == TYPE_USER) ? " (USER)" : " (SYSTEM)"));
-    rtn.append("\nName: " + _name);
-    rtn.append("\nRow count: " + _rowCount);
-    rtn.append("\nColumn count: " + _columns.size());
-    rtn.append("\nIndex (data) count: " + _indexCount);
-    rtn.append("\nLogical Index count: " + _logicalIndexCount);
-    rtn.append("\nColumns:\n");
-    for(ColumnImpl col : _columns) {
-      rtn.append(col);
-    }
-    rtn.append("\nIndexes:\n");
-    for(Index index : _indexes) {
-      rtn.append(index);
-    }
-    rtn.append("\nOwned pages: " + _ownedPages + "\n");
-    return rtn.toString();
+    return CustomToStringStyle.builder(this)
+      .append("type", (_tableType + 
+                       ((_tableType == TYPE_USER) ? " (USER)" : " (SYSTEM)")))
+      .append("name", _name)
+      .append("rowCount", _rowCount)
+      .append("columnCount", _columns.size())
+      .append("indexCount(data)", _indexCount)
+      .append("logicalIndexCount", _logicalIndexCount)
+      .append("columns", _columns)
+      .append("indexes", _indexes)
+      .append("ownedPages", _ownedPages)
+      .toString();
   }
   
   /**
@@ -2553,10 +2547,11 @@ public class TableImpl implements Table
     }  
 
     @Override
-    public String toString()
-    {
-      return "RowState: headerRowId = " + _headerRowId + ", finalRowId = " +
-        _finalRowId;
+    public String toString() {
+      return CustomToStringStyle.valueBuilder(this)
+        .append("headerRowId", _headerRowId)
+        .append("finalRowId", _finalRowId)
+        .toString();
     }
   }
   
index 6a80e044db96988338e24d4df68cd7014ee8028e..91695824d70158d6ffb45a964006a7fe9e251376 100644 (file)
@@ -29,11 +29,12 @@ package com.healthmarketscience.jackcess.impl;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.BitSet;
+import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import com.healthmarketscience.jackcess.RowId;
 
 /**
  * Describes which database pages a particular table uses
@@ -413,10 +414,8 @@ public class UsageMap
 
   @Override
   public String toString() {
-    StringBuilder builder = new StringBuilder(
-        "(" + _handler.getClass().getSimpleName() +
-        ") page numbers (range " + _startPage + " " + _endPage + "): [");
 
+    List<String> ranges = new ArrayList<String>();
     PageCursor pCursor = cursor();
     int curRangeStart = Integer.MIN_VALUE;
     int prevPage = Integer.MIN_VALUE;
@@ -428,28 +427,31 @@ public class UsageMap
 
       if(nextPage != (prevPage + 1)) {
         if(prevPage >= 0) {
-          rangeToString(builder, curRangeStart, prevPage);
+          rangeToString(ranges, curRangeStart, prevPage);
         }
         curRangeStart = nextPage;
       }
       prevPage = nextPage;
     }
     if(prevPage >= 0) {
-      rangeToString(builder, curRangeStart, prevPage);
+      rangeToString(ranges, curRangeStart, prevPage);
     }
 
-    builder.append("]");
-    return builder.toString();
+    return CustomToStringStyle.valueBuilder(
+        _handler.getClass().getSimpleName())
+      .append("range", "(" + _startPage + "-" + _endPage + ")")
+      .append("pageNumbers", ranges)
+      .toString();
   }
 
-  private static void rangeToString(StringBuilder builder, int rangeStart,
+  private static void rangeToString(List<String> ranges, int rangeStart,
                                     int rangeEnd)
   {
-    builder.append(rangeStart);
     if(rangeEnd > rangeStart) {
-      builder.append("-").append(rangeEnd);
+      ranges.add(rangeStart + "-" + rangeEnd);
+    } else {
+      ranges.add(String.valueOf(rangeStart));
     }
-    builder.append(", ");
   }
   
   private abstract class Handler
index 83e86a2acc4ed57dc879e0e82a1e35fa02a8641a..ecfc485dee2b02c1253fb3b6ac0e339432bc33ad 100644 (file)
@@ -40,6 +40,7 @@ import com.healthmarketscience.jackcess.complex.ComplexDataType;
 import com.healthmarketscience.jackcess.complex.ComplexValue;
 import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
 import com.healthmarketscience.jackcess.impl.ColumnImpl;
+import com.healthmarketscience.jackcess.impl.CustomToStringStyle;
 import com.healthmarketscience.jackcess.impl.TableImpl;
 
 /**
@@ -302,10 +303,10 @@ public abstract class ComplexColumnInfoImpl<V extends ComplexValue>
   
   @Override
   public String toString() {
-    StringBuilder rtn = new StringBuilder();
-    rtn.append("\n\t\tComplexType: " + getType());
-    rtn.append("\n\t\tComplexTypeId: " + _complexTypeId);
-    return rtn.toString();
+    return CustomToStringStyle.valueBuilder(this)
+      .append("complexType", getType())
+      .append("complexTypeId", _complexTypeId)
+      .toString();
   }
 
   protected static void diffFlatColumns(Table typeObjTable, 
index 3a583e5fb0e7f076630597ba50917ac2f206fad4..1c657664199a9cd45a62c933365e9fed13257d99 100644 (file)
@@ -286,7 +286,7 @@ public class MemFileChannel extends FileChannel
     int chunkIndex = getChunkIndex(position);
     int chunkOffset = getChunkOffset(position);
 
-    long numBytes = 0;
+    long numBytes = 0L;
     while(count > 0L) {
 
       int chunkBytes = (int)Math.min(count, CHUNK_SIZE - chunkOffset);