/*
 * Copyright (c) 2012-2013 rebaze GmbH
 * All rights reserved. 
 * 
 * This library and the accompanying materials are made available under the terms of the Apache License Version 2.0,
 * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.
 *
 */
package dogtooth.tree.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.thoughtworks.xstream.XStream;

import dogtooth.tree.Tree;
import dogtooth.tree.TreeBuilder;
import dogtooth.tree.TreeException;

/**
 * Set of tools for this API.
 * 
 * @author Toni Menzel <toni.menzel@rebaze.com>
 *
 */
public class TreeTools {

    private static final Logger LOG = LoggerFactory.getLogger( TreeTools.class );
       
    public File store( Tree tree ) throws IOException {
        // persist tree
        File f = File.createTempFile( "tree", ".xml" );
        return store( tree, f );
    }

    public File store( Tree tree, File f ) throws IOException {
        // persist tree
        XStream xstream = new XStream();
        xstream.toXML( tree, new FileOutputStream( f ) );
        LOG.debug( "Stored tree to " + f.getAbsolutePath() );
        return f;
    }

    public Tree load( File f ) {
        XStream xstream = new XStream();
        return (Tree) xstream.fromXML( f );
    }

    public Tree load( String locationClasspath ) {
        XStream xstream = new XStream();
        return (Tree) xstream.fromXML( this.getClass().getResourceAsStream( locationClasspath ) );
    }  

    public long nodes(Tree tree) {
    	int total = 1;
    	for (Tree sub : tree.branches()) {
    		total += nodes(sub);
    	}
    	return total;
    	
    }
   
}

@@ -345,40 +345,8 @@
 le;%0A
-import java.io.FileInputStream;%0A
 impo
@@ -405,61 +405,8 @@
 ion;
-%0Aimport java.io.InputStream;%0Aimport java.util.Arrays;
 %0A%0Aim
@@ -555,55 +555,21 @@
 ree.
-TreeBuilder;%0Aimport dogtooth.tree.TreeException
+annotated.Tag
 ;%0A%0A/
@@ -943,32 +943,36 @@
 ree, f );%0A    %7D%0A
+    
 %0A    public File
@@ -1707,17 +1707,16 @@
 al;%0A    
-%09
 %0A    %7D%0A 

fix imports