Permalink
Browse files

also did a major reorganization

  • Loading branch information...
leadVisionary committed Dec 30, 2012
1 parent 94f93ee commit 0fdd75079a583f063a8a511c140040b1fd32171d
Showing with 505 additions and 0 deletions.
  1. +6 −0 src/com/visionarysoftwaresolutions/camera/api/BoundingBox.java
  2. +5 −0 src/com/visionarysoftwaresolutions/camera/api/Camera.java
  3. +5 −0 src/com/visionarysoftwaresolutions/camera/api/Color.java
  4. +6 −0 src/com/visionarysoftwaresolutions/camera/api/Picture.java
  5. +6 −0 src/com/visionarysoftwaresolutions/camera/api/Pixel.java
  6. +6 −0 src/com/visionarysoftwaresolutions/camera/api/Point2D.java
  7. +6 −0 src/com/visionarysoftwaresolutions/camera/api/Viewfinder.java
  8. +22 −0 src/com/visionarysoftwaresolutions/camera/domain/BasicCamera.java
  9. +25 −0 src/com/visionarysoftwaresolutions/camera/domain/BasicPicture.java
  10. +26 −0 src/com/visionarysoftwaresolutions/camera/domain/BasicPixel.java
  11. +23 −0 src/com/visionarysoftwaresolutions/camera/domain/BasicPoint.java
  12. +75 −0 src/com/visionarysoftwaresolutions/camera/domain/BasicViewfinder.java
  13. +19 −0 src/com/visionarysoftwaresolutions/camera/domain/Lens.java
  14. +14 −0 src/com/visionarysoftwaresolutions/camera/domain/RGB.java
  15. +29 −0 src/com/visionarysoftwaresolutions/camera/domain/Screen.java
  16. +7 −0 src/com/visionarysoftwaresolutions/camera/factories/CameraFactory.java
  17. +7 −0 src/com/visionarysoftwaresolutions/camera/factories/ColorFactory.java
  18. +10 −0 src/com/visionarysoftwaresolutions/camera/factories/PictureFactory.java
  19. +11 −0 src/com/visionarysoftwaresolutions/camera/factories/PixelFactory.java
  20. +22 −0 test/com/visionarysoftwaresolutions/camera/domain/CameraTests.java
  21. +23 −0 test/com/visionarysoftwaresolutions/camera/domain/PictureTests.java
  22. +19 −0 test/com/visionarysoftwaresolutions/camera/domain/ScreenTests.java
  23. +38 −0 test/com/visionarysoftwaresolutions/camera/domain/ViewfinderTests.java
  24. +11 −0 test/com/visionarysoftwaresolutions/camera/factories/BasicCameraFactory.java
  25. +20 −0 test/com/visionarysoftwaresolutions/camera/factories/BasicPictureFactory.java
  26. +24 −0 test/com/visionarysoftwaresolutions/camera/factories/CameraFactoryTests.java
  27. +40 −0 test/com/visionarysoftwaresolutions/camera/factories/PictureFactoryTests.java
