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 NestedSetFunction is the base class for {@link Function} implementations that want to simply store
031 * values in an existing nested object tree.
032 * <p>
033 * All argument values referenced by the pointerMap will be set on the root node, a copy of the first argument to this
034 * operation.
035 * <p>
036 * That is, every Fields instance in the pointer map is expected to have a corresponding argument passed to the operation.
037 * <p>
038 * The pointer path mapped to any given Fields instance in the pointerMap will be used as the location to set on the
039 * root node.
040 * <p>
041 * If a {@code pointerMap} is not provided, the resolved argument fields will be mapped to the root of the node. This is a
042 * convenience for quickly pivoting a Tuple into an nested object with the same attributes.
043 */
044public class NestedSetFunction<Node, Result> extends NestedBaseFunction<Node, Result>
045  {
046  public NestedSetFunction( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration )
047    {
048    super( nestedCoercibleType, fieldDeclaration );
049    }
050
051  public NestedSetFunction( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration, String rootPointer )
052    {
053    super( nestedCoercibleType, fieldDeclaration, rootPointer );
054    }
055
056  public NestedSetFunction( NestedCoercibleType nestedCoercibleType, Fields fieldDeclaration, Map<Fields, String> pointerMap )
057    {
058    super( nestedCoercibleType, fieldDeclaration, pointerMap );
059    }
060
061  @Override
062  protected Node getNode( TupleEntry arguments )
063    {
064    Node node = (Node) arguments.getObject( 0, getCoercibleType() );
065
066    return deepCopy( node );
067    }
068  }