props)
{
properties = props;
}
/**
* Answers true if this object is either equivalent to, or can be 'improved'
* by, the given entry.
*
* If newEntry has the same id (ignoring case), and doesn't have a conflicting
* file spec or chain code, then update this entry from its file and/or chain
* code.
*
* @param newEntry
* @return true if modifications were made
*/
public boolean updateFrom(PDBEntry newEntry)
{
if (this.equals(newEntry))
{
return true;
}
String newId = newEntry.getId();
if (newId == null || getId() == null)
{
return false; // shouldn't happen
}
boolean idMatches = getId().equalsIgnoreCase(newId);
/*
* Don't update if associated with different structure files
*/
String newFile = newEntry.getFile();
if (newFile != null && getFile() != null)
{
if (!newFile.equals(getFile()))
{
return false;
}
else
{
// files match.
if (!idMatches)
{
// this shouldn't happen, but could do if the id from the
// file is not the same as the id from the authority that provided
// the file
if (!newEntry.fakedPDBId() && !isAuthoritative())
{
return false;
} // otherwise we can update
}
}
}
else
{
// one has data, one doesn't ..
if (!idMatches)
{
return false;
} // otherwise maybe can update
}
/*
* Don't update if associated with different chains (ignoring case)
*/
String newChain = newEntry.getChainCode();
if (newChain != null && newChain.length() > 0 && getChainCode() != null
&& getChainCode().length() > 0
&& !getChainCode().equalsIgnoreCase(newChain))
{
return false;
}
/*
* set file path if not already set
*/
String newType = newEntry.getType();
if (getFile() == null && newFile != null)
{
setFile(newFile);
setType(newType);
}
/*
* set file type if new entry has it and we don't
* (for the case where file was not updated)
*/
if (getType() == null && newType != null)
{
setType(newType);
}
/*
* set chain if not already set (we excluded differing
* chains earlier) (ignoring case change only)
*/
if (newChain != null && newChain.length() > 0
&& !newChain.equalsIgnoreCase(getChainCode()))
{
setChainCode(newChain);
}
/*
* copy any new or modified properties
*/
Enumeration newProps = newEntry.getProperties();
while (newProps.hasMoreElements())
{
/*
* copy properties unless value matches; this defends against changing
* the case of chain_code which is wrapped in a CaseInsensitiveString
*/
String key = newProps.nextElement();
Object value = newEntry.getProperty(key);
if (FAKED_ID.equals(key) || AUTHORITATIVE_ID.equals(key))
{
// we never update the fake ID property
continue;
}
if (!value.equals(getProperty(key)))
{
setProperty(key, value);
}
}
return true;
}
public void setAuthoritative(boolean isAuthoritative)
{
setProperty(AUTHORITATIVE_ID, Boolean.valueOf(isAuthoritative));
}
/**
*
* @return true if the identifier should be preferred over any identifiers
* embedded in the structure data
*/
public boolean isAuthoritative()
{
if (_hasProperty(AUTHORITATIVE_ID))
{
return ((Boolean) getProperty(AUTHORITATIVE_ID));
}
return false;
}
/**
* set when Jalview has manufactured the ID using a local filename
*
* @return
*/
public boolean fakedPDBId()
{
if (_hasProperty(FAKED_ID))
{
return true;
}
return false;
}
public void setFakedPDBId(boolean faked)
{
if (faked)
{
setProperty(FAKED_ID, Boolean.TRUE);
}
else
{
if (properties != null)
{
properties.remove(FAKED_ID);
}
}
}
private boolean _hasProperty(final String key)
{
return (properties != null && properties.containsKey(key));
}
private static final String RETRIEVE_FROM = "RETRIEVE_FROM";
private static final String PROVIDER = "PROVIDER";
private static final String MODELPAGE = "PROVIDERPAGE";
private static final String PROVIDERCATEGORY = "PROVIDERCATEGORY";
/**
* Permanent URI for retrieving the original structure data
*
* @param urlStr
*/
public void setRetrievalUrl(String urlStr)
{
setProperty(RETRIEVE_FROM, urlStr);
}
public boolean hasRetrievalUrl()
{
return _hasProperty(RETRIEVE_FROM);
}
/**
* get the Permanent URI for retrieving the original structure data
*/
public String getRetrievalUrl()
{
return (String) getProperty(RETRIEVE_FROM);
}
/**
* Data provider name - from 3D Beacons
*
* @param provider
*/
public void setProvider(String provider)
{
setProperty(PROVIDER, provider);
}
/**
* Get Data provider name - from 3D Beacons
*
*/
public String getProvider()
{
return (String) getProperty(PROVIDER);
}
/**
* Permanent URI for retrieving the original structure data
*
* @param urlStr
*/
public void setProviderPage(String urlStr)
{
setProperty(MODELPAGE, urlStr);
}
/**
* get the Permanent URI for retrieving the original structure data
*/
public String getProviderPage()
{
return (String) getProperty(MODELPAGE);
}
public boolean hasProviderPage()
{
return _hasProperty(MODELPAGE);
}
public boolean hasProvider()
{
return _hasProperty(PROVIDER);
}
public StructureFile getStructureFile()
{
return sf;
}
public void setStructureFile(StructureFile f)
{
sf = f;
}
public boolean hasStructureFile()
{
return sf != null && sf.inFile != null && sf.inFile.exists();
}
public void setProviderCategory(String providerCategory)
{
setProperty(PROVIDERCATEGORY, providerCategory);
}
public String getProviderCategory()
{
return (String) getProperty(PROVIDERCATEGORY);
}
public boolean hasProviderCategory()
{
return _hasProperty(PROVIDERCATEGORY);
}
}