From 4cf04d9fa926d0fed7c6ffc64aaee45d88f5ad15 Mon Sep 17 00:00:00 2001 From: yeom Date: Sat, 17 Sep 2011 23:27:54 +0000 Subject: [PATCH] 1) it passes the linear type checking 2) start annotations 3) removes unnecessary class libraries --- .../src/Analysis/SSJava/LinearTypeCheck.java | 42 +- .../src/Analysis/SSJava/SSJavaAnalysis.java | 19 +- .../SSJava/EyeTracking/Classifier.java | 252 +------ .../SSJava/EyeTracking/ClassifierTree.java | 365 ++-------- .../SSJava/EyeTracking/Deviation.java | 59 -- .../SSJava/EyeTracking/DeviationScanner.java | 108 +-- .../SSJava/EyeTracking/EyeInfoPanel.java | 71 -- .../EyeTracking/IEyeMovementListener.java | 50 -- .../SSJava/EyeTracking/LATTICE.java | 3 + .../Benchmarks/SSJava/EyeTracking/LEA.java | 100 +-- .../SSJava/EyeTracking/LEAImplementation.java | 25 +- .../EyeTracking/StaticSizeArrayList.java | 72 -- Robust/src/ClassLibrary/SSJava/ArrayList.java | 621 ------------------ .../SSJava/ArrayListIterator.java | 64 -- Robust/src/ClassLibrary/SSJava/Iterator.java | 16 - 15 files changed, 201 insertions(+), 1666 deletions(-) delete mode 100644 Robust/src/Benchmarks/SSJava/EyeTracking/Deviation.java delete mode 100644 Robust/src/Benchmarks/SSJava/EyeTracking/EyeInfoPanel.java delete mode 100644 Robust/src/Benchmarks/SSJava/EyeTracking/IEyeMovementListener.java create mode 100644 Robust/src/Benchmarks/SSJava/EyeTracking/LATTICE.java delete mode 100644 Robust/src/Benchmarks/SSJava/EyeTracking/StaticSizeArrayList.java delete mode 100644 Robust/src/ClassLibrary/SSJava/ArrayList.java delete mode 100644 Robust/src/ClassLibrary/SSJava/ArrayListIterator.java delete mode 100644 Robust/src/ClassLibrary/SSJava/Iterator.java diff --git a/Robust/src/Analysis/SSJava/LinearTypeCheck.java b/Robust/src/Analysis/SSJava/LinearTypeCheck.java index 3401093a..77b7de65 100644 --- a/Robust/src/Analysis/SSJava/LinearTypeCheck.java +++ b/Robust/src/Analysis/SSJava/LinearTypeCheck.java @@ -513,15 +513,19 @@ public class LinearTypeCheck { if (en.kind() == Kind.AssignmentNode) { AssignmentNode an = (AssignmentNode) en; - String destName = an.getDest().printNode(0); - if (destName.startsWith("this.")) { - destName = destName.substring(5); - } + boolean postinc = isPostIncAssignment(an); - if (an.getSrc().getType().isNull() && destName.equals(needToNullify)) { - needToNullify = null; - return true; + if (!postinc) { + String destName = an.getDest().printNode(0); + if (destName.startsWith("this.")) { + destName = destName.substring(5); + } + if (an.getSrc().getType().isNull() && destName.equals(needToNullify)) { + needToNullify = null; + return true; + } } + } } @@ -547,13 +551,19 @@ public class LinearTypeCheck { } } - private void checkAssignmentNode(MethodDescriptor md, SymbolTable nametable, AssignmentNode an) { - - boolean postinc = true; + public boolean isPostIncAssignment(AssignmentNode an) { if (an.getOperation().getBaseOp() == null || (an.getOperation().getBaseOp().getOp() != Operation.POSTINC && an.getOperation() - .getBaseOp().getOp() != Operation.POSTDEC)) - postinc = false; + .getBaseOp().getOp() != Operation.POSTDEC)) { + return false; + } else { + return true; + } + } + + private void checkAssignmentNode(MethodDescriptor md, SymbolTable nametable, AssignmentNode an) { + + boolean postinc = isPostIncAssignment(an); if (!postinc) { checkExpressionNode(md, nametable, an.getSrc()); @@ -669,11 +679,15 @@ public class LinearTypeCheck { } prevAssignNode = node; } else if (src.kind() == Kind.ArrayAccessNode) { + ArrayAccessNode aan = (ArrayAccessNode) src; TypeDescriptor srcType = src.getType(); - if (srcType.isPtr() && !srcType.isString()) { + if (srcType.isPtr() && srcType.getArrayCount() > 0) { throw new Error( "Not allowed to create an alias to the middle of the multidimensional array at " + md.getClassDesc().getSourceFileName() + "::" + node.getNumLine()); + } else { + needToNullify = aan.printNode(0); + prevAssignNode = node; } } else if (src.kind() == Kind.CreateObjectNode || src.kind() == Kind.MethodInvokeNode || src.kind() == Kind.ArrayInitializerNode || src.kind() == Kind.LiteralNode) { @@ -739,7 +753,7 @@ public class LinearTypeCheck { } private boolean isReference(TypeDescriptor td) { - if (td.isPtr()) { + if (td.isPtr() && (!td.isString())) { return true; } return false; diff --git a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java index 4eee8062..0c0b477a 100644 --- a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java +++ b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java @@ -113,13 +113,13 @@ public class SSJavaAnalysis { // debugPrint(); // } parseLocationAnnotation(); - inference(); + // inference(); doFlowDownCheck(); doDefinitelyWrittenCheck(); debugDoLoopCheck(); } - - private void inference(){ + + private void inference() { SSJavaInferenceEngine inferEngine = new SSJavaInferenceEngine(this, state); inferEngine.inference(); } @@ -199,6 +199,7 @@ public class SSJavaAnalysis { } } + private void doLinearTypeCheck() { LinearTypeCheck checker = new LinearTypeCheck(this, state); checker.linearTypeCheck(); @@ -363,12 +364,12 @@ public class SSJavaAnalysis { // sanity checks if (locOrder.getThisLoc() != null && !locOrder.containsKey(locOrder.getThisLoc())) { throw new Error("Variable 'this' location '" + locOrder.getThisLoc() - + "' is not defined in the default local variable lattice at " + cd.getSourceFileName()); + + "' is not defined in the local variable lattice at " + cd.getSourceFileName()); } if (locOrder.getGlobalLoc() != null && !locOrder.containsKey(locOrder.getGlobalLoc())) { throw new Error("Variable global location '" + locOrder.getGlobalLoc() - + "' is not defined in the default local variable lattice at " + cd.getSourceFileName()); + + "' is not defined in the local variable lattice at " + cd.getSourceFileName()); } } @@ -435,7 +436,13 @@ public class SSJavaAnalysis { if (md2lattice.containsKey(md)) { return md2lattice.get(md); } else { - return cd2methodDefault.get(md.getClassDesc()); + + if (cd2methodDefault.containsKey(md.getClassDesc())) { + return cd2methodDefault.get(md.getClassDesc()); + } else { + throw new Error("Method Lattice of " + md + " is not defined."); + } + } } diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/Classifier.java b/Robust/src/Benchmarks/SSJava/EyeTracking/Classifier.java index 067a86d1..4f5f8f34 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/Classifier.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/Classifier.java @@ -21,18 +21,22 @@ * * @author Florian */ +@LATTICE("V") +@METHODDEFAULT("OUT= avg); - // - // if (isFace) { - // // here we change the possibility of P(Scanarea_N = (Bright | NotBright) - // // | Face=Yes) - // this.possibilities_FaceYes[i] = - // (((this.possibilityFaceYes - 1) * this.possibilities_FaceYes[i]) + (bright - // ? 0.999f - // : 0.001f)) / this.possibilityFaceYes; - // // - // System.out.println("P(Scannarea"+i+"=bright|Face=Yes) = "+this.possibilities_FaceYes[i]); - // // - // System.out.println("P(Scannarea"+i+"=dark|Face=Yes) = "+(1.0f-this.possibilities_FaceYes[i])); - // } else { - // // here we change the possibility of P(Scanarea_N = (Bright | NotBright) - // // | Face=No) - // this.possibilities_FaceNo[i] = - // (((this.possibilityFaceNo - 1) * this.possibilities_FaceNo[i]) + (bright ? - // 0.999f - // : 0.001f)) / this.possibilityFaceNo; - // // - // System.out.println("P(Scannarea"+i+"=bright|Face=No) = "+this.possibilities_FaceNo[i]); - // // - // System.out.println("P(Scannarea"+i+"=dark|Face=No) = "+(1.0f-this.possibilities_FaceNo[i])); - // } - // - // } - // - // // System.out.println("Average: "+avg); - // // System.out.println(this); - // } - /** * Classifies an images region as face * @@ -141,36 +74,34 @@ public class Classifier { * @param translationY * @return true if this region was classified as face, else false */ - public boolean classifyFace(IntegralImageData image, float scaleFactor, int translationX, - int translationY, float borderline) { + public boolean classifyFace(@LOC("IN") IntegralImageData image, @LOC("IN") float scaleFactor, + @LOC("IN") int translationX, @LOC("IN") int translationY, @LOC("IN") float borderline) { - long values[] = new long[this.scanAreas.length]; + @LOC("V") long values[] = new long[this.scanAreas.length]; - float avg = 0f; - int avgItems = 0; - for (int i = 0; i < this.scanAreas.length; ++i) { - ScanArea scanArea = this.scanAreas[i]; - // System.out.println("scanarea="+scanArea); + @LOC("V") float avg = 0f; + @LOC("V") int avgItems = 0; + for (@LOC("C") int i = 0; i < this.scanAreas.length; ++i) { values[i] = 0l; values[i] += - image.getIntegralAt(translationX + scanArea.getToX(scaleFactor), - translationY + scanArea.getToY(scaleFactor)); + image.getIntegralAt(translationX + scanAreas[i].getToX(scaleFactor), translationY + + scanAreas[i].getToY(scaleFactor)); values[i] += - image.getIntegralAt(translationX + scanArea.getFromX(scaleFactor), translationY - + scanArea.getFromY(scaleFactor)); + image.getIntegralAt(translationX + scanAreas[i].getFromX(scaleFactor), translationY + + scanAreas[i].getFromY(scaleFactor)); values[i] -= - image.getIntegralAt(translationX + scanArea.getToX(scaleFactor), - translationY + scanArea.getFromY(scaleFactor)); + image.getIntegralAt(translationX + scanAreas[i].getToX(scaleFactor), translationY + + scanAreas[i].getFromY(scaleFactor)); values[i] -= - image.getIntegralAt(translationX + scanArea.getFromX(scaleFactor), translationY - + scanArea.getToY(scaleFactor)); + image.getIntegralAt(translationX + scanAreas[i].getFromX(scaleFactor), translationY + + scanAreas[i].getToY(scaleFactor)); - values[i] = (long) (values[i] / ((float) scanArea.getSize(scaleFactor))); + values[i] = (long) (values[i] / ((float) scanAreas[i].getSize(scaleFactor))); avg = ((avgItems * avg) + values[i]) / (++avgItems); } -// System.out.println("avg=" + avg); + // System.out.println("avg=" + avg); // int amountYesNo = this.possibilityFaceNo + this.possibilityFaceYes; @@ -180,15 +111,18 @@ public class Classifier { // as we just maximize the args we don't actually calculate the accurate // possibility - float isFaceYes = 1.0f;// this.possibilityFaceYes / (float)amountYesNo; - float isFaceNo = 1.0f;// this.possibilityFaceNo / (float)amountYesNo; + @LOC("OUT") float isFaceYes = 1.0f;// this.possibilityFaceYes / + // (float)amountYesNo; + @LOC("OUT") float isFaceNo = 1.0f;// this.possibilityFaceNo / + // (float)amountYesNo; - for (int i = 0; i < this.scanAreas.length; ++i) { - boolean bright = (values[i] >= avg); + for (@LOC("C") int i = 0; i < this.scanAreas.length; ++i) { + @LOC("V") boolean bright = (values[i] >= avg); isFaceYes *= (bright ? this.possibilities_FaceYes[i] : 1 - this.possibilities_FaceYes[i]); isFaceNo *= (bright ? this.possibilities_FaceNo[i] : 1 - this.possibilities_FaceNo[i]); } -// System.out.println("avg=" + avg + " yes=" + isFaceYes + " no=" + isFaceNo); + // System.out.println("avg=" + avg + " yes=" + isFaceYes + " no=" + + // isFaceNo); return (isFaceYes >= isFaceNo && (isFaceYes / (isFaceYes + isFaceNo)) > borderline); } @@ -226,129 +160,13 @@ public class Classifier { public String toString() { - String str = ""; - for (int i = 0; i < scanAreas.length; i++) { + @LOC("OUT") String str = ""; + for (@LOC("C") int i = 0; i < scanAreas.length; i++) { str += scanAreas[i].toString() + "\n"; } return str; } - // @Override - // public String toString() { - // StringBuilder sb = new StringBuilder(); - // sb.append("Classifier [ScanAreas: " + this.scanAreas.length); - // int yesNo = this.possibilityFaceYes + this.possibilityFaceNo; - // sb.append(String.format("|Yes: %3.2f| No:%3.2f] (", - // (this.possibilityFaceYes / (float) yesNo) * 100.0f, - // (this.possibilityFaceNo / (float) yesNo) * 100.0f)); - // for (int i = 0; i < this.scanAreas.length; ++i) { - // sb.append(String.format("[%3d|Yes: %3.2f| No: %3.2f], ", i + 1, - // (this.possibilities_FaceYes[i] * 100.0f), (this.possibilities_FaceNo[i] * - // 100.0f))); - // } - // sb.append(")"); - // - // return sb.toString(); - // } - - /** - * Generates a new set of classifiers each with more ScanAreas than the last - * classifier. You can specifiy the amount of classifiers you want to generate - * - * @param amount - * amount of classifiers to create - * @param startAmountScanAreas - * the start amount of scanAreas - if your first classifiers should - * contain 3 items you should give 3 here - * @param incAmountScanAreas - * the amount of which the scanAreas should increase - a simple 2 - * will increase them by 2 every step - * @return a List of classifiers - */ - // public static List generateNewClassifiers(int amount, int - // startAmountScanAreas, - // float incAmountScanAreas) { - // List classifiers = new ArrayList(); - // - // int maxDim = 40; - // Random random = new Random(System.currentTimeMillis()); - // double maxSpace = 2 * Math.PI * Math.pow(50, 2); - // - // for (int i = 0; i < amount; ++i) { - // // we create an odd amount of ScanAreas starting with 1 (3, 5, 7, ...) - // int scanAreaAmount = startAmountScanAreas + (int) - // Math.pow(incAmountScanAreas, i);// + - // // ((i)*incAmountScanAreas+1); - // - // int scanAreaSize = - // randomInt(random, scanAreaAmount * 20, (int) Math.min(maxDim * maxDim, - // maxSpace)) - // / scanAreaAmount; - // // System.out.println("scanAreaSize = "+scanAreaSize); - // - // List scanAreas = new ArrayList(); - // - // for (int j = 0; j < scanAreaAmount; ++j) { - // - // int counter = 0; - // ScanArea scanArea = null; - // do { - // // new the width has the first choice - // int minWidth = (int) Math.ceil(scanAreaSize / (float) maxDim); - // - // int scanAreaWidth = randomInt(random, minWidth, Math.min(maxDim, - // scanAreaSize / 2)); - // int scanAreaHeight = (int) Math.ceil(scanAreaSize / (float) scanAreaWidth); - // - // int radius = - // randomInt(random, 5, Math.min(50 - scanAreaHeight / 2, 50 - scanAreaWidth / - // 2)); - // double angle = random.nextFloat() * 2 * Math.PI; - // - // int posX = (int) (50 + Math.cos(angle) * radius) - (scanAreaWidth / 2); - // int posY = (int) (50 + Math.sin(angle) * radius) - (scanAreaHeight / 2); - // - // // System.out.println("[Angle: "+(angle / - // // (Math.PI*2)*180)+" | radius: "+radius+"]"); - // // - // System.out.println("Area"+j+" is "+posX+", "+posY+" ("+scanAreaWidth+" x "+scanAreaHeight+" = "+((scanAreaWidth*scanAreaHeight))+")"); - // - // // now we get random position for this area - // scanArea = new ScanArea(posX, posY, scanAreaWidth, scanAreaHeight); - // - // counter++; - // } while (scanAreas.contains(scanArea) && counter < 30); - // - // if (counter == 30) { - // j -= 1; - // continue; - // } - // - // scanAreas.add(scanArea); - // } - // - // Classifier classifier = new Classifier(scanAreas.toArray(new ScanArea[0])); - // classifiers.add(classifier); - // } - // - // return classifiers; - // } - - // private static int randomInt(Random random, int from, int to) { - // if (to - from <= 0) - // to = from + 1; - // return from + random.nextInt(to - from); - // } - // - // public static List getDefaultClassifier() { - // List classifier = new ArrayList(); - // - // classifier.add(new Classifier(new ScanArea(30, 30, 30, 30), new - // ScanArea(15, 8, 15, 82), - // new ScanArea(75, 8, 15, 82))); - // - // return classifier; - // } } diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/ClassifierTree.java b/Robust/src/Benchmarks/SSJava/EyeTracking/ClassifierTree.java index 8c3dfffe..54e19f70 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/ClassifierTree.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/ClassifierTree.java @@ -21,149 +21,21 @@ * * @author Florian */ +@LATTICE("C") +@METHODDEFAULT("OUT image.getHeight()) { - // factor = dimension / (float) image.getWidth(); - // newWidth = dimension; - // newHeight = (int) (factor * image.getHeight()); - // } else { - // factor = dimension / (float) image.getHeight(); - // newHeight = dimension; - // newWidth = (int) (factor * image.getWidth()); - // } - // - // if (factor > 1) { - // BufferedImageOp op = new - // ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); - // BufferedImage tmpImage = op.filter(image, null); - // - // return tmpImage; - // } - // - // BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, - // BufferedImage.TYPE_INT_RGB); - // - // Graphics2D g2D = resizedImage.createGraphics(); - // g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, - // RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); - // - // g2D.drawImage(image, 0, 0, newWidth - 1, newHeight - 1, 0, 0, - // image.getWidth() - 1, - // image.getHeight() - 1, null); - // - // BufferedImageOp op = new - // ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); - // BufferedImage tmpImage = op.filter(resizedImage, null); - // - // return tmpImage; - // } - // - // /** - // * Image should have 100x100px and should be in b/w - // * - // * @param image - // */ - // public void learn(BufferedImage image, boolean isFace) { - // IntegralImageData imageData = new IntegralImageData(image); - // for (Classifier classifier : this.classifiers) { - // classifier.learn(imageData, isFace); - // } - // } - // - // public int getLearnedFacesYes() { - // return this.classifiers.get(0).getLearnedFacesYes(); - // } - // - // public int getLearnedFacesNo() { - // return this.classifiers.get(0).getLearnedFacesNo(); - // } - - /** - * Locates a face by linear iteration through all probable face positions - * - * @deprecated use locateFaceRadial instead for improved performance - * @param image - * @return an rectangle representing the actual face position on success or - * null if no face could be detected - */ - // public Rectangle2D locateFace(BufferedImage image) { - // long timeStart = System.currentTimeMillis(); - // - // int resizeTo = 600; - // - // BufferedImage smallImage = resizeImageFittingInto(image, resizeTo); - // IntegralImageData imageData = new IntegralImageData(smallImage); - // - // float factor = image.getWidth() / (float) smallImage.getWidth(); - // - // int maxIterations = 0; - // - // // first we calculate the maximum scale factor for our 200x200 image - // float maxScaleFactor = Math.min(imageData.getWidth() / 100f, - // imageData.getHeight() / 100f); - // - // // we simply won't recognize faces that are smaller than 40x40 px - // float minScaleFactor = 0.5f; - // - // // border for faceYes-possibility must be greater that that - // float maxBorder = 0.999f; - // - // for (float scale = maxScaleFactor; scale > minScaleFactor; scale -= 0.25) { - // int actualDimension = (int) (scale * 100); - // int borderX = imageData.getWidth() - actualDimension; - // int borderY = imageData.getHeight() - actualDimension; - // for (int x = 0; x <= borderX; ++x) { - // yLines: for (int y = 0; y <= borderY; ++y) { - // - // for (int iterations = 0; iterations < this.classifiers.size(); - // ++iterations) { - // Classifier classifier = this.classifiers.get(iterations); - // - // float borderline = - // 0.8f + (iterations / this.classifiers.size() - 1) * (maxBorder - 0.8f); - // if (iterations > maxIterations) - // maxIterations = iterations; - // if (!classifier.classifyFace(imageData, scale, x, y, borderline)) { - // continue yLines; - // } - // } - // - // // if we reach here we have a face recognized because our image went - // // through all - // // classifiers - // - // Rectangle2D faceRect = - // new Rectangle2D.Float(x * factor, y * factor, actualDimension * factor, - // actualDimension * factor); - // - // System.out.println("Time: " + (System.currentTimeMillis() - timeStart) + - // "ms"); - // return faceRect; - // - // } - // } - // } - // - // return null; - // } - /** * Locates a face by searching radial starting at the last known position. If * lastCoordinates are null we simply start in the center of the image. @@ -178,20 +50,22 @@ public class ClassifierTree { * @return an rectangle representing the actual face position on success or * null if no face could be detected */ + @LATTICE("OUT,THIS maxX) continue; // yLines: - for (float yDiff = 0.1f; Math.abs(yDiff) <= maxDiffY; yDiff = + for (@LOC("CXY") float yDiff = 0.1f; Math.abs(yDiff) <= maxDiffY; yDiff = (yDiff + sgn(yDiff) * 0.5f) * -1) { - int yPos = Math.round(startPosY + yDiff); + @LOC("CXY") int yPos = Math.round(startPosY + yDiff); if (yPos < 0 || yPos > maxY) continue; // by now we should have a valid coordinate to process which we should // do now - boolean backToYLines = false; - for (int iterations = 0; iterations < classifiers.size(); ++iterations) { - Classifier classifier = (Classifier) classifiers.get(iterations); - - float borderline = 0.8f + (iterations / (classifiers.size() - 1)) * (maxBorder - 0.8f); - if (!classifier.classifyFace(imageData, factor, xPos, yPos, borderline)) { -// System.out.println("continue yLines; "); + @LOC("CXY") boolean backToYLines = false; + for (@LOC("CXY") int idx = 0; idx < classifiers.length; ++idx) { + @LOC("CXY") float borderline = + 0.8f + (idx / (classifiers.length - 1)) * (maxBorder - 0.8f); + if (!classifiers[idx].classifyFace(imageData, factor, xPos, yPos, borderline)) { backToYLines = true; break; - // continue yLines; + // continue yLines; } } - // if we reach here we have a face recognized because our image went // through all // classifiers @@ -275,7 +147,7 @@ public class ClassifierTree { if (backToYLines) { continue; } - Rectangle2D faceRect = + @LOC("OUT") Rectangle2D faceRect = new Rectangle2D(xPos * originalImageFactor, yPos * originalImageFactor, actualDimmension * originalImageFactor, actualDimmension * originalImageFactor); @@ -292,156 +164,7 @@ public class ClassifierTree { } - // public Rectangle2D locateFaceRadial(BufferedImage image, Rectangle2D - // lastCoordinates) { - // - // int resizeTo = 600; - // - // BufferedImage smallImage = resizeImageFittingInto(image, resizeTo); - // float originalImageFactor = image.getWidth() / (float) - // smallImage.getWidth(); - // IntegralImageData imageData = new IntegralImageData(smallImage); - // - // if (lastCoordinates == null) { - // // if we don't have a last coordinate we just begin in the center - // int smallImageMaxDimension = Math.min(smallImage.getWidth(), - // smallImage.getHeight()); - // lastCoordinates = - // new Rectangle2D.Float((smallImage.getWidth() - smallImageMaxDimension) / - // 2.0f, - // (smallImage.getHeight() - smallImageMaxDimension) / 2.0f, - // smallImageMaxDimension, - // smallImageMaxDimension); - // } else { - // // first we have to scale the last coodinates back relative to the resized - // // image - // lastCoordinates = - // new Rectangle2D.Float((float) (lastCoordinates.getX() * (1 / - // originalImageFactor)), - // (float) (lastCoordinates.getY() * (1 / originalImageFactor)), - // (float) (lastCoordinates.getWidth() * (1 / originalImageFactor)), - // (float) (lastCoordinates.getHeight() * (1 / originalImageFactor))); - // } - // - // float startFactor = (float) (lastCoordinates.getWidth() / 100.0f); - // - // // first we calculate the maximum scale factor for our 200x200 image - // float maxScaleFactor = Math.min(imageData.getWidth() / 100f, - // imageData.getHeight() / 100f); - // // maxScaleFactor = 1.0f; - // - // // we simply won't recognize faces that are smaller than 40x40 px - // float minScaleFactor = 0.5f; - // - // float maxScaleDifference = - // Math.max(Math.abs(maxScaleFactor - startFactor), Math.abs(minScaleFactor - - // startFactor)); - // - // // border for faceYes-possibility must be greater that that - // float maxBorder = 0.999f; - // - // int startPosX = (int) lastCoordinates.getX(); - // int startPosY = (int) lastCoordinates.getX(); - // - // for (float factorDiff = 0.0f; Math.abs(factorDiff) <= maxScaleDifference; - // factorDiff = - // (factorDiff + sgn(factorDiff) * 0.1f) * -1 // we alternate between - // // negative and positiv - // // factors - // ) { - // - // float factor = startFactor + factorDiff; - // if (factor > maxScaleFactor || factor < minScaleFactor) - // continue; - // - // // now we calculate the actualDimmension - // int actualDimmension = (int) (100 * factor); - // int maxX = imageData.getWidth() - actualDimmension; - // int maxY = imageData.getHeight() - actualDimmension; - // - // int maxDiffX = Math.max(Math.abs(startPosX - maxX), startPosX); - // int maxDiffY = Math.max(Math.abs(startPosY - maxY), startPosY); - // - // for (float xDiff = 0.1f; Math.abs(xDiff) <= maxDiffX; xDiff = - // (xDiff + sgn(xDiff) * 0.5f) * -1) { - // int xPos = Math.round(startPosX + xDiff); - // if (xPos < 0 || xPos > maxX) - // continue; - // - // yLines: for (float yDiff = 0.1f; Math.abs(yDiff) <= maxDiffY; yDiff = - // (yDiff + sgn(yDiff) * 0.5f) * -1) { - // int yPos = Math.round(startPosY + yDiff); - // if (yPos < 0 || yPos > maxY) - // continue; - // - // // by now we should have a valid coordinate to process which we should - // // do now - // for (int iterations = 0; iterations < this.classifiers.size(); - // ++iterations) { - // Classifier classifier = this.classifiers.get(iterations); - // - // float borderline = - // 0.8f + (iterations / (this.classifiers.size() - 1)) * (maxBorder - 0.8f); - // - // if (!classifier.classifyFace(imageData, factor, xPos, yPos, borderline)) { - // continue yLines; - // } - // } - // - // // if we reach here we have a face recognized because our image went - // // through all - // // classifiers - // - // Rectangle2D faceRect = - // new Rectangle2D.Float(xPos * originalImageFactor, yPos * - // originalImageFactor, - // actualDimmension * originalImageFactor, actualDimmension * - // originalImageFactor); - // - // return faceRect; - // - // } - // - // } - // - // } - // - // // - // System.out.println("Time: "+(System.currentTimeMillis()-timeStart)+"ms"); - // return null; - // - // } - - // public List getClassifiers() { - // return new ArrayList(this.classifiers); - // } - // - // public static void saveToXml(OutputStream out, ClassifierTree tree) throws - // IOException { - // PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, "UTF-8")); - // writer.write(xStream.toXML(tree)); - // writer.close(); - // } - // - // public static ClassifierTree loadFromXml(InputStream in) throws IOException - // { - // Reader reader = new InputStreamReader(in, "UTF-8"); - // StringBuilder sb = new StringBuilder(); - // - // char[] buffer = new char[1024]; - // int read = 0; - // do { - // read = reader.read(buffer); - // if (read > 0) { - // sb.append(buffer, 0, read); - // } - // } while (read > -1); - // reader.close(); - // - // return (ClassifierTree) xStream.fromXML(sb.toString()); - // } - - private static int sgn(float value) { + private static int sgn(@LOC("IN") float value) { return (value < 0 ? -1 : (value > 0 ? +1 : 1)); } diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/Deviation.java b/Robust/src/Benchmarks/SSJava/EyeTracking/Deviation.java deleted file mode 100644 index 41e3c7a5..00000000 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/Deviation.java +++ /dev/null @@ -1,59 +0,0 @@ -import Analysis.SSJava.Location; - -/* - * Copyright 2009 (c) Florian Frankenberger (darkblue.de) - * - * This file is part of LEA. - * - * LEA is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * LEA is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with LEA. If not, see . - */ - -/** - * Representing an eyes deviation - * - * @author Florian Frankenberger - */ -public class Deviation { - - int directionX, directionY; - String direction; - - public Deviation(String direction, int directionX, int directionY) { - this.directionX = directionX; - this.directionY = directionY; - this.direction = direction; - } - - public boolean concurs(int directionX, int directionY) { - return (directionX == this.directionX && directionY == this.directionY); - } - - public boolean equals(Object o) { - if (!(o instanceof Deviation)) { - return false; - } - - Deviation dev = (Deviation) o; - if (dev.directionX == directionX && dev.directionY == directionY) { - return true; - } - - return false; - } - - public String toString() { - return direction; - } - -} diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/DeviationScanner.java b/Robust/src/Benchmarks/SSJava/EyeTracking/DeviationScanner.java index dfabadee..b5308f50 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/DeviationScanner.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/DeviationScanner.java @@ -22,24 +22,28 @@ * * @author Florian Frankenberger */ +@LATTICE("SIZE= 3) { - double deviationX = 0; - double deviationY = 0; - - EyePosition lastEyePosition = null; - for (int i = 0; i < 3; ++i) { - EyePosition eyePosition = this.eyePositions[i]; - if (lastEyePosition != null) { - deviationX += (eyePosition.getX() - lastEyePosition.getX()); - deviationY += (eyePosition.getY() - lastEyePosition.getY()); + @LOC("DEV") double deviationX = 0; + @LOC("DEV") double deviationY = 0; + + @LOC("DEV") int lastIdx = -1; + for (@LOC("C") int i = 0; i < 3; ++i) { + if (lastIdx != -1) { + deviationX += (eyePositions[i].getX() - eyePositions[lastIdx].getX()); + deviationY += (eyePositions[i].getY() - eyePositions[lastIdx].getY()); } - lastEyePosition = eyePosition; + lastIdx = i; } - final double deviationPercentX = 0.04; - final double deviationPercentY = 0.04; + @LOC("DEV") final double deviationPercentX = 0.04; + @LOC("DEV") final double deviationPercentY = 0.04; deviationX /= faceRect.getWidth(); deviationY /= faceRect.getWidth(); - int deviationAbsoluteX = 0; - int deviationAbsoluteY = 0; + @LOC("DEV") int deviationAbsoluteX = 0; + @LOC("DEV") int deviationAbsoluteY = 0; if (deviationX > deviationPercentX) deviationAbsoluteX = 1; if (deviationX < -deviationPercentX) @@ -111,28 +117,29 @@ public class DeviationScanner { return deviation; } - public static Deviation getDirectionFor(int directionX, int directionY) { + public int getDirectionFor(@LOC("IN") int directionX, @LOC("IN") int directionY) { - if (LEFT_UP.concurs(directionX, directionY)) { + if (directionX == +1 && directionY == -1) { return LEFT_UP; - } else if (UP.concurs(directionX, directionY)) { + } else if (directionX == 0 && directionY == -1) { return UP; - } else if (RIGHT_UP.concurs(directionX, directionY)) { + } else if (directionX == -1 && directionY == -1) { return RIGHT_UP; - } else if (LEFT.concurs(directionX, directionY)) { + } else if (directionX == +1 && directionY == 0) { return LEFT; - } else if (NONE.concurs(directionX, directionY)) { + } else if (directionX == 0 && directionY == 0) { return NONE; - } else if (RIGHT.concurs(directionX, directionY)) { + } else if (directionX == -1 && directionY == 0) { return RIGHT; - } else if (LEFT_DOWN.concurs(directionX, directionY)) { + } else if (directionX == +1 && directionY == +1) { return LEFT_DOWN; - } else if (DOWN.concurs(directionX, directionY)) { + } else if (directionX == 0 && directionY == +1) { return DOWN; - } else if (RIGHT_DOWN.concurs(directionX, directionY)) { + } else if (directionX == -1 && directionY == +1) { return RIGHT_DOWN; } - return null; + + return -1; } public void clear() { @@ -141,4 +148,27 @@ public class DeviationScanner { size = 0; } + public String toStringDeviation(@LOC("IN") int dev) { + if (dev == LEFT_UP) { + return "LEFT_UP"; + } else if (dev == UP) { + return "UP"; + } else if (dev == RIGHT_UP) { + return "RIGHT_UP"; + } else if (dev == LEFT) { + return "LEFT"; + } else if (dev == NONE) { + return "NONE"; + } else if (dev == RIGHT) { + return "RIGHT"; + } else if (dev == LEFT_DOWN) { + return "LEFT_DOWN"; + } else if (dev == DOWN) { + return "DOWN"; + } else if (dev == RIGHT_DOWN) { + return "RIGHT_DOWN"; + } + return "ERROR"; + } + } diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/EyeInfoPanel.java b/Robust/src/Benchmarks/SSJava/EyeTracking/EyeInfoPanel.java deleted file mode 100644 index 544a48d2..00000000 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/EyeInfoPanel.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2009 (c) Florian Frankenberger (darkblue.de) - * - * This file is part of LEA. - * - * LEA is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * LEA is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with LEA. If not, see . - */ - -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; - -/** - * - * @author Florian - */ -class EyeInfoPanel extends InfoPanel { - - private static final long serialVersionUID = 7681992432092759058L; - - public EyeInfoPanel() { - super("Eye Status", new String[] { "nolock.png" }, 0, 100, 40); - } - - public void setDeviation(Deviation deviation) { - if (deviation == null) { - this.setImage(null); - } else { - this.setImage(loadImage(deviation.toString() + ".png")); - } - } - - public void setEyePosition(BufferedImage image, Rectangle2D faceRect, EyePosition eyePosition) { - - BufferedImage faceRectImage = null; - if (image != null && faceRect != null) { - int width = 100; - int height = 40; - - int posX = (int) (faceRect.getX() + eyePosition.getX()); - int posY = (int) (faceRect.getY() + eyePosition.getY()); - - int targetWidth = (int) (0.3 * faceRect.getWidth()); - int targetHeight = (int) (height / (float) width * targetWidth); - - faceRectImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); - - Graphics2D g2D = faceRectImage.createGraphics(); - g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); - - g2D.drawImage(image, 0, 0, width, height, posX - targetWidth / 2, posY - targetHeight / 2, - posX + targetWidth / 2, posY + targetHeight / 2, null); - - } - this.setImage(faceRectImage); - } - -} diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/IEyeMovementListener.java b/Robust/src/Benchmarks/SSJava/EyeTracking/IEyeMovementListener.java deleted file mode 100644 index 339514cb..00000000 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/IEyeMovementListener.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2009 (c) Florian Frankenberger (darkblue.de) - * - * This file is part of LEA. - * - * LEA is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * LEA is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with LEA. If not, see . - */ - - -import de.darkblue.lea.model.Deviation; - -/** - * Implementations of eye movements and face detections should - * look like this. - * s - * @author Florian Frankenberger - */ -public interface IEyeMovementListener { - - /** - * Is called whenever a face has been detected. Only - * if a face was detected onEyeMoved will be - * called (no face = no eye movement) - */ - public void onFaceDetected(); - - /** - * If the face was lost this method is being called - */ - public void onFaceLost(); - - /** - * Gets called whenever an eye movement has been recognized - * - * @param deviation the calculated deviation - */ - public void onEyeMoved(Deviation deviation); - -} diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/LATTICE.java b/Robust/src/Benchmarks/SSJava/EyeTracking/LATTICE.java new file mode 100644 index 00000000..3cb4b1da --- /dev/null +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/LATTICE.java @@ -0,0 +1,3 @@ +public @interface LATTICE { + String value(); +} diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java b/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java index 3aad7e86..74bccd64 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/LEA.java @@ -59,89 +59,6 @@ public class LEA { private DeviationScanner deviationScanner = new DeviationScanner(); private int counter = 0; - // private ImageProcessor imageProcessor; - // - // private class ImageProcessor extends TimedThread { - // - // private FaceAndEyePosition lastPositions = new FaceAndEyePosition(null, - // null); - // private DeviationScanner deviationScanner = new DeviationScanner(); - // private int counter = 0; - // - // private int fps; - // - // public ImageProcessor(int fps) { - // super(fps); - // this.fps = fps; - // } - // - // @Override - // public void doRun() { - // - // BufferedImage image = captureDevice.getImage(); - // if (image == null) - // return; - // - // try { - // FaceAndEyePosition positions = implementation.getEyePosition(image); - // - // if (((lastPositions.getFacePosition() == null && - // positions.getFacePosition() != null) || (lastPositions - // .getFacePosition() != null && positions.getFacePosition() == null)) || - // counter++ > fps) { - // - // if ((lastPositions.getFacePosition() == null && positions.getFacePosition() - // != null) - // || (lastPositions.getFacePosition() != null && positions.getFacePosition() - // == null)) { - // if (positions.getFacePosition() != null) { - // notifyEyeMovementListenerFaceDetected(); - // } else { - // notifyEyeMovementListenerFaceLost(); - // } - // } - // counter = 0; - // if (statusWindow != null) - // statusWindow.getFaceInfoPanel().setFace(image, - // positions.getFacePosition()); - // } - // - // if (positions.getEyePosition() != null) { - // if (statusWindow != null) { - // statusWindow.getEyeInfoPanel().setEyePosition(image, - // positions.getFacePosition(), - // positions.getEyePosition()); - // } - // deviationScanner.addEyePosition(positions.getEyePosition()); - // Deviation deviation = - // deviationScanner.scanForDeviation(positions.getFacePosition());// - // positions.getEyePosition().getDeviation(lastPositions.getEyePosition()); - // - // if (deviation != Deviation.NONE) { - // notifyEyeMovementListenerEyeMoved(deviation); - // } - // - // } else { - // if (statusWindow != null) - // statusWindow.getEyeInfoPanel().setDeviation(null); - // } - // - // lastPositions = positions; - // } catch (Exception e) { - // e.printStackTrace(); - // try { - // close(); - // } catch (Exception e2) { - // } - // } - // } - // - // public synchronized void clearDeviationScanner() { - // this.deviationScanner.clear(); - // } - // - // } - public LEA() { // this.imageProcessor = new // ImageProcessor(this.captureDevice.getFrameRate()); @@ -177,7 +94,7 @@ public class LEA { ImageReader reader = new ImageReader(); - while (i < maxCount) { + SSJAVA: while (i < maxCount) { Image image = reader.readImage("data/b" + i + ".bmp"); i++; if (image == null) { @@ -196,24 +113,13 @@ public class LEA { if (positions.getEyePosition() != null) { deviationScanner.addEyePosition(positions.getEyePosition()); - Deviation deviation = deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition()); + int deviation = deviationScanner.scanForDeviation(positions.getFacePosition());// positions.getEyePosition().getDeviation(lastPositions.getEyePosition()); if (deviation != DeviationScanner.NONE) { - System.out.println("deviation=" + deviation); + System.out.println("deviation=" + deviationScanner.toStringDeviation(deviation)); // notifyEyeMovementListenerEyeMoved(deviation); } } - // else { - // if (statusWindow != null) - // statusWindow.getEyeInfoPanel().setDeviation(null); - // } lastPositions = positions; - // } catch (Exception e) { - // e.printStackTrace(); - // try { - // close(); - // } catch (Exception e2) { - // } - // } } } diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/LEAImplementation.java b/Robust/src/Benchmarks/SSJava/EyeTracking/LEAImplementation.java index fe81654e..141cb872 100644 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/LEAImplementation.java +++ b/Robust/src/Benchmarks/SSJava/EyeTracking/LEAImplementation.java @@ -40,14 +40,15 @@ public class LEAImplementation { EyePosition eyePosition = null; if (faceRect != null) { lastRectangle = faceRect; - Point point = readEyes(image, faceRect); + faceRect = null; + Point point = readEyes(image, lastRectangle); if (point != null) { - eyePosition = new EyePosition(point, faceRect); + eyePosition = new EyePosition(point, lastRectangle); } } System.out.println("eyePosition=" + eyePosition); - return new FaceAndEyePosition(faceRect, eyePosition); + return new FaceAndEyePosition(lastRectangle, eyePosition); } private Point readEyes(Image image, Rectangle2D rect) { @@ -67,9 +68,8 @@ public class LEAImplementation { FileInputStream inputFile = new FileInputStream("facedata.dat"); - classifierTree = new ClassifierTree(); - int numClassifier = Integer.parseInt(inputFile.readLine()); + classifierTree = new ClassifierTree(numClassifier); for (int c = 0; c < numClassifier; c++) { int numArea = Integer.parseInt(inputFile.readLine()); @@ -105,21 +105,8 @@ public class LEAImplementation { classifier.setPossibilityFaceYes(Integer.parseInt(inputFile.readLine())); classifier.setPossibilityFaceNo(Integer.parseInt(inputFile.readLine())); - classifierTree.addClassifier(classifier); + classifierTree.addClassifier(c, classifier); } } - // private Point readEyes(BufferedImage image, Rectangle2D rect) { - // - // // now we cluster the black image points and try to find the inner eye - // /* - // * BlackHoleDetector bhd = new BlackHoleDetector(image, rect); - // * bhd.detect(20); - // * - // * return bhd.getPosition(); - // */ - // - // EyeDetector ed = new EyeDetector(image, rect); - // return ed.detectEye(); - // } } diff --git a/Robust/src/Benchmarks/SSJava/EyeTracking/StaticSizeArrayList.java b/Robust/src/Benchmarks/SSJava/EyeTracking/StaticSizeArrayList.java deleted file mode 100644 index 168369c2..00000000 --- a/Robust/src/Benchmarks/SSJava/EyeTracking/StaticSizeArrayList.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2009 (c) Florian Frankenberger (darkblue.de) - * - * This file is part of LEA. - * - * LEA is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) any - * later version. - * - * LEA is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with LEA. If not, see . - */ - - -/** - * An array with just a static size. If you add more than - * the capacity holds the oldest element gets removed. - *

- * This List is implemented as an ring buffer array. - *

- * TODO: implement the List interface - * - * @author Florian Frankenberger - */ -public class StaticSizeArrayList { - - private Object[] buffer; - private int startPos = 0; - private int pos = 0; - private int size = 0; - - public StaticSizeArrayList(int size) { - this.buffer = new Object[size]; - } - - public synchronized void add(T item) { - this.buffer[pos] = item; - pos = ++pos % buffer.length; - if (size < buffer.length) { - size++; - } else { - this.startPos = ++this.startPos % this.buffer.length; - } - } - - @SuppressWarnings("unchecked") - public synchronized T get(int i) { - if (i >= this.size) - throw new ArrayIndexOutOfBoundsException("Size is "+this.size+" but tried to access item "+i); - - int acPos = (this.startPos + i) % this.buffer.length; - - return (T)this.buffer[acPos]; - } - - public synchronized void clear() { - this.startPos = 0; - this.pos = 0; - this.size = 0; - } - - public synchronized int size() { - return this.size; - } - -} diff --git a/Robust/src/ClassLibrary/SSJava/ArrayList.java b/Robust/src/ClassLibrary/SSJava/ArrayList.java deleted file mode 100644 index 08bb4c64..00000000 --- a/Robust/src/ClassLibrary/SSJava/ArrayList.java +++ /dev/null @@ -1,621 +0,0 @@ -/* ArrayList.java -- JDK1.2's answer to Vector; this is an array-backed - implementation of the List interface - Copyright (C) 1998, 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -//package java.util; - -/*import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.reflect.Array; -*/ -/** - * An array-backed implementation of the List interface. This implements - * all optional list operations, and permits null elements, so that it is - * better than Vector, which it replaces. Random access is roughly constant - * time, and iteration is roughly linear time, so it is nice and fast, with - * less overhead than a LinkedList. - *

- * - * Each list has a capacity, and as the array reaches that capacity it - * is automatically transferred to a larger array. You also have access to - * ensureCapacity and trimToSize to control the backing array's size, avoiding - * reallocation or wasted memory. - *

- * - * ArrayList is not synchronized, so if you need multi-threaded access, - * consider using:
- * List l = Collections.synchronizedList(new ArrayList(...)); - *

- * - * The iterators are fail-fast, meaning that any structural - * modification, except for remove() called on the iterator - * itself, cause the iterator to throw a - * {@link ConcurrentModificationException} rather than exhibit - * non-deterministic behavior. - * - * @author Jon A. Zeppieri - * @author Bryce McKinlay - * @author Eric Blake (ebb9@email.byu.edu) - * @see Collection - * @see List - * @see LinkedList - * @see Vector - * @see Collections#synchronizedList(List) - * @see AbstractList - * @status updated to 1.4 - */ -//public class ArrayList extends AbstractList -// implements List, RandomAccess, Cloneable, Serializable -public class ArrayList -{ - protected transient int modCount; - /** - * Compatible with JDK 1.2 - */ - private static final long serialVersionUID = 8683452581122892189L; - - /** - * The default capacity for new ArrayLists. - */ - private static final int DEFAULT_CAPACITY = 10; - - /** - * The number of elements in this list. - * @serial the list size - */ - private int size; - - /** - * Where the data is stored. - */ - //private transient E[] data; - private transient Object[] data; - - /** - * Construct a new ArrayList with the supplied initial capacity. - * - * @param capacity initial capacity of this ArrayList - * @throws IllegalArgumentException if capacity is negative - */ - public ArrayList(int capacity) - { - // Must explicitly check, to get correct exception. - if (capacity < 0) - throw new Error("Illegal Argument Exception")/*IllegalArgumentException()*/; - data = (Object/*E*/[]) new Object[capacity]; - } - - /** - * Construct a new ArrayList with the default capacity (16). - */ - public ArrayList() - { - this(DEFAULT_CAPACITY); - } - - /** - * Construct a new ArrayList, and initialize it with the elements - * in the supplied Collection. The initial capacity is 110% of the - * Collection's size. - * - * @param c the collection whose elements will initialize this list - * @throws NullPointerException if c is null - */ - /*public ArrayList(Collection c) - { - this((int) (c.size() * 1.1f)); - addAll(c); - }*/ - - /** - * Trims the capacity of this List to be equal to its size; - * a memory saver. - */ - public void trimToSize() - { - // Not a structural change from the perspective of iterators on this list, - // so don't update modCount. - if (size != data.length) - { - Object/*E*/[] newData = /*(ObjectE[])*/ new Object[size]; - System.arraycopy(data, 0, newData, 0, size); - data = newData; - } - } - - /** - * Guarantees that this list will have at least enough capacity to - * hold minCapacity elements. This implementation will grow the list to - * max(current * 2, minCapacity) if (minCapacity > current). The JCL says - * explictly that "this method increases its capacity to minCap", while - * the JDK 1.3 online docs specify that the list will grow to at least the - * size specified. - * - * @param minCapacity the minimum guaranteed capacity - */ - public void ensureCapacity(int minCapacity) - { - int current = data.length; - - if (minCapacity > current) - { - Object/*E*/[] newData = /*(E[])*/ new Object[Math.max(current * 2, minCapacity)]; - System.arraycopy(data, 0, newData, 0, size); - data = newData; - } - } - - /** - * Returns the number of elements in this list. - * - * @return the list size - */ - public int size() - { - return size; - } - - /** - * Checks if the list is empty. - * - * @return true if there are no elements - */ - public boolean isEmpty() - { - return size == 0; - } - - /** - * Returns true iff element is in this ArrayList. - * - * @param e the element whose inclusion in the List is being tested - * @return true if the list contains e - */ - public boolean contains(Object e) - { - return indexOf(e) != -1; - } - - /** - * Returns the lowest index at which element appears in this List, or - * -1 if it does not appear. - * - * @param e the element whose inclusion in the List is being tested - * @return the index where e was found - */ - public int indexOf(Object e) - { - for (int i = 0; i < size; i++) - if (equals(e, data[i])) - return i; - return -1; - } - - /** - * Returns the highest index at which element appears in this List, or - * -1 if it does not appear. - * - * @param e the element whose inclusion in the List is being tested - * @return the index where e was found - */ - public int lastIndexOf(Object e) - { - for (int i = size - 1; i >= 0; i--) - if (equals(e, data[i])) - return i; - return -1; - } - - boolean equals(Object o1, Object o2) - { - return o1 == null ? o2 == null : o1.equals(o2); - } - - /** - * Creates a shallow copy of this ArrayList (elements are not cloned). - * - * @return the cloned object - */ - /*public Object clone() - { - ArrayList clone = null; - try - { - clone = (ArrayList) super.clone(); - //clone = new ArrayList(); - clone.data = (E[]) data.clone(); - } - catch (CloneNotSupportedException e) - { - // Impossible to get here. - } - return clone; - }*/ - - /** - * Returns an Object array containing all of the elements in this ArrayList. - * The array is independent of this list. - * - * @return an array representation of this list - */ - public Object[] toArray() - { - Object/*E*/[] array = /*(E[])*/ new Object[size]; - System.arraycopy(data, 0, array, 0, size); - return array; - } - - /** - * Returns an Array whose component type is the runtime component type of - * the passed-in Array. The returned Array is populated with all of the - * elements in this ArrayList. If the passed-in Array is not large enough - * to store all of the elements in this List, a new Array will be created - * and returned; if the passed-in Array is larger than the size - * of this List, then size() index will be set to null. - * - * @param a the passed-in Array - * @return an array representation of this list - * @throws ArrayStoreException if the runtime type of a does not allow - * an element in this list - * @throws NullPointerException if a is null - */ - /*public T[] toArray(T[] a) - { - if (a.length < size) - a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); - else if (a.length > size) - a[size] = null; - System.arraycopy(data, 0, a, 0, size); - return a; - }*/ - - /** - * Retrieves the element at the user-supplied index. - * - * @param index the index of the element we are fetching - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object/*E*/ get(int index) - { - checkBoundExclusive(index); - return data[index]; - } - - /** - * Sets the element at the specified index. The new element, e, - * can be an object of any type or null. - * - * @param index the index at which the element is being set - * @param e the element to be set - * @return the element previously at the specified index - * @throws IndexOutOfBoundsException if index < 0 || index >= 0 - */ - public Object/*E*/ set(int index, Object/*E*/ e) - { - checkBoundExclusive(index); - Object/*E*/ result = data[index]; - data[index] = e; - return result; - } - - /** - * Appends the supplied element to the end of this list. - * The element, e, can be an object of any type or null. - * - * @param e the element to be appended to this list - * @return true, the add will always succeed - */ - public boolean add(Object/*E*/ e) - { - modCount++; - if (size == data.length) - ensureCapacity(size + 1); - data[size++] = e; - return true; - } - - /** - * Adds the supplied element at the specified index, shifting all - * elements currently at that index or higher one to the right. - * The element, e, can be an object of any type or null. - * - * @param index the index at which the element is being added - * @param e the item being added - * @throws IndexOutOfBoundsException if index < 0 || index > size() - */ - public void add(int index, Object/*E*/ e) - { - checkBoundInclusive(index); - modCount++; - if (size == data.length) - ensureCapacity(size + 1); - if (index != size) - System.arraycopy(data, index, data, index + 1, size - index); - data[index] = e; - size++; - } - - /** - * Removes the element at the user-supplied index. - * - * @param index the index of the element to be removed - * @return the removed Object - * @throws IndexOutOfBoundsException if index < 0 || index >= size() - */ - public Object/*E*/ remove(int index) - { - checkBoundExclusive(index); - Object/*E*/ r = data[index]; - modCount++; - if (index != --size) - System.arraycopy(data, index + 1, data, index, size - index); - // Aid for garbage collection by releasing this pointer. - data[size] = null; - return r; - } - - /** - * Removes all elements from this List - */ - public void clear() - { - if (size > 0) - { - modCount++; - // Allow for garbage collection. - //Arrays.fill(data, 0, size, null); - for(int i = 0; i < size; i++) { - this.data[i] = null; - } - size = 0; - } - } - - /** - * Add each element in the supplied Collection to this List. It is undefined - * what happens if you modify the list while this is taking place; for - * example, if the collection contains this list. c can contain objects - * of any type, as well as null values. - * - * @param c a Collection containing elements to be added to this List - * @return true if the list was modified, in other words c is not empty - * @throws NullPointerException if c is null - */ - /*public boolean addAll(Collection c) - { - return addAll(size, c); - }*/ - - /** - * Add all elements in the supplied collection, inserting them beginning - * at the specified index. c can contain objects of any type, as well - * as null values. - * - * @param index the index at which the elements will be inserted - * @param c the Collection containing the elements to be inserted - * @throws IndexOutOfBoundsException if index < 0 || index > 0 - * @throws NullPointerException if c is null - */ - /*public boolean addAll(int index, Collection c) - { - checkBoundInclusive(index); - Iterator itr = c.iterator(); - int csize = c.size(); - - modCount++; - if (csize + size > data.length) - ensureCapacity(size + csize); - int end = index + csize; - if (size > 0 && index != size) - System.arraycopy(data, index, data, end, size - index); - size += csize; - for ( ; index < end; index++) - data[index] = itr.next(); - return csize > 0; - }*/ - - /** - * Removes all elements in the half-open interval [fromIndex, toIndex). - * Does nothing when toIndex is equal to fromIndex. - * - * @param fromIndex the first index which will be removed - * @param toIndex one greater than the last index which will be removed - * @throws IndexOutOfBoundsException if fromIndex > toIndex - */ - protected void removeRange(int fromIndex, int toIndex) - { - int change = toIndex - fromIndex; - if (change > 0) - { - modCount++; - System.arraycopy(data, toIndex, data, fromIndex, size - toIndex); - size -= change; - } - else if (change < 0) - throw new Error("Index Out Of Bounds Exception")/*IndexOutOfBoundsException()*/; - } - - /** - * Checks that the index is in the range of possible elements (inclusive). - * - * @param index the index to check - * @throws IndexOutOfBoundsException if index > size - */ - private void checkBoundInclusive(int index) - { - // Implementation note: we do not check for negative ranges here, since - // use of a negative index will cause an ArrayIndexOutOfBoundsException, - // a subclass of the required exception, with no effort on our part. - if (index > size) - raiseBoundsError(index); - } - - /** - * Checks that the index is in the range of existing elements (exclusive). - * - * @param index the index to check - * @throws IndexOutOfBoundsException if index >= size - */ - private void checkBoundExclusive(int index) - { - // Implementation note: we do not check for negative ranges here, since - // use of a negative index will cause an ArrayIndexOutOfBoundsException, - // a subclass of the required exception, with no effort on our part. - if (index >= size) - raiseBoundsError(index); - } - - /** - * Raise the ArrayIndexOfOutBoundsException. - * - * @param index the index of the access - * @throws IndexOutOfBoundsException unconditionally - */ - private void raiseBoundsError(int index) - { - // Implementaion note: put in a separate method to make the JITs job easier - // (separate common from uncommon code at method boundaries when trivial to - // do so). - throw new Error/*IndexOutOfBoundsException*/("IndexOutOfBoundsException Index: " + index + ", Size: " + size); - } - - - /** - * Remove from this list all elements contained in the given collection. - * This is not public, due to Sun's API, but this performs in linear - * time while the default behavior of AbstractList would be quadratic. - * - * @param c the collection to filter out - * @return true if this list changed - * @throws NullPointerException if c is null - */ - /*boolean removeAllInternal(Collection c) - { - int i; - int j; - for (i = 0; i < size; i++) - if (c.contains(data[i])) - break; - if (i == size) - return false; - - modCount++; - for (j = i++; i < size; i++) - if (! c.contains(data[i])) - data[j++] = data[i]; - size -= i - j; - return true; - }*/ - - /** - * Retain in this vector only the elements contained in the given collection. - * This is not public, due to Sun's API, but this performs in linear - * time while the default behavior of AbstractList would be quadratic. - * - * @param c the collection to filter by - * @return true if this vector changed - * @throws NullPointerException if c is null - * @since 1.2 - */ - /*boolean retainAllInternal(Collection c) - { - int i; - int j; - for (i = 0; i < size; i++) - if (! c.contains(data[i])) - break; - if (i == size) - return false; - - modCount++; - for (j = i++; i < size; i++) - if (c.contains(data[i])) - data[j++] = data[i]; - size -= i - j; - return true; - }*/ - - /** - * Serializes this object to the given stream. - * - * @param s the stream to write to - * @throws IOException if the underlying stream fails - * @serialData the size field (int), the length of the backing array - * (int), followed by its elements (Objects) in proper order. - */ - /*private void writeObject(ObjectOutputStream s) throws IOException - { - // The 'size' field. - s.defaultWriteObject(); - // We serialize unused list entries to preserve capacity. - int len = data.length; - s.writeInt(len); - // it would be more efficient to just write "size" items, - // this need readObject read "size" items too. - for (int i = 0; i < size; i++) - s.writeObject(data[i]); - }*/ - - /** - * Deserializes this object from the given stream. - * - * @param s the stream to read from - * @throws ClassNotFoundException if the underlying stream fails - * @throws IOException if the underlying stream fails - * @serialData the size field (int), the length of the backing array - * (int), followed by its elements (Objects) in proper order. - */ - /*private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - // the `size' field. - s.defaultReadObject(); - int capacity = s.readInt(); - data = (E[]) new Object[capacity]; - for (int i = 0; i < size; i++) - data[i] = (E) s.readObject(); - }*/ - - public ArrayListIterator iterator() - { - // Bah, Sun's implementation forbids using listIterator(0). - return new ArrayListIterator(this); - } -} diff --git a/Robust/src/ClassLibrary/SSJava/ArrayListIterator.java b/Robust/src/ClassLibrary/SSJava/ArrayListIterator.java deleted file mode 100644 index cb3b226d..00000000 --- a/Robust/src/ClassLibrary/SSJava/ArrayListIterator.java +++ /dev/null @@ -1,64 +0,0 @@ -public class ArrayListIterator extends Iterator { - private int pos; - private int size; - private int last; - private ArrayList list; - - public ArrayListIterator(ArrayList list) { - this.list = list; - this.pos = 0; - this.size = this.list.size(); - this.last = -1; - } - - /** - * Tests to see if there are any more objects to - * return. - * - * @return True if the end of the list has not yet been - * reached. - */ - public boolean hasNext() - { - return pos < size; - } - - /** - * Retrieves the next object from the list. - * - * @return The next object. - * @throws NoSuchElementException if there are - * no more objects to retrieve. - * @throws ConcurrentModificationException if the - * list has been modified elsewhere. - */ - public Object next() - { - if (pos == size) - throw new /*NoSuchElement*/Exception("NoSuchElementException"); - last = pos; - return this.list.get(pos++); - } - - /** - * Removes the last object retrieved by next() - * from the list, if the list supports object removal. - * - * @throws ConcurrentModificationException if the list - * has been modified elsewhere. - * @throws IllegalStateException if the iterator is positioned - * before the start of the list or the last object has already - * been removed. - * @throws UnsupportedOperationException if the list does - * not support removing elements. - */ - public void remove() - { - if (last < 0) - throw new /*IllegalState*/Exception("IllegalStateException"); - this.list.remove(last); - pos--; - size--; - last = -1; - } -} \ No newline at end of file diff --git a/Robust/src/ClassLibrary/SSJava/Iterator.java b/Robust/src/ClassLibrary/SSJava/Iterator.java deleted file mode 100644 index f80ed50d..00000000 --- a/Robust/src/ClassLibrary/SSJava/Iterator.java +++ /dev/null @@ -1,16 +0,0 @@ -public class Iterator { - boolean hasNext() { - System.out.println("Iterator is an abstract class."); - System.exit(-1); - } - - Object next() { - System.out.println("Iterator is an abstract class."); - System.exit(-1); - } - - void remove() { - System.out.println("Iterator is an abstract class."); - System.exit(-1); - } -} -- 2.34.1