001/*
002 * JPPF.
003 * Copyright (C) 2005-2019 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.job;
020
021import org.jppf.node.protocol.JPPFDistributedJob;
022
023/**
024 * Performs a comparison of type "strictly more than lower_bound and strictly less than upper_bound" between  a {@code Comparable} metadata value or a job name
025 * and {@code Comparable} lower and upper bounds.
026 * @author Laurent Cohen
027 * @since 6.2
028 */
029public class BetweenEEJobSelector extends AbstractTernaryComparisonJobSelector<Comparable<?>> {
030  /**
031   * Explicit serialVersionUID.
032   */
033  private static final long serialVersionUID = 1L;
034
035  /**
036   * Initialize this job selector with a metadata key and lower and upper bounds.
037   * @param lower the lower bound to compare job names with.
038   * @param upper the upper bound to compare job names with.
039   */
040  public BetweenEEJobSelector(final String lower, final String upper) {
041    this(null, lower, upper);
042  }
043
044  /**
045   * Initialize this job selector with a metadata key and lower and upper bounds.
046   * @param key the metadata key of the value to compare with.
047   * @param lower the lower bound to compare with.
048   * @param upper the upper bound to compare with.
049   */
050  public BetweenEEJobSelector(final Object key, final Comparable<?> lower, final Comparable<?> upper) {
051    super(key, lower, upper);
052  }
053
054  @SuppressWarnings({ "rawtypes", "unchecked" })
055  @Override
056  public boolean accepts(final JPPFDistributedJob job) {
057    final Comparable value = getComparableValueOrName(job);
058    if (value == null) return false;
059    return (value.compareTo(operand) > 0) && (value.compareTo(operand2) < 0);
060  }
061}