001/*
002 * Copyright 2015-2023 Ping Identity Corporation
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License (GPLv2 only)
006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007 * as published by the Free Software Foundation.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, see <http://www.gnu.org/licenses>.
016 */
017
018package com.unboundid.scim2.common.filters;
019
020import com.fasterxml.jackson.databind.node.ValueNode;
021import com.unboundid.scim2.common.Path;
022import com.unboundid.scim2.common.exceptions.ScimException;
023
024/**
025 * Equal attribute comparison filter.
026 */
027public final class EqualFilter extends ComparisonFilter
028{
029  /**
030   * Creates a new equals attribute comparison filter.
031   *
032   * @param filterAttribute The path to the attribute to compare.
033   * @param filterValue The comparison value.
034   */
035  EqualFilter(final Path filterAttribute, final ValueNode filterValue)
036  {
037    super(filterAttribute, filterValue);
038  }
039
040  /**
041   * {@inheritDoc}
042   */
043  public <R, P> R visit(final FilterVisitor<R, P> visitor, final P param)
044      throws ScimException
045  {
046    return visitor.visit(this, param);
047  }
048
049  /**
050   * {@inheritDoc}
051   */
052  @Override
053  public FilterType getFilterType()
054  {
055    return FilterType.EQUAL;
056  }
057
058  /**
059   * {@inheritDoc}
060   */
061  @Override
062  public boolean equals(final Object o)
063  {
064    if (this == o)
065    {
066      return true;
067    }
068    if (o == null || getClass() != o.getClass())
069    {
070      return false;
071    }
072
073    ComparisonFilter that = (ComparisonFilter) o;
074
075    if (!getAttributePath().equals(that.getAttributePath()))
076    {
077      return false;
078    }
079    if (!getComparisonValue().equals(that.getComparisonValue()))
080    {
081      return false;
082    }
083
084    return true;
085  }
086
087  /**
088   * {@inheritDoc}
089   */
090  @Override
091  public int hashCode()
092  {
093    int result = getAttributePath().hashCode();
094    result = 31 * result + getComparisonValue().hashCode();
095    return result;
096  }
097}