/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */

package com.hp.hpl.jena.sparql.engine.binding;

import com.hp.hpl.jena.graph.Node ;
import com.hp.hpl.jena.sparql.core.Var ;

public class BindingFactory
{
    public static final Binding noParent = null ; 
    
    /** Create a binding of no pairs */
    public static Binding binding() { return binding(noParent) ; }
    
    /** Create a binding of no pairs */
    public static Binding binding(Binding parent) { return new Binding0(parent)  ; }
    
    public static Binding binding(Var var, Node node) { return binding(noParent, var, node) ; }
    
    /** Create a binding of one (var, value) pair */
    public static Binding binding(Binding parent, Var var, Node node)
    {
        if ( Var.isAnonVar(var) )
            return new Binding0(parent) ;
        return new Binding1(parent, var, node) ;
    }
    
    public static BindingMap create() { return create(noParent) ; }
    public static BindingMap create(Binding parent) { return new BindingHashMap(parent)  ; }
    
    public static Binding root() { return BindingRoot.create() ; }
}

@@ -848,16 +848,45 @@
 nding;%0A%0A
+import java.util.Iterator ;%0A%0A
 import c
@@ -1881,11 +1881,427 @@
 te() ; %7D
+%0A%0A    /** Create a new Binding as a copy of an existing one.%0A     * Additionally, it guarantees to touch each element of the binding */ %0A    public static Binding materialize(Binding b)%0A    %7B%0A        Iterator%3CVar%3E vIter = b.vars() ; %0A        BindingMap b2 = create() ; %0A        while( vIter.hasNext() )%0A        %7B%0A            Var v = vIter.next();%0A            b2.add(v, b.get(v)) ;%0A        %7D%0A        return b2 ;%0A    %7D
 %0A%7D%0A

Add materialization (copy structure and touch all (var,node) pairs)