001/* 002 * Copyright (c) 2016-2020 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.operation.SerPredicate; 027import cascading.tuple.Fields; 028import cascading.tuple.TupleEntry; 029 030/** 031 * Class NestedCreateFunction is the base class for {@link Function} implementations that want to simply store 032 * values in a new nested object tree. 033 * <p> 034 * All argument values referenced by the {@code pointerMap} will be set on a new instance of the root node. 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 {@code 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 abstract class NestedCreateFunction<Node, Result> extends NestedBaseFunction<Node, Result> 045 { 046 public NestedCreateFunction( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration ) 047 { 048 super( nestedCoercibleType, fieldDeclaration ); 049 } 050 051 public NestedCreateFunction( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration, String rootPointer ) 052 { 053 super( nestedCoercibleType, fieldDeclaration, rootPointer ); 054 } 055 056 public NestedCreateFunction( NestedCoercibleType nestedCoercibleType, Fields fieldDeclaration, Map<Fields, String> pointerMap ) 057 { 058 super( nestedCoercibleType, fieldDeclaration, pointerMap ); 059 } 060 061 public NestedCreateFunction( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration, SerPredicate<?> defaultValueFilter ) 062 { 063 super( nestedCoercibleType, fieldDeclaration, defaultValueFilter ); 064 } 065 066 public NestedCreateFunction( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration, String rootPointer, SerPredicate<?> defaultValueFilter ) 067 { 068 super( nestedCoercibleType, fieldDeclaration, rootPointer, defaultValueFilter ); 069 } 070 071 public NestedCreateFunction( NestedCoercibleType nestedCoercibleType, Fields fieldDeclaration, SerPredicate<?> defaultValueFilter, Map<Fields, String> pointerMap ) 072 { 073 super( nestedCoercibleType, fieldDeclaration, defaultValueFilter, pointerMap ); 074 } 075 076 @Override 077 protected Node getNode( TupleEntry arguments ) 078 { 079 return getRootNode(); 080 } 081 }