@@ -0,0 +1,6 @@
+package com.visionarysoftwaresolutions.camera.api;
+
+public interface BoundingBox {
+ int getWidth();
+ int getHeight();
+}
@@ -0,0 +1,5 @@
+package com.visionarysoftwaresolutions.camera.api;
+
+public interface Camera {
+ Picture capture();
+}
@@ -0,0 +1,5 @@
+package com.visionarysoftwaresolutions.camera.api;
+
+public interface Color {
+ Number decimalValue();
+}
@@ -0,0 +1,6 @@
+package com.visionarysoftwaresolutions.camera.api;
+
+public interface Picture {
+ Pixel[] getContents();
+ BoundingBox getDimensions();
+}
@@ -0,0 +1,6 @@
+package com.visionarysoftwaresolutions.camera.api;
+
+public interface Pixel {
+ Point2D point();
+ Color color();
+}
@@ -0,0 +1,6 @@
+package com.visionarysoftwaresolutions.camera.api;
+
+public interface Point2D {
+ int getX();
+ int getY();
+}
@@ -0,0 +1,6 @@
+package com.visionarysoftwaresolutions.camera.api;
+
+public interface Viewfinder {
+ BoundingBox getDimensions();
+ Picture getContents();
+}
@@ -0,0 +1,22 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import com.visionarysoftwaresolutions.camera.api.Camera;
+import com.visionarysoftwaresolutions.camera.api.Picture;
+import com.visionarysoftwaresolutions.camera.api.Viewfinder;
+
+public class BasicCamera implements Camera {
+ Viewfinder view;
+
+ public BasicCamera(Viewfinder v){
+ setViewfinder(v);
+ }
+
+ private void setViewfinder(Viewfinder v) {
+ view = v;
+ }
+
+ @Override
+ public Picture capture() {
+ return view.getContents();
+ }
+}
@@ -0,0 +1,25 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import com.visionarysoftwaresolutions.camera.api.BoundingBox;
+import com.visionarysoftwaresolutions.camera.api.Picture;
+import com.visionarysoftwaresolutions.camera.api.Pixel;
+
+public class BasicPicture implements Picture {
+ private final BoundingBox dimensions;
+ private final Pixel[] contents;
+
+ public BasicPicture(final BoundingBox dims, final Pixel[] results) {
+ contents = results;
+ dimensions = dims;
+ }
+ @Override
+ public Pixel[] getContents() {
+ return contents;
+ }
+
+ @Override
+ public BoundingBox getDimensions() {
+ return dimensions;
+ }
+
+}
@@ -0,0 +1,26 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import com.visionarysoftwaresolutions.camera.api.Color;
+import com.visionarysoftwaresolutions.camera.api.Pixel;
+import com.visionarysoftwaresolutions.camera.api.Point2D;
+
+public class BasicPixel implements Pixel {
+ final Point2D point;
+ final Color color;
+
+ public BasicPixel(final Point2D pt, final Color c) {
+ point = pt;
+ color = c;
+ }
+
+ @Override
+ public Point2D point() {
+ return point;
+ }
+
+ @Override
+ public Color color() {
+ return color;
+ }
+
+}
@@ -0,0 +1,23 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import com.visionarysoftwaresolutions.camera.api.Point2D;
+
+public class BasicPoint implements Point2D {
+ final int x,y;
+
+ public BasicPoint(final int xCordinate, final int yCordinate) {
+ x = xCordinate;
+ y = yCordinate;
+ }
+
+ @Override
+ public int getX() {
+ return x;
+ }
+
+ @Override
+ public int getY() {
+ return y;
+ }
+
+}
@@ -0,0 +1,75 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import com.visionarysoftwaresolutions.camera.api.BoundingBox;
+import com.visionarysoftwaresolutions.camera.api.Color;
+import com.visionarysoftwaresolutions.camera.api.Picture;
+import com.visionarysoftwaresolutions.camera.api.Pixel;
+import com.visionarysoftwaresolutions.camera.api.Point2D;
+import com.visionarysoftwaresolutions.camera.api.Viewfinder;
+import com.visionarysoftwaresolutions.camera.factories.ColorFactory;
+import com.visionarysoftwaresolutions.camera.factories.PictureFactory;
+import com.visionarysoftwaresolutions.camera.factories.PixelFactory;
+
+public class BasicViewfinder implements Viewfinder, PixelFactory {
+ private BoundingBox dimensions;
+ private PictureFactory lens;
+
+ public BasicViewfinder(BoundingBox size, PictureFactory source) {
+ setDimensions(size);
+ setPictureFactory(source);
+ }
+
+ public void setDimensions(BoundingBox dim) {
+ this.dimensions = dim;
+ }
+
+ private void setPictureFactory(PictureFactory source) {
+ this.lens = source;
+ }
+
+ @Override
+ public BoundingBox getDimensions() {
+ return this.dimensions;
+ }
+
+ @Override
+ public Picture getContents() {
+ Pixel[] pixels = pixels(dimensions);
+ return lens.create(dimensions, pixels);
+ }
+
+ @Override
+ public Pixel[] pixels(BoundingBox captured) {
+ Pixel[] pix = new Pixel[captured.getWidth()*captured.getHeight()];
+ byte[] results = capture();
+ for (int i = 0; i < dimensions.getWidth(); i++) {
+ for (int j = 0; j < dimensions.getHeight(); j++) {
+ Pixel p = create(i, j, results);
+ int row_major_offset = i*dimensions.getHeight() + j;
+ pix[row_major_offset] = p;
+ }
+ }
+ return pix;
+ }
+
+ private byte[] capture() {
+ return new byte[dimensions.getWidth()*dimensions.getHeight()];
+ }
+
+ private Pixel create(int x, int y, byte[] toProcess) {
+ Point2D pt = new BasicPoint(x,y);
+ Color result = createColorFromBytes(toProcess, new RGB());
+ return create(pt, result);
+ }
+
+ private Color createColorFromBytes(byte[] toProcess, ColorFactory colorSpace) {
+ // TO DO: fix color processing
+ return null;
+ }
+
+ @Override
+ public Pixel create(Point2D place, Color value) {
+ Pixel pete = new BasicPixel(place, value);
+ return pete;
+ }
+}
@@ -0,0 +1,19 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import com.visionarysoftwaresolutions.camera.api.BoundingBox;
+import com.visionarysoftwaresolutions.camera.api.Picture;
+import com.visionarysoftwaresolutions.camera.api.Pixel;
+import com.visionarysoftwaresolutions.camera.factories.PictureFactory;
+
+public class Lens implements PictureFactory {
+
+ @Override
+ public Picture create(int width, int height, Pixel[] pixels) {
+ return new BasicPicture(new Screen(width,height), pixels);
+ }
+
+ @Override
+ public Picture create(BoundingBox dimensions, Pixel[] pixels) {
+ return new BasicPicture(dimensions, pixels);
+ }
+}
@@ -0,0 +1,14 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import com.visionarysoftwaresolutions.camera.api.Color;
+import com.visionarysoftwaresolutions.camera.factories.ColorFactory;
+
+public class RGB implements ColorFactory {
+
+ @Override
+ public Color create(int decimalValue) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
@@ -0,0 +1,29 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import com.visionarysoftwaresolutions.camera.api.BoundingBox;
+
+public class Screen implements BoundingBox {
+ private final int width,height;
+
+ public Screen(final int width, final int height) {
+ this.width = setIfNonNegative(width);
+ this.height = setIfNonNegative(height);
+ }
+
+ private int setIfNonNegative(int number) {
+ if(number < 0) {
+ throw new IllegalArgumentException("cannot have negative dimensions");
+ }
+ return number;
+ }
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ @Override
+ public int getHeight() {
+ return height;
+ }
+}
@@ -0,0 +1,7 @@
+package com.visionarysoftwaresolutions.camera.factories;
+
+import com.visionarysoftwaresolutions.camera.api.Camera;
+
+public interface CameraFactory {
+ public Camera create();
+}
@@ -0,0 +1,7 @@
+package com.visionarysoftwaresolutions.camera.factories;
+
+import com.visionarysoftwaresolutions.camera.api.Color;
+
+public interface ColorFactory {
+ Color create(int decimalValue);
+}
@@ -0,0 +1,10 @@
+package com.visionarysoftwaresolutions.camera.factories;
+
+import com.visionarysoftwaresolutions.camera.api.BoundingBox;
+import com.visionarysoftwaresolutions.camera.api.Picture;
+import com.visionarysoftwaresolutions.camera.api.Pixel;
+
+public interface PictureFactory {
+ Picture create(BoundingBox dimensions, Pixel[] pixels);
+ Picture create(int width, int height, Pixel[] pixels);
+}
@@ -0,0 +1,11 @@
+package com.visionarysoftwaresolutions.camera.factories;
+
+import com.visionarysoftwaresolutions.camera.api.BoundingBox;
+import com.visionarysoftwaresolutions.camera.api.Color;
+import com.visionarysoftwaresolutions.camera.api.Pixel;
+import com.visionarysoftwaresolutions.camera.api.Point2D;
+
+public interface PixelFactory {
+ Pixel create(Point2D place, Color value);
+ Pixel[] pixels(BoundingBox captured);
+}
@@ -0,0 +1,22 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+import com.visionarysoftwaresolutions.camera.api.Camera;
+import com.visionarysoftwaresolutions.camera.api.Picture;
+import com.visionarysoftwaresolutions.camera.api.Viewfinder;
+
+public class CameraTests {
+
+ @Test
+ public void testCaptureAPicture() {
+ Screen s = new Screen(640,480);
+ Lens basic = new Lens();
+ Viewfinder contents = new BasicViewfinder(s, basic);
+ Camera toTest = new BasicCamera(contents);
+ Picture result = toTest.capture();
+ assertNotNull(result);
+ }
+}
@@ -0,0 +1,23 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import com.visionarysoftwaresolutions.camera.api.BoundingBox;
+import com.visionarysoftwaresolutions.camera.api.Picture;
+import com.visionarysoftwaresolutions.camera.api.Pixel;
+import com.visionarysoftwaresolutions.camera.domain.Screen;
+import com.visionarysoftwaresolutions.camera.domain.BasicPicture;
+
+public class PictureTests {
+ @Test
+ public void canCreateAPicture() {
+ int width = 200, height = 200;
+ BoundingBox dim = new Screen(width, height);
+ Pixel[] pix = new BasicPixel[width*height*3];
+ Picture toTest = new BasicPicture(dim,pix);
+ assertEquals(dim, toTest.getDimensions());
+ assertArrayEquals(pix, toTest.getContents());
+ }
+}
@@ -0,0 +1,19 @@
+package com.visionarysoftwaresolutions.camera.domain;
+
+import org.junit.Test;
+
+import com.visionarysoftwaresolutions.camera.domain.Screen;
+
+public class ScreenTests {
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNegativeWidth() {
+ new Screen(-10, 400);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testNegativeHeight() {
+ new Screen(400, -10);
+ }
+
+}
Oops, something went wrong.

0 comments on commit 0fdd750

Please sign in to comment.