Skip to content
Snippets Groups Projects
Commit c7b0ec11 authored by brinn's avatar brinn
Browse files

add: PermanentIdentifier and make PlateIdentifier and Plate derive from it

SVN: 17202
parent 5d8be035
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto;
import java.io.Serializable;
/**
* A class representing a permanent identifier in openBIS.
*
* @author Bernd Rinn
*/
public class PermanentIdentifier implements Serializable, IPermanentIdentifier
{
private static final long serialVersionUID = 1L;
private final String permId;
public PermanentIdentifier(String permId)
{
this.permId = permId;
}
public String getPermId()
{
return permId;
}
@Override
public String toString()
{
return getPermId();
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((permId == null) ? 0 : permId.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final PermanentIdentifier other = (PermanentIdentifier) obj;
if (permId == null)
{
if (other.permId != null)
{
return false;
}
} else if (permId.equals(other.permId) == false)
{
return false;
}
return true;
}
}
package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto; package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto;
import java.io.Serializable; import java.io.IOException;
import java.io.ObjectInputStream;
/** /**
* Describes a plate and its context in a hierarchy * Unique identifier for a plate which is assigned to an experiment. This class really should be
* called <code>ExperimentPlateIdentifier</code>.
* *
* @author Tomasz Pylak * @author Tomasz Pylak
*/ */
public class Plate extends PlateIdentifier implements Serializable public class Plate extends PlateIdentifier
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// Keep for backward compatibility
private String experimentCode, projectCode; private String experimentCode, projectCode;
public Plate(String plateCode, String experimentCode, String projectCode, String spaceCodeOrNull) private ExperimentIdentifier experimentIdentifier;
@Deprecated
public Plate(String plateCode, String experimentCode, String projectCode, String spaceCode)
{
this(plateCode, spaceCode, null, new ExperimentIdentifier(spaceCode, projectCode,
experimentCode, null));
}
public Plate(String plateCode, String spaceCode, String permId,
ExperimentIdentifier experimentIdentifier)
{
super(plateCode, spaceCode, permId);
this.experimentCode = experimentIdentifier.getExperimentCode();
this.projectCode = experimentIdentifier.getProjectCode();
this.experimentIdentifier = experimentIdentifier;
}
/**
* Get the identifier of the experiment that this plate is assigned to.
*/
public ExperimentIdentifier getExperimentIdentifier()
{ {
super(plateCode, spaceCodeOrNull); return experimentIdentifier;
this.experimentCode = experimentCode;
this.projectCode = projectCode;
} }
/** a code of the experiment to which the plate belongs */ /**
* The code of the experiment to which the plate belongs.
*/
public String getExperimentCode() public String getExperimentCode()
{ {
return experimentCode; return experimentCode;
} }
/** a code of the project to which the plate belongs */ /**
* The code of the project to which the plate belongs.
*/
public String getProjectCode() public String getProjectCode()
{ {
return projectCode; return projectCode;
} }
// Special method for customizing Java deserialization.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
// Kick-off the default serialization procedure.
in.defaultReadObject();
// V1.0 didn't have the experimentIdentifier, so it may be null here.
if (experimentIdentifier == null)
{
experimentIdentifier =
new ExperimentIdentifier(experimentCode, projectCode, tryGetSpaceCode(), null);
}
}
} }
\ No newline at end of file
package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto; package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto;
import java.io.Serializable;
/** /**
* Contains data which uniquely define a plate * Contains data which uniquely define a plate.
* *
* @author Tomasz Pylak * @author Tomasz Pylak
*/ */
public class PlateIdentifier implements Serializable public class PlateIdentifier extends PermanentIdentifier
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -15,47 +13,44 @@ public class PlateIdentifier implements Serializable ...@@ -15,47 +13,44 @@ public class PlateIdentifier implements Serializable
public PlateIdentifier(String plateCode, String spaceCodeOrNull) public PlateIdentifier(String plateCode, String spaceCodeOrNull)
{ {
this(plateCode, spaceCodeOrNull, null);
}
public PlateIdentifier(String plateCode, String spaceCodeOrNull, String permId)
{
super(permId);
this.plateCode = plateCode; this.plateCode = plateCode;
this.spaceCodeOrNull = spaceCodeOrNull; this.spaceCodeOrNull = spaceCodeOrNull;
} }
/** a code of the plate */ /**
* A code of the plate.
*/
public String getPlateCode() public String getPlateCode()
{ {
return plateCode; return plateCode;
} }
/** a code of the space to which the plate belongs or null if it is a shared plate */ /**
* A code of the space to which the plate belongs or <code>null</code> if it is a shared plate.
*/
public String tryGetSpaceCode() public String tryGetSpaceCode()
{ {
return spaceCodeOrNull; return spaceCodeOrNull;
} }
@Override /**
public String toString() * Returns the augmented (full) code of this plate.
*/
public String getAugmentedCode()
{ {
return (spaceCodeOrNull != null ? "/" + spaceCodeOrNull : "") + "/" + plateCode; if (spaceCodeOrNull != null)
} {
return "/" + spaceCodeOrNull + "/" + plateCode;
@Override } else
public int hashCode()
{
final int prime = 31;
int result = prime + plateCode.hashCode();
return prime * result + ((spaceCodeOrNull == null) ? 0 : spaceCodeOrNull.hashCode());
}
@Override
public boolean equals(Object obj)
{
if (obj == null || obj instanceof PlateIdentifier == false)
{ {
return false; return "/" + plateCode;
} }
PlateIdentifier that = (PlateIdentifier) obj;
return plateCode.equals(that.getPlateCode())
&& ((spaceCodeOrNull != null && spaceCodeOrNull.equals(that.tryGetSpaceCode())) || (spaceCodeOrNull == null && that
.tryGetSpaceCode() == null));
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment