001/*
002 * Copyright (c) 2016-2017 Chris K Wensel <chris@wensel.net>. All Rights Reserved.
003 *
004 * Project and contact information: http://www.cascading.org/
005 *
006 * This file is part of the Cascading project.
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020
021package cascading.nested.core;
022
023import java.util.Map;
024
025import cascading.operation.Function;
026import cascading.tuple.Fields;
027import cascading.tuple.TupleEntry;
028
029/**
030 * Class NestedCreateFunction is the base class for {@link Function} implementations that want to simply store
031 * values in a new nested object tree.
032 * <p>
033 * All argument values referenced by the {@code pointerMap} will be set on a new instance of the root node.
034 * <p>
035 * That is, every Fields instance in the pointer map is expected to have a corresponding argument passed to the operation.
036 * <p>
037 * The pointer path mapped to any given Fields instance in the {@code pointerMap} will be used as the location to set on the
038 * root node.
039 * <p>
040 * If a {@code pointerMap} is not provided, the resolved argument fields will be mapped to the root of the node. This is a
041 * convenience for quickly pivoting a Tuple into an nested object with the same attributes.
042 */
043public abstract class NestedCreateFunction<Node, Result> extends NestedBaseFunction<Node, Result>
044  {
045  public NestedCreateFunction( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration )
046    {
047    super( nestedCoercibleType, fieldDeclaration );
048    }
049
050  public NestedCreateFunction( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration, String rootPointer )
051    {
052    super( nestedCoercibleType, fieldDeclaration, rootPointer );
053    }
054
055  public NestedCreateFunction( NestedCoercibleType nestedCoercibleType, Fields fieldDeclaration, Map<Fields, String> pointerMap )
056    {
057    super( nestedCoercibleType, fieldDeclaration, pointerMap );
058    }
059
060  @Override
061  protected Node getNode( TupleEntry arguments )
062    {
063    return getRootNode();
064    }
065  }