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 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-api:0.2.0 024 * Bundle : ldp4j-application-api-0.2.0.jar 025 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 026 */ 027package org.ldp4j.application.data; 028 029import java.io.Serializable; 030import java.net.URI; 031 032import com.google.common.base.MoreObjects; 033import com.google.common.base.Objects; 034 035import static com.google.common.base.Preconditions.*; 036 037public final class ManagedIndividualId implements Serializable { 038 039 private static final long serialVersionUID = 3320976326537867325L; 040 041 private final String managerId; 042 private final Name<?> name; 043 private final URI indirectId; 044 045 private ManagedIndividualId(Name<?> name, String managerId, URI indirectId) { 046 this.name = name; 047 this.managerId = managerId; 048 this.indirectId = indirectId; 049 } 050 051 public Name<?> name() { 052 return this.name; 053 } 054 055 public String managerId() { 056 return this.managerId; 057 } 058 059 public URI indirectId() { 060 return this.indirectId; 061 } 062 063 @Override 064 public int hashCode() { 065 return Objects.hashCode(this.name,this.managerId,this.indirectId); 066 } 067 068 @Override 069 public boolean equals(Object obj) { 070 boolean result=false; 071 if(obj!=null && obj.getClass()==this.getClass()) { 072 ManagedIndividualId that=(ManagedIndividualId)obj; 073 result= 074 Objects.equal(this.name, that.name) && 075 Objects.equal(this.managerId, that.managerId) && 076 Objects.equal(this.indirectId, that.indirectId); 077 } 078 return result; 079 } 080 081 @Override 082 public String toString() { 083 return 084 MoreObjects. 085 toStringHelper(getClass()). 086 omitNullValues(). 087 add("name", this.name). 088 add("managerId",this.managerId). 089 add("indirectId", this.indirectId). 090 toString(); 091 } 092 093 public static ManagedIndividualId createId(Name<?> name, String managerId) { 094 checkNotNull(name,"Resource name cannot be null"); 095 checkNotNull(managerId,"Manager identifier cannot be null"); 096 return new ManagedIndividualId(name,managerId,null); 097 } 098 099 public static ManagedIndividualId createId(URI indirectId, ManagedIndividualId parent) { 100 checkNotNull(indirectId,"Indirect identifier cannot be null"); 101 checkNotNull(parent,"Parent identifier cannot be null"); 102 return new ManagedIndividualId(parent.name,parent.managerId,indirectId); 103 } 104 105}