// @formatter:off
 /*******************************************************************************
 *
 * This file is part of tensorics.
 * 
 * Copyright (c) 2008-2011, CERN. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 ******************************************************************************/
// @formatter:on
package org.tensorics.core.tensorbacked.lang;

import static org.tensorics.core.tensorbacked.TensorbackedInternals.createBackedByTensor;
import static org.tensorics.core.tensorbacked.TensorbackedInternals.dimensionsOf;

import java.util.Map;

import org.tensorics.core.tensor.ImmutableTensor;
import org.tensorics.core.tensor.Position;
import org.tensorics.core.tensor.Tensor;
import org.tensorics.core.tensor.lang.TensorStructurals;
import org.tensorics.core.tensorbacked.Tensorbacked;
import org.tensorics.core.tensorbacked.TensorbackedInternals;

import com.google.common.base.Preconditions;

public class OngoingTensorbackedConstruction<V, TB extends Tensorbacked<V>> {

    private final Class<TB> tensorbackedClass;

    public OngoingTensorbackedConstruction(Class<TB> tensorbackedClass) {
        super();
        this.tensorbackedClass = Preconditions.checkNotNull(tensorbackedClass, "tensorbackedClass must not be null");
    }

    public TB byMerging(Iterable<Tensor<V>> tensors) {
        return TensorbackedInternals.createBackedByTensor(tensorbackedClass, TensorStructurals.merge(tensors));
    }

    public TB byMergingTb(Iterable<? extends Tensorbacked<V>> tensorbackeds) {
        return byMerging(TensorbackedInternals.tensorsOf(tensorbackeds));
    }

    public TB fromMap(Map<Position, V> inputMap) {
        Preconditions.checkNotNull(inputMap, "inputMap must not be null");
        Tensor<V> tensor = ImmutableTensor.fromMap(dimensionsOf(tensorbackedClass), inputMap);
        return createBackedByTensor(tensorbackedClass, tensor);
    }

}

@@ -133,17 +133,16 @@
 rics.%0A *
- 
 %0A * Copy
@@ -749,17 +749,16 @@
 ense.%0A *
- 
 %0A ******
@@ -899,98 +899,8 @@
 g;%0A%0A
-import static org.tensorics.core.tensorbacked.TensorbackedInternals.createBackedByTensor;%0A
 impo
@@ -1559,25 +1559,8 @@
 ) %7B%0A
-        super();%0A
     
@@ -1698,27 +1698,13 @@
  TB 
-byMerging(Iterable%3C
+from(
 Tens
@@ -1712,17 +1712,15 @@
 r%3CV%3E
-%3E
  tensor
-s
 ) %7B%0A
@@ -1796,16 +1796,107 @@
 dClass, 
+tensor);%0A    %7D%0A%0A    public TB byMerging(Iterable%3CTensor%3CV%3E%3E tensors) %7B%0A        return from(
 TensorSt
@@ -2329,48 +2329,13 @@
 urn 
-createBackedByTensor(tensorbackedClass, 
+from(
 tens

add variant to construct tensorbacked from a tensor....