Class TypeConverter


  • public final class TypeConverter
    extends java.lang.Object
    Static helper routines to convert bags between different types.
    Author:
    Matthew Wakeling, Richard Smith
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static PathQuery getConversionMapQuery​(java.util.List<ApiTemplate> conversionTemplates, java.lang.Class<? extends InterMineObject> typeA, java.lang.Class<? extends InterMineObject> typeB, java.lang.Object bagOrIds)
      Get conversion query for the types provided, edited so that the first type is constrained to be in the bag.
      static PathQuery getConversionQuery​(java.util.List<ApiTemplate> conversionTemplates, java.lang.Class<? extends InterMineObject> typeA, java.lang.Class<? extends InterMineObject> typeB, java.lang.Object bagOrIds)
      Get conversion query for the types provided, edited so that the first type is constrained to be in the bag and the first type is removed from the view list so that the query only returns the converted type.
      static java.util.Map<java.lang.Class,​ApiTemplate> getConversionTemplates​(java.util.List<ApiTemplate> conversionTemplates, java.lang.Class typeA)
      Return a Map from typeB to a TemplateQuery that will convert from typeA to typeB.
      static java.util.Map<InterMineObject,​java.util.List<InterMineObject>> getConvertedObjectMap​(java.util.List<ApiTemplate> conversionTemplates, java.lang.Class<? extends InterMineObject> typeA, java.lang.Class<? extends InterMineObject> typeB, java.lang.Object bagOrIds, ObjectStore os)
      Converts a List of objects from one type to another type using a TemplateQuery, returns a map from an original object to the converted object(s).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getConvertedObjectMap

        public static java.util.Map<InterMineObject,​java.util.List<InterMineObject>> getConvertedObjectMap​(java.util.List<ApiTemplate> conversionTemplates,
                                                                                                                 java.lang.Class<? extends InterMineObject> typeA,
                                                                                                                 java.lang.Class<? extends InterMineObject> typeB,
                                                                                                                 java.lang.Object bagOrIds,
                                                                                                                 ObjectStore os)
                                                                                                          throws InterMineException
        Converts a List of objects from one type to another type using a TemplateQuery, returns a map from an original object to the converted object(s).
        Parameters:
        conversionTemplates - a list of templates to be used for conversion
        typeA - the type to convert from
        typeB - the type to convert to
        bagOrIds - an InterMineBag or Collection of Integer object ids
        os - the ObjectStore to execute queries in
        Returns:
        a Map from original object to a List of converted objects, or null if conversion is possible (because no suitable template is available)
        Throws:
        InterMineException - if an error occurs
      • getConversionMapQuery

        public static PathQuery getConversionMapQuery​(java.util.List<ApiTemplate> conversionTemplates,
                                                      java.lang.Class<? extends InterMineObject> typeA,
                                                      java.lang.Class<? extends InterMineObject> typeB,
                                                      java.lang.Object bagOrIds)
        Get conversion query for the types provided, edited so that the first type is constrained to be in the bag. If there is no suitable conversion template, returns null. Throws a run-time exception if there is such a template, but it is not valid.
        Parameters:
        conversionTemplates - a list of templates to be used for conversion
        typeA - the type to convert from
        typeB - the type to convert to
        bagOrIds - an InterMineBag or Collection of Integer object ids
        Returns:
        a PathQuery that finds a conversion mapping for the given bag
      • getConversionQuery

        public static PathQuery getConversionQuery​(java.util.List<ApiTemplate> conversionTemplates,
                                                   java.lang.Class<? extends InterMineObject> typeA,
                                                   java.lang.Class<? extends InterMineObject> typeB,
                                                   java.lang.Object bagOrIds)
        Get conversion query for the types provided, edited so that the first type is constrained to be in the bag and the first type is removed from the view list so that the query only returns the converted type.
        Parameters:
        conversionTemplates - a list of templates to be used for conversion
        typeA - the type to convert from
        typeB - the type to convert to
        bagOrIds - an InterMineBag or Collection of Integer object identifiers
        Returns:
        a PathQuery that finds converted objects for the given bag
      • getConversionTemplates

        public static java.util.Map<java.lang.Class,​ApiTemplate> getConversionTemplates​(java.util.List<ApiTemplate> conversionTemplates,
                                                                                              java.lang.Class typeA)
        Return a Map from typeB to a TemplateQuery that will convert from typeA to typeB. TODO: return a map of Class -> ApiTemplates
        Parameters:
        conversionTemplates - a list of templates to be used for conversion
        typeA - the type to convert from
        Returns:
        a Map from Class to TemplateQuery