/** * {@inheritDoc} */ @Override public T getTargetEntity() { return getTargetEntity(0); }
/** * {@inheritDoc} */ @Override public T removeTargetEntity() { return removeTargetEntity(0); }
/** * Constructs a relationship specifying its id and source entity. * * @param id the URI of the relationship instance. * @param sourceEntity the source entity. */ public AbstractRelationship(URI id, S sourceEntity) { super(id); this.setSourceEntity(sourceEntity); }
/** * {@inheritDoc} */ @Override public void setAllTargetEntities(List<T> targetEntities) { synchronized (this.targetEntities) { if (!targetEntities.equals(this.targetEntities)) { List<T> oldTargetEntities = getAllTargetEntities(); this.targetEntities.clear(); this.targetEntities.addAll(targetEntities); Logger.getLogger(this.getClass()).debug("All Target Entities Set: " + targetEntities + " * " + this); this.notifyElementUpdated(ContextEvent.ALL_TARGETENTITIES_PUT, oldTargetEntities); } } }
/** * Constructs a relationship specifying its source entity. * * @param sourceEntity the source entity. */ public AbstractRelationship(S sourceEntity) { this.setId(relationshipInstanceURI(this.getClass(), sourceEntity.getId())); this.setSourceEntity(sourceEntity); }
/** * {@inheritDoc} */ @Override public final void setSourceEntity(S sourceEntity) { if (sourceEntity != null) if (this.sourceEntity == null || sourceEntity.getClass().equals(this.sourceEntity.getClass()) && sourceEntity.getId().equals(this.sourceEntity.getId())) { this.sourceEntity = sourceEntity; if (this.getId() == null) this.setId(relationshipInstanceURI(this.getClass(), sourceEntity.getId())); } else throw new IllegalArgumentException("entity " + sourceEntity + " not compatible with " + this); else throw new NullPointerException("sourceEntity is null"); }
/** * {@inheritDoc} */ @Override public T setTargetEntity(T targetEntity) { return setTargetEntity(0, targetEntity); }
/** * {@inheritDoc} */ @Override public T removeTargetEntity(int index) { synchronized (targetEntities) { T ent = targetEntities.set(index, null); if (ent != null) { Logger.getLogger(this.getClass()) .debug("Target Entity Removed: (" + index + ", " + ent + ") * " + this); this.notifyElementUpdated(ContextEvent.TARGETENTITY_REMOVED, ent); } return ent; } }
/** * {@inheritDoc} */ @Override public List<T> getAllTargetEntities() { synchronized (targetEntities) { List<T> clone = setUpTargetEntities(); clone.addAll(targetEntities); return clone; } }
/** * {@inheritDoc} */ @Override public void removeAllTargetEntities() { synchronized (targetEntities) { List<T> oldTargetEntities = getAllTargetEntities(); boolean changed = false; for (int i = 0; i < targetEntities.size(); ++i) { T ent = targetEntities.set(i, null); if (ent != null) changed = true; } if (changed) { Logger.getLogger(this.getClass()).debug("All Target Entities Removed * " + this); this.notifyElementUpdated(ContextEvent.ALL_TARGETENTITIES_REMOVED, oldTargetEntities); } } }
/** * {@inheritDoc} */ @Override public int addTargetEntity(T targetEntity) { synchronized (targetEntities) { int size = targetEntities.size(); setTargetEntity(size, targetEntity); return size; } }
/** * {@inheritDoc} */ @Override public T setTargetEntity(int index, T targetEntity) { synchronized (targetEntities) { while (targetEntities.size() <= index) targetEntities.add(null); T oldEntity = targetEntities.set(index, targetEntity); if (targetEntity != oldEntity) { Logger.getLogger(this.getClass()).debug( "Target Entity Set: (" + index + ", " + targetEntity + ") * " + this); this.notifyElementUpdated(ContextEvent.TARGETENTITY_PUT, targetEntity); } return oldEntity; } }
@Override public int removeTargetEntity(T targetEntity) { synchronized (targetEntities) { int index = targetEntities.indexOf(targetEntity); if (index >= 0) removeTargetEntity(index); return index; } }