001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. 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, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.isis.core.metamodel.spec; 020 021import static org.hamcrest.CoreMatchers.is; 022 023import java.io.Serializable; 024 025import org.apache.isis.core.commons.ensure.Ensure; 026import org.apache.isis.core.commons.matchers.IsisMatchers; 027import org.apache.isis.core.metamodel.facets.object.objecttype.ObjectSpecIdFacet; 028 029/** 030 * Represents an {@link ObjectSpecification}, as determined by 031 * an {@link ObjectSpecIdFacet}. 032 * 033 * <p> 034 * Has value semantics. 035 */ 036public final class ObjectSpecId implements Serializable { 037 038 private static final long serialVersionUID = 1L; 039 040 private final String specId; 041 042 public static ObjectSpecId of(String specId) { 043 return new ObjectSpecId(specId); 044 } 045 046 public ObjectSpecId(String specId) { 047 Ensure.ensureThatArg(specId, is(IsisMatchers.nonEmptyString())); 048 this.specId = specId; 049 } 050 051 public String asString() { 052 return specId; 053 } 054 055 @Override 056 public int hashCode() { 057 final int prime = 31; 058 int result = 1; 059 result = prime * result + ((specId == null) ? 0 : specId.hashCode()); 060 return result; 061 } 062 063 @Override 064 public boolean equals(Object obj) { 065 if (this == obj) 066 return true; 067 if (obj == null) 068 return false; 069 if (getClass() != obj.getClass()) 070 return false; 071 ObjectSpecId other = (ObjectSpecId) obj; 072 if (specId == null) { 073 if (other.specId != null) 074 return false; 075 } else if (!specId.equals(other.specId)) 076 return false; 077 return true; 078 } 079 080 @Override 081 public String toString() { 082 return asString(); 083 } 084 085 086}