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 "less than" strict comparison between a job metadata value or a job name and an other comparable value.
025 * @author Laurent Cohen
026 * @since 6.2
027 */
028public class LessThanJobSelector extends AbstractBinaryComparisonJobSelector<Comparable<?>> {
029  /**
030   * Explicit serialVersionUID.
031   */
032  private static final long serialVersionUID = 1L;
033
034  /**
035   * Initialize this selector with a value to compare job names with.
036   * @param operand the operand to compare with.
037   */
038  public LessThanJobSelector(final String operand) {
039    this(null, operand);
040  }
041
042  /**
043   * Initialize this selector with a job metadata key and a value to compare with.
044   * @param key the metadata key of the value to compare with.
045   * @param operand the operand to compare with.
046   */
047  public LessThanJobSelector(final Object key, final Comparable<?> operand) {
048    super(key, operand);
049  }
050
051  @SuppressWarnings({ "rawtypes", "unchecked" })
052  @Override
053  public boolean accepts(final JPPFDistributedJob job) {
054    final Comparable value = getComparableValueOrName(job);
055    if (value == null) return false;
056    return value.compareTo(operand) < 0;
057  }
058}