view src/main/java/org/mpi/openmind/scripts/recovery/RecoveryCache.java @ 90:4b6c0b368f46

new UpdateMpiwgDigitalizations script.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Tue, 29 May 2018 21:15:06 +0200
parents 615d27dce9b3
children
line wrap: on
line source

package org.mpi.openmind.scripts.recovery;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mpi.openmind.repository.bo.Entity;
import org.mpi.openmind.repository.bo.Relation;

import cl.maps.triple.TripleKey;
import cl.maps.triple.TripleMap;

public class RecoveryCache {
	private TripleMap<Relation, Long, Long, Long> relMap = new TripleMap<Relation, Long, Long, Long>();
	private Map<Long, Entity> entMap = new HashMap<Long, Entity>();
	
	public Collection<Entity> getEnts(){
		return entMap.values();
	}
	
	public Collection<Relation> getRels(){
		return relMap.values();
	}
	
	public void addEnt(Entity ent){
		if(!entMap.containsKey(ent.getId())){
			entMap.put(ent.getId(), ent);
		}
	}
	
	public void addRel(Relation rel){
		TripleKey<Long, Long, Long> key = new TripleKey<Long, Long, Long>(rel.getSourceId(), rel.getTargetId(), rel.getId());
		relMap.put(key, rel);
	}
	
	public List<Relation> getRelBySrc(Long srcId){
		return this.relMap.getValuesByAKey(srcId);
	}
	
	public List<Relation> getRelByTar(Long tarId){
		return this.relMap.getValuesByBKey(tarId);
	}
	
	public boolean existEnt(Long id){
		return entMap.containsKey(id);
	}
}