Junior JAVA + PHP Developer
Ricerchiamo un developer Java+Php junior, laureando, neolaureato o diplomato. Inviaci una email a careers@attrakt.net nella quale dovrai provare a rispondere ad alcune di queste domande:
1. Per quale scopo uso questa classe Java?
2. Come potrei migliorare l’efficienza del codice di questa classe Java?
3. L’utilizzo di questa classe, quali problemi potrebbe creare in un contesto Multithreading?
4. Quale importante algoritmo viene utilizzato in questa classe?
5. Potevo seguire un diverso approccio?
We are looking for a junior Java+Php developer (high school degree, student or recent university graduate). Please send us an email at careers@attrakt.net with your answers to this brief test:
1) When would I use this Java class?
2) How might I make this Java class code more efficient?
3) In the use of this class, what problems might take place in a Multithreading context?
4) What important algorythm is being used in this class?
5) Would you suggest a different approach?
————————————–
import java.util.ArrayList; import java.util.StringTokenizer; public class StringSimil { private static final int MAXDISTANCE = 0; private static final int MINWORDPROXIMITY = 2; // http://searchengineland.com/how-to-understand-keywords-in-searcher-context-118188 private static String first_example = "Nevertheless, the ability to be objective about keywords is vital in order to truly understand web searchers. As SEO professionals, we not only need to understand the words and phrases that our target audiences type in to search engine, we also need to understand the context of keyword phrases."; // http://searchengineland.com/interview-with-louis-rosenfeld-author-of-search-analytics-84637 private static String second_example = "SEO professionals utilize a variety of resources to understand the words and phrases that users/searchers type into the commercial Web search engines, as well as to understand searcher behaviors."; public static void main(String[] args) { String firstocc = cleanstr(first_example); String secondocc = cleanstr(second_example); new StringSimil().findSimil(firstocc, secondocc); } private void findSimil(String firstocc, String secondocc) { StringTokenizer ftok = new StringTokenizer(firstocc); StringTokenizer stok = new StringTokenizer(secondocc); try { int[][] fsmatrix = new int[ftok.countTokens()][stok.countTokens()]; ArrayList<String> tokens = new ArrayList<String>(); int fc = 0; int sc = 0; String thistok = null; while (ftok.hasMoreTokens()) { stok = new StringTokenizer(secondocc); thistok = ftok.nextToken(); tokens.add(thistok); while (stok.hasMoreTokens()) { fsmatrix[fc][sc] = getDistance(thistok, stok.nextToken()); sc++; } fc++; sc = 0; } int[] strmin = getWordMinDis(fsmatrix, secondocc); printOut(strmin, secondocc); } catch (Exception e) { System.err.println(e.toString()); } } private void printOut(int[] strmin, String secondocc) { ArrayList<String> tokens = new ArrayList<String>(); StringTokenizer stok = new StringTokenizer(secondocc); while (stok.hasMoreTokens()) { tokens.add(stok.nextToken()); } StringBuffer smstr = new StringBuffer(); int cmindis = 0; for (int h = 0; h < strmin.length; h++) { if (strmin[h] <= MAXDISTANCE) { smstr.append(tokens.get(h) + " "); cmindis++; } else { if (cmindis >= MINWORDPROXIMITY) { System.out.println(smstr.toString().trim()); } smstr = new StringBuffer(); cmindis = 0; } } } private int[] getWordMinDis(int[][] fsmatrix, String secondocc) { int[] strmin = new int[fsmatrix[0].length]; int[][] extm = tMatrix(fsmatrix); int rowSize = extm.length; for (int i = 0; i < rowSize; i++) { int[] extmin = new int[extm[i].length]; for (int j = 0; j < extm[i].length; j++) { extmin[j] = extm[i][j]; } strmin[i] = getMinValue(extmin); } return strmin; } private int[][] tMatrix(int[][] m) { int r = m.length; int c = m[r - 1].length; int[][] t = new int[c][r]; for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { t[j][i] = m[i][j]; } } return t; } private int getMinValue(int[] numbers) { int minValue = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < minValue) { minValue = numbers[i]; } } return minValue; } private static String cleanstr(String s) { return s.replaceAll("[^a-zA-Z0-9]", " "); } private int getDistance(String s, String t) { if (s == null || t == null) { throw new IllegalArgumentException("Strings null"); } int n = s.length(); int m = t.length(); if (n == 0) { return m; } else if (m == 0) { return n; } int p[] = new int[n + 1]; int d[] = new int[n + 1]; int _d[]; int i; int j; char t_j; int cost; for (i = 0; i <= n; i++) { p[i] = i; } for (j = 1; j <= m; j++) { t_j = t.charAt(j - 1); d[0] = j; for (i = 1; i <= n; i++) { cost = s.charAt(i - 1) == t_j ? 0 : 1; d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] + cost); } _d = p; p = d; d = _d; } return p[n]; } }