package com.github.tkurz.media.fragments;

/**
 * Utilization methods for media fragments
 * <p/>
 * Author: Thomas Kurz (tkurz@apache.org)
 */
public class MediaFragments {

    /**
     * tests for spatial fragments
     * @param uris a set of uris
     * @return true is all uris has spatial fragments, false otherwise
     */
    private static boolean hasSpatial(MediaFragmentURI... uris) {
        for(MediaFragmentURI uri : uris) {
            if(!uri.getMediaFragment().hasSpatialFragment()) return false;
        }
        return true;
    }

    /**
     * tests for temporal fragments
     * @param uris a set of uris
     * @return true is all uris has temporal fragments, false otherwise
     */
    private static boolean hasTemporal(MediaFragmentURI... uris) {
        for(MediaFragmentURI uri : uris) {
            if(!uri.getMediaFragment().hasTemporalFragment()) return false;
        }
        return true;
    }

    /**
     * test if fragments are temporal comparable
     * @param uris a set of uris
     * @return true if media fragments has temporal fragments and their temporal units are equal
     */
    public static boolean temporalComparable(MediaFragmentURI... uris) {
        TemporalFragment.Unit unit = null;
        for(MediaFragmentURI uri : uris) {
            if(!uri.getMediaFragment().hasTemporalFragment()) return false;
            if(unit == null) { unit = uri.getMediaFragment().getTemporalFragment().getUnit(); }
            else if(unit != uri.getMediaFragment().getTemporalFragment().getUnit()) return false;
        }
        return true;
    }

    /**
     * test if fragments are spatial comparable
     * @param uris a set of uris
     * @return true if media fragments has spatial fragments and their spatial types are equal
     */
    public static boolean spatialComparable(MediaFragmentURI... uris) {
        SpatialFragment.Unit unit = null;
        for(MediaFragmentURI uri : uris) {
            if(!uri.getMediaFragment().hasSpatialFragment()) return false;
            if(unit == null) { unit = uri.getMediaFragment().getSpatialFragment().getUnit(); }
            else if(unit != uri.getMediaFragment().getSpatialFragment().getUnit()) return false;
        }
        return true;
    }

}

@@ -918,32 +918,546 @@
 rn true;%0A    %7D%0A%0A
+    /**%0A     * test if fragments are comparable regarding uri%0A     * @param uris a set of uris%0A     * @return true if absolute uri paths are equal%0A     */%0A    public static boolean uriComparable(MediaFragmentURI... uris) %7B%0A        String absolutePath = null;%0A        for(MediaFragmentURI uri : uris) %7B%0A            if(absolutePath == null) %7B%0A                absolutePath = uri.getAbsolutePath();%0A            %7D else if(!absolutePath.equals(uri.getAbsolutePath())) return false;%0A        %7D%0A        return true;%0A    %7D%0A%0A
     /**%0A     * t
@@ -1489,32 +1489,32 @@
 oral comparable%0A
-
      * @param ur
@@ -1743,32 +1743,69 @@
 it unit = null;%0A
+        String absolutePath = null;%0A%0A
         for(Medi
@@ -1899,32 +1899,208 @@
 ) return false;%0A
+%0A            if(absolutePath == null) %7B%0A                absolutePath = uri.getAbsolutePath();%0A            %7D else if(!absolutePath.equals(uri.getAbsolutePath())) return false;%0A%0A
             if(u
@@ -2105,32 +2105,48 @@
 (unit == null) %7B
+%0A               
  unit = uri.getM
@@ -2184,34 +2184,32 @@
 ent().getUnit();
- %7D
 %0A            els
@@ -2196,32 +2196,34 @@
 t();%0A           
+ %7D
  else if(unit !=
@@ -2629,32 +2629,69 @@
 it unit = null;%0A
+        String absolutePath = null;%0A%0A
         for(Medi
@@ -2709,32 +2709,32 @@
 I uri : uris) %7B%0A
-
             if(!
@@ -2784,32 +2784,208 @@
 ) return false;%0A
+%0A            if(absolutePath == null) %7B%0A                absolutePath = uri.getAbsolutePath();%0A            %7D else if(!absolutePath.equals(uri.getAbsolutePath())) return false;%0A%0A
             if(u

add uri similarity to comparable methods