    001/*
    002 * Copyright (c) 2007-2017 Xplenty, Inc. 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.flow.planner.iso.expression;
    022
    023import cascading.flow.FlowElement;
    024import cascading.flow.planner.PlannerContext;
    025import cascading.flow.planner.graph.ElementGraph;
    026import cascading.operation.PlannedOperation;
    027import cascading.operation.PlannerLevel;
    028import cascading.pipe.Operator;
    029
    030/**
    031 *
    032 */
    033public class PlannerLevelElementExpression extends ElementExpression
    034  {
    035  private final Class<? extends PlannerLevel> plannerLevelClass;
    036
    037  protected PlannerLevelElementExpression( ElementCapture capture, Class<? extends PlannerLevel> plannerLevelClass )
    038    {
    039    super( capture );
    040    this.plannerLevelClass = plannerLevelClass;
    041    }
    042
    043  @Override
    044  public boolean applies( PlannerContext plannerContext, ElementGraph elementGraph, FlowElement flowElement )
    045    {
    046    if( !( flowElement instanceof Operator ) )
    047      return false;
    048
    049    Operator operator = (Operator) flowElement;
    050
    051    if( !operator.hasPlannerLevel() )
    052      return false;
    053
    054    PlannerLevel plannerLevel = plannerContext.getPlannerLevelFor( plannerLevelClass );
    055
    056    if( plannerLevel == null )
    057      return false;
    058
    059    if( !( (PlannedOperation) operator.getOperation() ).supportsPlannerLevel( plannerLevel ) )
    060      return false;
    061
    062    return operator.getPlannerLevel().isStricterThan( plannerLevel );
    063    }
    064  }