mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 05:39:18 +01:00
remove unused file, spacing cleanups
This commit is contained in:
@@ -32,7 +32,7 @@ public class OffsetMatcher {
|
||||
String pdeCodeLine, javaCodeLine;
|
||||
boolean matchingNeeded = false;
|
||||
|
||||
|
||||
|
||||
public OffsetMatcher(String pdeCode, String javaCode) {
|
||||
this.pdeCodeLine = pdeCode;
|
||||
this.javaCodeLine = javaCode;
|
||||
@@ -43,15 +43,15 @@ public class OffsetMatcher {
|
||||
} else {
|
||||
matchingNeeded = true;
|
||||
minDistance();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getPdeOffForJavaOff(int start, int length) {
|
||||
// log("PDE :" + pdeCodeLine + "\nJAVA:" + javaCodeLine);
|
||||
// log("getPdeOffForJavaOff() start:" + start + ", len " + length);
|
||||
if(!matchingNeeded) return start;
|
||||
int ans = getPdeOffForJavaOff(start);
|
||||
int ans = getPdeOffForJavaOff(start);
|
||||
int end = getPdeOffForJavaOff(start + length - 1);
|
||||
if(ans == -1 || end == -1){
|
||||
// log("ans: " + ans + " end: " + end);
|
||||
@@ -66,10 +66,10 @@ public class OffsetMatcher {
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getJavaOffForPdeOff(int start, int length) {
|
||||
if(!matchingNeeded) return start;
|
||||
int ans = getJavaOffForPdeOff(start);
|
||||
int ans = getJavaOffForPdeOff(start);
|
||||
// log(start + " pde start off, java start off "
|
||||
// + getJavaOffForPdeOff(start));
|
||||
// log((start + length - 1) + " pde end off, java end off "
|
||||
@@ -77,7 +77,7 @@ public class OffsetMatcher {
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getPdeOffForJavaOff(int javaOff) {
|
||||
if (!matchingNeeded)
|
||||
return javaOff;
|
||||
@@ -86,7 +86,7 @@ public class OffsetMatcher {
|
||||
continue;
|
||||
} else if (offsetMatch.get(i).javaOffset == javaOff) {
|
||||
// int j = i;
|
||||
|
||||
|
||||
// sometimes there are multiple repeated j offsets for a single pde offset
|
||||
// so go to the last one, with bound check
|
||||
while (i > 0 && offsetMatch.get(--i).javaOffset == javaOff) {
|
||||
@@ -107,7 +107,7 @@ public class OffsetMatcher {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getJavaOffForPdeOff(int pdeOff) {
|
||||
if(!matchingNeeded) return pdeOff;
|
||||
for (int i = offsetMatch.size() - 1; i >= 0; i--) {
|
||||
@@ -117,11 +117,11 @@ public class OffsetMatcher {
|
||||
// int j = i;
|
||||
while (i > 0 && offsetMatch.get(--i).pdeOffset == pdeOff) {
|
||||
// log("MP " + offsetMatch.get(i).javaOffset + " "
|
||||
// + offsetMatch.get(i).pdeOffset);
|
||||
// + offsetMatch.get(i).pdeOffset);
|
||||
}
|
||||
if (i + 1 < offsetMatch.size()) { // bounds check, see #2664
|
||||
int javaOff = offsetMatch.get(++i).javaOffset;
|
||||
while (i > 0 && offsetMatch.get(--i).javaOffset == javaOff) {
|
||||
while (i > 0 && offsetMatch.get(--i).javaOffset == javaOff) {
|
||||
}
|
||||
}
|
||||
int j = i + 1;
|
||||
@@ -133,12 +133,12 @@ public class OffsetMatcher {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Finds 'distance' between two Strings.
|
||||
* See Edit Distance Problem
|
||||
* https://secweb.cs.odu.edu/~zeil/cs361/web/website/Lectures/styles/pages/editdistance.html
|
||||
* http://www.stanford.edu/class/cs124/lec/med.pdf
|
||||
* http://www.stanford.edu/class/cs124/lec/med.pdf
|
||||
*/
|
||||
private int minDistance() {
|
||||
|
||||
@@ -192,7 +192,7 @@ public class OffsetMatcher {
|
||||
return dp[len1][len2];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void minDistInGrid(int g[][], int i, int j, int fi, int fj,
|
||||
char s1[], char s2[], ArrayList<OffsetPair> set) {
|
||||
// if(i < s1.length)System.out.print(s1[i] + " <->");
|
||||
@@ -230,7 +230,7 @@ public class OffsetMatcher {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class OffsetPair {
|
||||
public final int pdeOffset, javaOffset;
|
||||
|
||||
@@ -252,7 +252,7 @@ public class OffsetMatcher {
|
||||
// a.getJavaOffForPdeOff(12, 3);
|
||||
// minDistance("static void main(){;", "public static void main(){;");
|
||||
// minDistance("#bb00aa", "0xffbb00aa");
|
||||
// a = new OffsetMatcher("void test(ArrayList<Boid> boids){",
|
||||
// a = new OffsetMatcher("void test(ArrayList<Boid> boids){",
|
||||
// "public void test(ArrayList<Boid> boids){");
|
||||
// a.getJavaOffForPdeOff(20,4);
|
||||
a = new OffsetMatcher("}", "\n");
|
||||
|
||||
@@ -1,287 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
Copyright (c) 2012-15 The Processing Foundation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A class containing multiple utility methods
|
||||
*
|
||||
* @author Manindra Moharana <me@mkmoharana.com>
|
||||
*
|
||||
*/
|
||||
|
||||
public class Utils {
|
||||
|
||||
public ArrayList<Utils.OfsSetTemp> offsetMatch;
|
||||
String word1, word2;
|
||||
public static String reverse(String s) {
|
||||
char w[] = s.toCharArray();
|
||||
for (int i = 0; i < w.length / 2; i++) {
|
||||
char t = w[i];
|
||||
w[i] = w[w.length - 1 - i];
|
||||
w[w.length - 1 - i] = t;
|
||||
}
|
||||
return new String(w);
|
||||
}
|
||||
|
||||
public void getPdeOffForJavaOff(int start, int length){
|
||||
System.out.println("PDE <-> Java" );
|
||||
for (int i = 0; i < offsetMatch.size(); i++) {
|
||||
System.out.print(offsetMatch.get(i).pdeOffset + " <-> " + offsetMatch.get(i).javaOffset);
|
||||
System.out.println(", " + word1.charAt(offsetMatch.get(i).pdeOffset) + " <-> "
|
||||
+ word2.charAt(offsetMatch.get(i).javaOffset));
|
||||
}
|
||||
System.out.println("Length " + offsetMatch.size());
|
||||
System.out.println(start + " java start off, pde start off "
|
||||
+ getPdeOffForJavaOff(start));
|
||||
System.out.println((start + length - 1) + " java end off, pde end off "
|
||||
+ getPdeOffForJavaOff(start + length - 1));
|
||||
}
|
||||
|
||||
public void getJavaOffForPdeOff(int start, int length){
|
||||
// System.out.println("PDE <-> Java" );
|
||||
// for (int i = 0; i < offsetMatch.size(); i++) {
|
||||
// System.out.print(offsetMatch.get(i).pdeOffset + " <-> " + offsetMatch.get(i).javaOffset);
|
||||
// System.out.println(", " + word1.charAt(offsetMatch.get(i).pdeOffset) + " <-> "
|
||||
// + word2.charAt(offsetMatch.get(i).javaOffset));
|
||||
// }
|
||||
// System.out.println("Length " + offsetMatch.size());
|
||||
System.out.println(start + " pde start off, java start off "
|
||||
+ getJavaOffForPdeOff(start));
|
||||
System.out.println((start + length - 1) + " pde end off, java end off "
|
||||
+ getJavaOffForPdeOff(start + length - 1));
|
||||
}
|
||||
|
||||
public int getPdeOffForJavaOff(int javaOff){
|
||||
for (int i = offsetMatch.size() - 1; i >= 0;i--) {
|
||||
if(offsetMatch.get(i).javaOffset < javaOff){
|
||||
continue;
|
||||
}
|
||||
else
|
||||
if(offsetMatch.get(i).javaOffset == javaOff){
|
||||
// int j = i;
|
||||
while(offsetMatch.get(--i).javaOffset == javaOff){
|
||||
System.out.println("MP " + offsetMatch.get(i).javaOffset + " "
|
||||
+ offsetMatch.get(i).pdeOffset);
|
||||
}
|
||||
int pdeOff = offsetMatch.get(++i).pdeOffset;
|
||||
while(offsetMatch.get(--i).pdeOffset == pdeOff);
|
||||
int j = i + 1;
|
||||
if (j > -1 && j < offsetMatch.size())
|
||||
return offsetMatch.get(j).pdeOffset;
|
||||
}
|
||||
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getJavaOffForPdeOff(int pdeOff){
|
||||
for (int i = offsetMatch.size() - 1; i >= 0;i--) {
|
||||
if(offsetMatch.get(i).pdeOffset < pdeOff){
|
||||
continue;
|
||||
}
|
||||
else
|
||||
if(offsetMatch.get(i).pdeOffset == pdeOff){
|
||||
// int j = i;
|
||||
while(offsetMatch.get(--i).pdeOffset == pdeOff){
|
||||
// System.out.println("MP " + offsetMatch.get(i).javaOffset + " "
|
||||
// + offsetMatch.get(i).pdeOffset);
|
||||
}
|
||||
int javaOff = offsetMatch.get(++i).javaOffset;
|
||||
while(offsetMatch.get(--i).javaOffset == javaOff);
|
||||
int j = i + 1;
|
||||
if (j > -1 && j < offsetMatch.size())
|
||||
return offsetMatch.get(j).javaOffset;
|
||||
}
|
||||
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int minDistance(String word1, String word2) {
|
||||
this.word1 = word1;
|
||||
this.word2 = word2;
|
||||
// word1 = reverse(word1);
|
||||
// word2 = reverse(word2);
|
||||
int len1 = word1.length();
|
||||
int len2 = word2.length();
|
||||
System.out.println(word1 + " len: " + len1);
|
||||
System.out.println(word2 + " len: " + len2);
|
||||
// len1+1, len2+1, because finally return dp[len1][len2]
|
||||
int[][] dp = new int[len1 + 1][len2 + 1];
|
||||
|
||||
for (int i = 0; i <= len1; i++) {
|
||||
dp[i][0] = i;
|
||||
}
|
||||
|
||||
for (int j = 0; j <= len2; j++) {
|
||||
dp[0][j] = j;
|
||||
}
|
||||
|
||||
//iterate though, and check last char
|
||||
for (int i = 0; i < len1; i++) {
|
||||
char c1 = word1.charAt(i);
|
||||
for (int j = 0; j < len2; j++) {
|
||||
char c2 = word2.charAt(j);
|
||||
//System.out.print(c1 + "<->" + c2);
|
||||
//if last two chars equal
|
||||
if (c1 == c2) {
|
||||
//update dp value for +1 length
|
||||
dp[i + 1][j + 1] = dp[i][j];
|
||||
// System.out.println();
|
||||
} else {
|
||||
int replace = dp[i][j] + 1;
|
||||
int insert = dp[i][j + 1] + 1;
|
||||
int delete = dp[i + 1][j] + 1;
|
||||
// if (replace < delete) {
|
||||
// System.out.println(" --- D");
|
||||
// } else
|
||||
// System.out.println(" --- R");
|
||||
int min = replace > insert ? insert : replace;
|
||||
min = delete > min ? min : delete;
|
||||
dp[i + 1][j + 1] = min;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for (int i = 0; i < dp.length; i++) {
|
||||
// for (int j = 0; j < dp[0].length; j++) {
|
||||
// System.out.print(dp[i][j] + " ");
|
||||
// }
|
||||
// System.out.println();
|
||||
// }
|
||||
// int maxLen = Math.max(len1, len2)+2;
|
||||
// int pdeCodeMap[] = new int[maxLen], javaCodeMap[] = new int[maxLen];
|
||||
// System.out.println("Edit distance1: " + dp[len1][len2]);
|
||||
ArrayList<OfsSetTemp> alist = new ArrayList<Utils.OfsSetTemp>();
|
||||
offsetMatch = alist;
|
||||
minDistInGrid(dp, len1, len2, 0, 0, word1.toCharArray(),
|
||||
word2.toCharArray(), alist);
|
||||
// System.out.println("PDE-to-Java");
|
||||
// for (int i = 0; i < maxLen; i++) {
|
||||
// System.out.print(pdeCodeMap[i] + " <-> " + javaCodeMap[i]);
|
||||
// System.out.println(", " + word1.charAt(pdeCodeMap[i]) + " <-> "
|
||||
// + word2.charAt(javaCodeMap[i]));
|
||||
// }
|
||||
// for (int i = 0; i < alist.size(); i++) {
|
||||
// System.out.print(alist.get(i).pdeOffset + " <-> " + alist.get(i).javaOffset);
|
||||
// System.out.println(", " + word1.charAt(alist.get(i).pdeOffset) + " <-> "
|
||||
// + word2.charAt(alist.get(i).javaOffset));
|
||||
// }
|
||||
// System.out.println("Length " + alist.size());
|
||||
return dp[len1][len2];
|
||||
}
|
||||
|
||||
public static int distance(String a, String b) {
|
||||
// a = a.toLowerCase();
|
||||
// b = b.toLowerCase();
|
||||
|
||||
// i == 0
|
||||
int[] costs = new int[b.length() + 1];
|
||||
for (int j = 0; j < costs.length; j++)
|
||||
costs[j] = j;
|
||||
for (int i = 1; i <= a.length(); i++) {
|
||||
// j == 0; nw = lev(i - 1, j)
|
||||
costs[0] = i;
|
||||
int nw = i - 1;
|
||||
for (int j = 1; j <= b.length(); j++) {
|
||||
int cj = Math.min(1 + Math.min(costs[j], costs[j - 1]),
|
||||
a.charAt(i - 1) == b.charAt(j - 1) ? nw : nw + 1);
|
||||
nw = costs[j];
|
||||
costs[j] = cj;
|
||||
}
|
||||
}
|
||||
System.out.println("Edit distance2: " + costs[b.length()]);
|
||||
return costs[b.length()];
|
||||
}
|
||||
|
||||
public void minDistInGrid(int g[][], int i, int j, int fi, int fj,
|
||||
char s1[], char s2[], ArrayList<OfsSetTemp> set) {
|
||||
// if(i < s1.length)System.out.print(s1[i] + " <->");
|
||||
// if(j < s2.length)System.out.print(s2[j]);
|
||||
if (i < s1.length && j < s2.length) {
|
||||
// pdeCodeMap[k] = i;
|
||||
// javaCodeMap[k] = j;
|
||||
//System.out.print(s1[i] + " " + i + " <-> " + j + " " + s2[j]);
|
||||
set.add(new OfsSetTemp(i, j));
|
||||
// if (s1[i] != s2[j])
|
||||
// System.out.println("--");
|
||||
}
|
||||
//System.out.println();
|
||||
if (i == fi && j == fj) {
|
||||
//System.out.println("Reached end.");
|
||||
} else {
|
||||
int a = Integer.MAX_VALUE, b = a, c = a;
|
||||
if (i > 0)
|
||||
a = g[i - 1][j];
|
||||
if (j > 0)
|
||||
b = g[i][j - 1];
|
||||
if (i > 0 && j > 0)
|
||||
c = g[i - 1][j - 1];
|
||||
int mini = Math.min(a, Math.min(b, c));
|
||||
if (mini == a) {
|
||||
//System.out.println(s1[i + 1] + " " + s2[j]);
|
||||
minDistInGrid(g, i - 1, j, fi, fj, s1, s2,set);
|
||||
} else if (mini == b) {
|
||||
//System.out.println(s1[i] + " " + s2[j + 1]);
|
||||
minDistInGrid(g, i, j - 1, fi, fj, s1, s2, set);
|
||||
} else if (mini == c) {
|
||||
//System.out.println(s1[i + 1] + " " + s2[j + 1]);
|
||||
minDistInGrid(g, i - 1, j - 1, fi, fj, s1, s2, set);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OfsSetTemp {
|
||||
public final int pdeOffset, javaOffset;
|
||||
public OfsSetTemp(int pde, int java){
|
||||
pdeOffset = pde;
|
||||
javaOffset = java;
|
||||
}
|
||||
}
|
||||
|
||||
// public class OffsetMatch{
|
||||
// public final ArrayList<Integer> pdeOffset, javaOffset;
|
||||
//
|
||||
// public OffsetMatch(){
|
||||
// pdeOffset = new ArrayList<Integer>();
|
||||
// javaOffset = new ArrayList<Integer>();
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void main(String[] args) {
|
||||
// minDistance("c = #qwerty;", "c = 0xffqwerty;");
|
||||
Utils a = new Utils();
|
||||
|
||||
a.minDistance("int a = int(can); int ball;", "int a = PApplet.parseInt(can); int ball;");
|
||||
a.getPdeOffForJavaOff(25, 3);
|
||||
a.getJavaOffForPdeOff(12,3);
|
||||
// minDistance("static void main(){;", "public static void main(){;");
|
||||
// minDistance("#bb00aa", "0xffbb00aa");
|
||||
//a.minDistance("color g = #qwerty;", "int g = 0xffqwerty;");
|
||||
System.out.println("--");
|
||||
a.minDistance("color abc = #qwerty;", "int abc = 0xffqwerty;");
|
||||
a.getPdeOffForJavaOff(4, 3);
|
||||
a.getJavaOffForPdeOff(6,3);
|
||||
// distance("c = #bb00aa;", "c = 0xffbb00aa;");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user