private String getDebugString(int max) { assert max > 0; StringBuffer result = new StringBuffer(); int start = Math.max(offset - max, 0); int end = Math.min(offset + max, tokens.size()); for (int i = start; i < end; i++) { JavaScriptToken token = tokens.get(i); if (i == offset - 1) { result.append(" ---> "); } result.append(token.getValue()); if (i == offset - 1) { result.append(" <--- "); } } return result.toString(); }
protected int[] computeResizedDimensions(int nw, int nh, int iw, int ih) { int[] dims = new int[2]; // this code keeps thumbnail ratio same as original image double thumbRatio = (double) nw / (double) nh; double imageRatio = (double) iw / (double) ih; if (iw < nw && ih < nh) { dims[0] = iw; dims[1] = ih; } else if (thumbRatio < imageRatio) { dims[0] = nw; dims[1] = (int) Math.ceil(nw / imageRatio); } else { dims[0] = (int) Math.ceil(nh * imageRatio); dims[1] = nh; } return dims; }