001/*
002 * Copyright (c) 2016-2017 Chris K Wensel. 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 cascading.operation.BaseOperation;
024import cascading.tuple.Fields;
025import cascading.tuple.type.CoercibleType;
026import heretical.pointer.path.NestedPointerCompiler;
027
028/**
029 *
030 */
031public class NestedBaseOperation<Node, Result, Context> extends BaseOperation<Context>
032  {
033  protected final NestedCoercibleType<Node, Result> nestedCoercibleType;
034
035  public NestedBaseOperation( NestedCoercibleType<Node, Result> nestedCoercibleType )
036    {
037    this.nestedCoercibleType = nestedCoercibleType;
038    }
039
040  public NestedBaseOperation( NestedCoercibleType<Node, Result> nestedCoercibleType, Fields fieldDeclaration )
041    {
042    super( fieldDeclaration.hasTypes() ? fieldDeclaration : fieldDeclaration.applyTypeToAll( nestedCoercibleType ) );
043    this.nestedCoercibleType = nestedCoercibleType;
044    }
045
046  public NestedBaseOperation( NestedCoercibleType<Node, Result> nestedCoercibleType, int numArgs, Fields fieldDeclaration )
047    {
048    super( numArgs, fieldDeclaration.hasTypes() ? fieldDeclaration : fieldDeclaration.applyTypeToAll( nestedCoercibleType ) );
049    this.nestedCoercibleType = nestedCoercibleType;
050    }
051
052  protected NestedPointerCompiler<Node, Result> getNestedPointerCompiler()
053    {
054    return nestedCoercibleType.getNestedPointerCompiler();
055    }
056
057  protected CoercibleType<Node> getCoercibleType()
058    {
059    return nestedCoercibleType;
060    }
061
062  protected Node deepCopy( Node node )
063    {
064    return nestedCoercibleType.deepCopy( node );
065    }
066
067  protected Node getRootNode()
068    {
069    return nestedCoercibleType.newRoot();
070    }
071
072  protected Node getLiteralNode( Object value )
073    {
074    return nestedCoercibleType.node( value );
075    }
076
077  protected Iterable<Node> iterable( Result node )
078    {
079    return nestedCoercibleType.getNestedPointerCompiler().iterable( node );
080    }
081  }