001/**
002 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
003 *   This file is part of the LDP4j Project:
004 *     http://www.ldp4j.org/
005 *
006 *   Center for Open Middleware
007 *     http://www.centeropenmiddleware.com/
008 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
009 *   Copyright (C) 2014-2016 Center for Open Middleware.
010 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
011 *   Licensed under the Apache License, Version 2.0 (the "License");
012 *   you may not use this file except in compliance with the License.
013 *   You may obtain a copy of the License at
014 *
015 *             http://www.apache.org/licenses/LICENSE-2.0
016 *
017 *   Unless required by applicable law or agreed to in writing, software
018 *   distributed under the License is distributed on an "AS IS" BASIS,
019 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020 *   See the License for the specific language governing permissions and
021 *   limitations under the License.
022 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
023 *   Artifact    : org.ldp4j.framework:ldp4j-application-kernel-api:0.2.1
024 *   Bundle      : ldp4j-application-kernel-api-0.2.1.jar
025 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
026 */
027package org.ldp4j.application.kernel.constraints;
028
029import java.io.Serializable;
030
031import org.ldp4j.application.kernel.resource.ResourceId;
032
033import com.google.common.base.MoreObjects;
034import com.google.common.base.Objects;
035
036import static com.google.common.base.Preconditions.*;
037
038public final class ConstraintReportId implements Serializable {
039
040  private static final long serialVersionUID = -1692929146077368881L;
041
042  /**
043   * Not final to enable its usage in JPA
044   */
045  private ResourceId resourceId;
046
047  /**
048   * Not final to enable its usage in JPA
049   */
050  private String failureId;
051
052  private ConstraintReportId() {
053    // JPA Friendly
054  }
055
056  private ConstraintReportId(ResourceId resourceId, String failureId) {
057    this();
058    this.resourceId = resourceId;
059    this.failureId = failureId;
060  }
061
062  public ResourceId resourceId() {
063    return this.resourceId;
064  }
065
066  public String failureId() {
067    return this.failureId;
068  }
069
070  /**
071   * {@inheritDoc}
072   */
073  @Override
074  public int hashCode() {
075    return Objects.hashCode(this.resourceId,this.failureId);
076  }
077
078  /**
079   * {@inheritDoc}
080   */
081  @Override
082  public boolean equals(Object obj) {
083    boolean result=false;
084    if(obj instanceof ConstraintReportId) {
085      ConstraintReportId that=(ConstraintReportId)obj;
086      result=
087        Objects.equal(this.resourceId,that.resourceId) &&
088        Objects.equal(this.failureId,that.failureId);
089    }
090    return result;
091  }
092
093  /**
094   * {@inheritDoc}
095   */
096  @Override
097  public String toString() {
098    return
099      MoreObjects.
100        toStringHelper(getClass()).
101          add("resourceId",this.resourceId).
102          add("failureId",this.failureId).
103          toString();
104  }
105
106  public static ConstraintReportId create(ResourceId resourceId, String failureId) {
107    checkNotNull(resourceId,"Resource identifier cannot be null");
108    checkNotNull(failureId,"Failure identifier cannot be null");
109    return new ConstraintReportId(resourceId,failureId);
110  }
111
112}