All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.ac.manchester.cs.owl.owlapi.CustomFieldSerializerUtil Maven / Gradle / Ivy

package uk.ac.manchester.cs.owl.owlapi;

import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.client.rpc.SerializationStreamReader;
import com.google.gwt.user.client.rpc.SerializationStreamWriter;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.util.CollectionFactory;

import java.util.*;

/**
 * Author: Matthew Horridge
* Stanford University
* Bio-Medical Informatics Research Group
* Date: 20/11/2013 */ public class CustomFieldSerializerUtil { private static void serializeCollection(Collection set, SerializationStreamWriter writer) throws SerializationException { writer.writeInt(set.size()); for(T object : set) { writer.writeObject(object); } } public static void serializeSet(Set set, SerializationStreamWriter writer) throws SerializationException { serializeCollection(set, writer); } public static Set deserializeSet(SerializationStreamReader reader) throws SerializationException { List elements = derserializeCollection(reader); if(elements.isEmpty()) { return Collections.emptySet(); } return CollectionFactory.createSet(elements); } @SuppressWarnings("unchecked") private static List derserializeCollection(SerializationStreamReader reader) throws SerializationException { int size = reader.readInt(); if(size == 0) { return Collections.emptyList(); } List elements = new ArrayList(); for(int i = 0; i < size; i++) { T object = (T) reader.readObject(); elements.add(object); } return elements; } public static void serializeAnnotations(A axiom, SerializationStreamWriter writer) throws SerializationException { Set annotations = axiom.getAnnotations(); serializeSet(annotations, writer); } public static Set deserializeAnnotations(SerializationStreamReader reader) throws SerializationException { return deserializeSet(reader); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy