Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author PiMaster
- */
- package bloxpedition;
- import java.util.ArrayList;
- import java.util.List;
- public class Matrix<T>{
- private List<T> data;
- private int width;
- private int length;
- private int height;
- Matrix(int w,int h,int l){
- resize(w,h,l);
- }
- T get(int x,int y,int z){
- if(x>=width){
- throw new IndexOutOfBoundsException("x greater than or equal to width");}
- if(z>=length){
- throw new IndexOutOfBoundsException("z greater than or equal to length");}
- if(y>=height){
- throw new IndexOutOfBoundsException("y greater than or equal to height");}
- return data.get(z*width*height+y*width+x);
- }
- void set(int x,int y,int z,T value){
- if(x>=width){
- throw new IndexOutOfBoundsException("x greater than or equal to width");}
- if(z>=length){
- throw new IndexOutOfBoundsException("z greater than or equal to length");}
- if(y>=height){
- throw new IndexOutOfBoundsException("y greater than or equal to height");}
- data.set(z*width*height+y*width+x,value);
- }
- void resize(int w,int l,int h){
- if(w<=0 || h<=0 || l<=0){
- throw new IllegalArgumentException("Passed dimension <=0");}
- width=w;
- length=l;
- height=h;
- System.out.println("Calculated size:"+width*length*height);
- data=new ArrayList<T>(width*length*height);
- System.out.println("Size:"+data.size());
- }
- int get_size(){
- return data.size();
- }
- int get_width(){
- return width;
- }
- int get_length(){
- return length;
- }
- int get_height(){
- return height;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement