LapisSea

Untitled

Aug 15th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package com.lapissea.opengl.program.rendering.gl.model;
  2.  
  3. import java.io.InputStream;
  4.  
  5. import com.lapissea.opengl.program.rendering.gl.model.ObjModelLoader.ModelData;
  6. import com.lapissea.opengl.program.util.UtilM;
  7.  
  8. public abstract class ModelParser{
  9.    
  10.     private static interface SimpleExtensionCheck{
  11.        
  12.         boolean match(String extension);
  13.     }
  14.    
  15.     private static final SimpleExtensionCheck DEFAULT=extension->{
  16.         throw new IllegalStateException("Extension checking not initialised!");
  17.     };
  18.    
  19.     private SimpleExtensionCheck defaultCheck=DEFAULT;
  20.    
  21.     public ModelParser(){}
  22.    
  23.     public ModelParser(String...extensions){
  24.         setSimpleExtensionCheck(extensions);
  25.     }
  26.    
  27.     protected void setSimpleExtensionCheck(String...extensions){
  28.         if(extensions.length==0) throw new IllegalStateException("No extensions defined!");
  29.        
  30.         if(extensions.length==1){
  31.             String extensionMatch=extensions[0];
  32.             defaultCheck=extension->extensionMatch.equalsIgnoreCase(extension);
  33.         }else{
  34.             defaultCheck=extension->{
  35.                 for(String extensionMatch:extensions){
  36.                     if(extensionMatch.equalsIgnoreCase(extension)) return true;
  37.                 }
  38.                 return false;
  39.             };
  40.         }
  41.        
  42.     }
  43.    
  44.     public ModelData load(String location){
  45.         return load(location, UtilM.getResource(location));
  46.     }
  47.    
  48.     public abstract ModelData load(String location, InputStream modelStream);
  49.    
  50.     /**
  51.      * returns if this parser is able to read data of a model with an extension
  52.      *
  53.      * @param extension
  54.      *            = string of the model file extension (Without a dot)
  55.      * @return true if parser supports extension
  56.      */
  57.     public boolean extensionSupported(String extension){
  58.         return defaultCheck.match(extension);
  59.     }
  60. }
Add Comment
Please, Sign In to add comment