@Test public void testIndividualsAreOnlyCreatedOnce() throws Exception { ExternalIndividual individual = sut.individual(URI.create("urn:individual"), ExternalIndividual.class); assertThat(sut.individual(URI.create("urn:individual"), ExternalIndividual.class),sameInstance(individual)); }
@Override public <T extends Serializable, S extends Individual<T, S>> S individual(T id, Class<? extends S> clazz) { Individual<T,?> result=individualOfId(id); if(result==null) { result=factory.newIndividual(clazz,id); this.individuals.put(id,result); } else if (!clazz.isInstance(result)) { throw new IllegalStateException("Existing individual '"+id+"' is not compatible with '"+clazz.getCanonicalName()+"' ("+result.getClass().getCanonicalName()+")"); } return clazz.cast(result); }
MutableDataSet implements DataSet { @Override public <T extends Serializable, S extends Individual<T, S>> S individual(T id, Class<? extends S> clazz) { Individual<T,?> result=individualOfId(id); if(result==null) { result=factory.newIndividual(clazz,id); this.individuals.put(id,result); } else if (!clazz.isInstance(result)) { throw new IllegalStateException("Existing individual '"+id+"' is not compatible with '"+clazz.getCanonicalName()+"' ("+result.getClass().getCanonicalName()+")"); } return clazz.cast(result); } }
MutableDataSet implements DataSet { @Override public <T extends Serializable, S extends Individual<T, S>> S individual(T id, Class<? extends S> clazz) { Individual<T,?> result=individualOfId(id); if(result==null) { result=factory.newIndividual(clazz,id); this.individuals.put(id,result); } else if (!clazz.isInstance(result)) { throw new IllegalStateException("Existing individual '"+id+"' is not compatible with '"+clazz.getCanonicalName()+"' ("+result.getClass().getCanonicalName()+")"); } return clazz.cast(result); } MutableDataSet(Name<?> name); }
MutableDataSet implements DataSet { @Override public <T extends Serializable, S extends Individual<T, S>> S individual(T id, Class<? extends S> clazz) { Individual<T,?> result=individualOfId(id); if(result==null) { result=factory.newIndividual(clazz,id); this.individuals.put(id,result); } else if (!clazz.isInstance(result)) { throw new IllegalStateException("Existing individual '"+id+"' is not compatible with '"+clazz.getCanonicalName()+"' ("+result.getClass().getCanonicalName()+")"); } return clazz.cast(result); } MutableDataSet(Name<?> name); @Override Name<?> name(); @Override int numberOfIndividuals(); @Override boolean hasIndividuals(); @Override Collection<Individual<?, ?>> individuals(); @Override Set<Serializable> individualIds(); @Override boolean hasIndividual(Object id); @SuppressWarnings("unchecked") @Override S individualOfId(T id); @Override S individual(T id, Class<? extends S> clazz); @Override Iterator<Individual<?, ?>> iterator(); @Override boolean isEmpty(); @Override void remove(final Individual<?, ?> src); @Override String toString(); }
MutableDataSet implements DataSet { @Override public <T extends Serializable, S extends Individual<T, S>> S individual(T id, Class<? extends S> clazz) { Individual<T,?> result=individualOfId(id); if(result==null) { result=factory.newIndividual(clazz,id); this.individuals.put(id,result); } else if (!clazz.isInstance(result)) { throw new IllegalStateException("Existing individual '"+id+"' is not compatible with '"+clazz.getCanonicalName()+"' ("+result.getClass().getCanonicalName()+")"); } return clazz.cast(result); } MutableDataSet(Name<?> name); @Override Name<?> name(); @Override int numberOfIndividuals(); @Override boolean hasIndividuals(); @Override Collection<Individual<?, ?>> individuals(); @Override Set<Serializable> individualIds(); @Override boolean hasIndividual(Object id); @SuppressWarnings("unchecked") @Override S individualOfId(T id); @Override S individual(T id, Class<? extends S> clazz); @Override Iterator<Individual<?, ?>> iterator(); @Override boolean isEmpty(); @Override void remove(final Individual<?, ?> src); @Override String toString();  }