/** * Build a {@PListObject} from a string that matches one of the tags defined in {@link Constants}. * * @param tag * @param value can be null if tag equals {@link Constants#TAG_BOOL_FALSE} or {@link * Constants#TAG_BOOL_TRUE}. * @throws Exception * @todo replace with factory for PListObject */ public PListObject buildObject(java.lang.String tag, java.lang.String value) throws Exception { if (null == tag) { throw new Exception("Cannot add a child with a null tag to a PList."); } PListObject ret = null; if (tag.equalsIgnoreCase(Constants.TAG_INTEGER)) { ret = new Integer(); ((Integer) ret).setValue(value); } else if (tag.equalsIgnoreCase(Constants.TAG_STRING)) { ret = new String(); ((String) ret).setValue(value); } else if (tag.equalsIgnoreCase(Constants.TAG_REAL)) { ret = new Real(); ((Real) ret).setValue(value); } else if (tag.equalsIgnoreCase(Constants.TAG_DATE)) { ret = new Date(); ((Date) ret).setValue(value); } else if (tag.equalsIgnoreCase(Constants.TAG_BOOL_FALSE)) { ret = new False(); } else if (tag.equalsIgnoreCase(Constants.TAG_BOOL_TRUE)) { ret = new True(); } else if (tag.equalsIgnoreCase(Constants.TAG_DATA)) { ret = new Data(); ((Data) ret).setValue(value.trim(), true); } else if (tag.equalsIgnoreCase(Constants.TAG_DICT)) { ret = new Dict(); } else if (tag.equalsIgnoreCase(Constants.TAG_PLIST_ARRAY)) { ret = new Array(); } return ret; }
/** * Turn a flattened 2D (string, double) string sequence into its corresponding map * * @param str2DMap Flattened 2D array input * @param strKVDelimiter Key-Value delimiter string * @param strRecordDelimiter Record delimiter string * @param bSkipNullValue Indicates whether NULL Values are to be skipped * @param strNULLString NULL string * @return [String, double] map */ public static final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> FlatStringTo2DSDMap( final java.lang.String str2DMap, final java.lang.String strKVDelimiter, final java.lang.String strRecordDelimiter, final boolean bSkipNullValue, final java.lang.String strNULLString) { if (null == str2DMap || str2DMap.isEmpty() || null == strNULLString || strNULLString.isEmpty() || strNULLString.equalsIgnoreCase(str2DMap) || null == strKVDelimiter || strKVDelimiter.isEmpty() || null == strRecordDelimiter || strRecordDelimiter.isEmpty()) return null; java.lang.String[] astrRecord = org.drip.math.common.StringUtil.Split(str2DMap, strRecordDelimiter); if (null == astrRecord || 0 == astrRecord.length) return null; org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> map2D = new org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>(); for (int i = 0; i < astrRecord.length; ++i) { if (null == astrRecord[i] || astrRecord[i].isEmpty() || strNULLString.equalsIgnoreCase(astrRecord[i])) continue; java.lang.String[] astrKVPair = org.drip.math.common.StringUtil.Split(astrRecord[i], strKVDelimiter); if (null == astrKVPair || 2 != astrKVPair.length || null == astrKVPair[0] || astrKVPair[0].isEmpty() || strNULLString.equalsIgnoreCase(astrKVPair[0]) || (bSkipNullValue && (null == astrKVPair[1] || astrKVPair[1].isEmpty() || strNULLString.equalsIgnoreCase(astrKVPair[1])))) continue; map2D.put(astrKVPair[0], new java.lang.Double(astrKVPair[1])); } if (0 == map2D.size()) return null; return map2D; }
private int fetchScore(net.heinke.cbingutter.game.player.Player p) { boolean success = false; java.lang.String input = null; while (!success) { System.out.print(p.getPlayerName() + " Enter score: "); java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); try { input = br.readLine().trim(); if (Validator.validateScore(input, p)) { success = true; } } catch (java.io.IOException e) { continue; } } if (input.equalsIgnoreCase("X")) { return Constants.MAX_PINS_PER_FRAME; } else { if (input.equals("/")) { net.heinke.cbingutter.game.frame.Frame f = p.getCurrentFrame(); return f.pinsRemaining(); } } return Integer.parseInt(input); }
public static boolean validateScore( java.lang.String input, net.heinke.cbingutter.game.player.Player p) { java.lang.String pattern = "^[0-9/Xx]$"; if (!input.matches(pattern)) { ScoreboardPainter.printMessage("Please enter 0-9, X or /"); return false; } net.heinke.cbingutter.game.frame.Frame f = p.getCurrentFrame(); if (!input.equals("/") && !input.equalsIgnoreCase("X")) { int score = Integer.parseInt(input); if (++score > Constants.MAX_PINS_PER_FRAME) { ScoreboardPainter.printMessage("Please enter 0-9, X or /"); return false; } else { if (score < 0) { ScoreboardPainter.printMessage("Please enter a positive score"); return false; } } if (f != null && !f.isCompleted()) { if (f.pinsRemaining() < score) { ScoreboardPainter.printMessage("You can't hit pins that don't exist"); return false; } } } else { if (f != null && !f.isCompleted() && input.equalsIgnoreCase("X")) { ScoreboardPainter.printMessage("Please enter your actual score or /"); return false; } else { if (input.equals("/") && (f == null || f.isCompleted())) { ScoreboardPainter.printMessage("Did you meant to enter X?"); return false; } } } return true; }
/** * Create an uncalibrated Stretch instance over the specified Predictor Ordinate Array using the * specified Basis Spline Parameters for the Segment. * * @param adblPredictorOrdinate Predictor Ordinate Array * @param aSCBC Array of Segment Builder Parameters * @return Stretch instance */ public static final org.drip.spline.segment.ConstitutiveState[] CreateSegmentSet( final double[] adblPredictorOrdinate, final org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC) { if (null == adblPredictorOrdinate || null == aSCBC) return null; int iNumSegment = adblPredictorOrdinate.length - 1; if (1 > iNumSegment || iNumSegment != aSCBC.length) return null; org.drip.spline.segment.ConstitutiveState[] aCS = new org.drip.spline.segment.ConstitutiveState[iNumSegment]; for (int i = 0; i < iNumSegment; ++i) { if (null == aSCBC[i]) return null; java.lang.String strBasisSpline = aSCBC[i].basisSpline(); if (null == strBasisSpline || (!BASIS_SPLINE_POLYNOMIAL.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_BERNSTEIN_POLYNOMIAL.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_HYPERBOLIC_TENSION.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_EXPONENTIAL_TENSION.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_KAKLIS_PANDELIS.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_EXPONENTIAL_RATIONAL.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_EXPONENTIAL_MIXTURE.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_KLK_EXPONENTIAL_TENSION.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_KLK_HYPERBOLIC_TENSION.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_KLK_RATIONAL_LINEAR_TENSION.equalsIgnoreCase(strBasisSpline) && !BASIS_SPLINE_KLK_RATIONAL_QUADRATIC_TENSION.equalsIgnoreCase(strBasisSpline))) return null; if (BASIS_SPLINE_POLYNOMIAL.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.basis.FunctionSetBuilder.PolynomialBasisSet( (org.drip.spline.basis.PolynomialFunctionSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_BERNSTEIN_POLYNOMIAL.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.basis.FunctionSetBuilder.BernsteinPolynomialBasisSet( (org.drip.spline.basis.PolynomialFunctionSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_HYPERBOLIC_TENSION.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.basis.FunctionSetBuilder.HyperbolicTensionBasisSet( (org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_EXPONENTIAL_TENSION.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.basis.FunctionSetBuilder.ExponentialTensionBasisSet( (org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_KAKLIS_PANDELIS.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.basis.FunctionSetBuilder.KaklisPandelisBasisSet( (org.drip.spline.basis.KaklisPandelisSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_EXPONENTIAL_RATIONAL.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.basis.FunctionSetBuilder.ExponentialRationalBasisSet( (org.drip.spline.basis.ExponentialRationalSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_EXPONENTIAL_MIXTURE.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.basis.FunctionSetBuilder.ExponentialMixtureBasisSet( (org.drip.spline.basis.ExponentialMixtureSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_KLK_EXPONENTIAL_TENSION.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.tension.KochLycheKvasovFamily.FromExponentialPrimitive( (org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_KLK_HYPERBOLIC_TENSION.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.tension.KochLycheKvasovFamily.FromHyperbolicPrimitive( (org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_KLK_RATIONAL_LINEAR_TENSION.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.tension.KochLycheKvasovFamily.FromRationalLinearPrimitive( (org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } else if (BASIS_SPLINE_KLK_RATIONAL_QUADRATIC_TENSION.equalsIgnoreCase(strBasisSpline)) { if (null == (aCS[i] = org.drip.spline.segment.ConstitutiveState.Create( adblPredictorOrdinate[i], adblPredictorOrdinate[i + 1], org.drip.spline.tension.KochLycheKvasovFamily.FromRationalQuadraticPrimitive( (org.drip.spline.basis.ExponentialTensionSetParams) aSCBC[i].basisSetParams()), aSCBC[i].shapeController(), aSCBC[i].inelasticParams()))) return null; } } return aCS; }
public void parseDescriptor(java.lang.String descriptor) { if (methodName.equalsIgnoreCase("<clinit>")) { methodName = "static"; descriptor = ""; accessSpecifiers = new java.lang.String[] {""}; return; } int charIndex = 0; java.lang.String parameterString = descriptor.substring(1, descriptor.lastIndexOf(")")); java.lang.String returnString = descriptor.substring(descriptor.lastIndexOf(")") + 1); if (returnString.trim().charAt(0) == 'L' || returnString.trim().charAt(0) == '[') this.setReturnTypeAsObjectOrArrayType(true); else this.setReturnTypeAsObjectOrArrayType(false); java.lang.String arrString = ""; // while(charIndex < parameterString.length()) while (parameterString.length() > 0) { if (parameterString.startsWith("L")) { java.lang.String objectString = parameterString.substring(0, parameterString.indexOf(";")); objectString = objectString.replace('/', '.'); parameters.add(objectString); charIndex = charIndex + (objectString.length() + 2); parameterString = parameterString.substring(parameterString.indexOf(";") + 1); } else { char parameterChar = parameterString.charAt(0); if (parameterChar == '[') { arrString = ""; while (parameterString.startsWith("[")) { arrString += "["; parameterString = parameterString.substring(1, parameterString.length()); isParameterArray = true; } java.lang.String objectString = ""; if (parameterString.charAt(0) == 'L') { objectString = parameterString.substring(0, parameterString.indexOf(";")); parameterString = parameterString.substring(parameterString.indexOf(";") + 1); objectString = objectString.replace('/', '.'); parameters.add(arrString + objectString); isParameterArray = false; } /* * while(objectString.startsWith("[")) { arrString += "["; * objectString = * objectString.substring(1,objectString.length()); } * objectString = objectString.substring(1); objectString = * objectString.replace('/','.'); * parameters.add(objectString); charIndex = charIndex + * (objectString.length() + 2); * parameters.add(arrString+objectString); */ } else { if (parameterChar == 'I') { if (isParameterArray) { parameters.add(arrString + "int"); isParameterArray = false; } else { parameters.add("int"); } } if (parameterChar == 'B') { if (isParameterArray) { parameters.add(arrString + "byte"); isParameterArray = false; } else { parameters.add("byte"); } } if (parameterChar == 'C') { if (isParameterArray) { parameters.add(arrString + "char"); isParameterArray = false; } else { parameters.add("char"); } } if (parameterChar == 'D') { if (isParameterArray) { parameters.add(arrString + "double"); isParameterArray = false; } else { parameters.add("double"); } } if (parameterChar == 'F') { if (isParameterArray) { parameters.add(arrString + "float"); isParameterArray = false; } else { parameters.add("float"); } } if (parameterChar == 'J') { if (isParameterArray) { parameters.add(arrString + "long"); isParameterArray = false; } else { parameters.add("long"); } } if (parameterChar == 'S') { if (isParameterArray) { parameters.add(arrString + "short"); isParameterArray = false; } else { parameters.add("short"); } } if (parameterChar == 'Z') { if (isParameterArray) { parameters.add(arrString + "boolean"); isParameterArray = false; } else { parameters.add("boolean"); } } parameterString = parameterString.substring(1); } } } if (returnString.indexOf(";") != -1) { returnString = returnString.substring(0, returnString.indexOf(";")); } while (returnString.length() > 0) { // System.out.println(); if (returnString.startsWith("L")) { // System.out.println(returnString + " "+returnType.length()); returnType = returnString.substring(1, returnString.length()); returnType = returnType.replace('/', '.'); returnString = ""; } else { if (returnString.equals("I")) { returnType = "int"; returnString = ""; } if (returnString.equals("B")) { returnType = "byte"; returnString = ""; } if (returnString.equals("C")) { returnType = "char"; returnString = ""; } if (returnString.equals("D")) { returnType = "double"; returnString = ""; } if (returnString.equals("F")) { returnType = "float"; returnString = ""; } if (returnString.equals("J")) { returnType = "long"; returnString = ""; } if (returnString.equals("S")) { returnType = "short"; returnString = ""; } if (returnString.equals("Z")) { returnType = "boolean"; returnString = ""; } if (returnString.equals("V")) { returnType = "void"; returnString = ""; } if (returnString.startsWith("[")) { returnTypeIsArray = true; returnTypeArrayDimension = returnString.lastIndexOf("[") + 1; if (returnString.indexOf("L") != -1) { returnType = returnString.substring(returnString.lastIndexOf("[") + 2); returnType = returnType.replace('/', '.'); returnString = ""; // returnString =returnType; } else { returnString = returnString.substring(returnString.lastIndexOf("[") + 1); // returnString = ""; } } } } }
/** * Turn a flattened 4D (string, string, string, double) string sequence into its corresponding map * * @param str4DMap Flattened 4D array input * @param strMultiLevelKeyDelimiter Multi-level key delimiter string * @param strKVDelimiter Key-Value delimiter string * @param strRecordDelimiter Record delimiter string * @param bSkipNullValue Indicates whether NULL Values are to be skipped * @param strNULLString NULL string * @return [String, [String, [String, double]]] map */ public static final org.drip.analytics.support.CaseInsensitiveTreeMap< org.drip.analytics.support.CaseInsensitiveTreeMap< org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>> FlatStringTo4DSDMap( final java.lang.String str4DMap, final java.lang.String strMultiLevelKeyDelimiter, final java.lang.String strKVDelimiter, final java.lang.String strRecordDelimiter, final boolean bSkipNullValue, final java.lang.String strNULLString) { if (null == str4DMap || str4DMap.isEmpty() || null == strNULLString || strNULLString.isEmpty() || strNULLString.equalsIgnoreCase(str4DMap) || null == strKVDelimiter || strKVDelimiter.isEmpty() || null == strRecordDelimiter || strRecordDelimiter.isEmpty()) return null; java.lang.String[] astrRecord = org.drip.math.common.StringUtil.Split(str4DMap, strRecordDelimiter); if (null == astrRecord || 0 == astrRecord.length) return null; org.drip.analytics.support.CaseInsensitiveTreeMap< org.drip.analytics.support.CaseInsensitiveTreeMap< org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>> map4D = new org.drip.analytics.support.CaseInsensitiveTreeMap< org.drip.analytics.support.CaseInsensitiveTreeMap< org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>(); for (int i = 0; i < astrRecord.length; ++i) { if (null == astrRecord[i] || astrRecord[i].isEmpty() || strNULLString.equalsIgnoreCase(astrRecord[i])) continue; java.lang.String[] astrKVPairOut = org.drip.math.common.StringUtil.Split(astrRecord[i], strKVDelimiter); if (null == astrKVPairOut || 2 != astrKVPairOut.length || null == astrKVPairOut[0] || astrKVPairOut[0].isEmpty() || strNULLString.equalsIgnoreCase(astrKVPairOut[0]) || (bSkipNullValue && (null == astrKVPairOut[1] || astrKVPairOut[1].isEmpty() || strNULLString.equalsIgnoreCase(astrKVPairOut[1])))) continue; java.lang.String[] astrKeySet = org.drip.math.common.StringUtil.Split(astrKVPairOut[0], strMultiLevelKeyDelimiter); if (null == astrKeySet || 3 != astrKeySet.length || null == astrKeySet[0] || astrKeySet[0].isEmpty() || strNULLString.equalsIgnoreCase(astrKeySet[0]) || null == astrKeySet[1] || astrKeySet[1].isEmpty() || strNULLString.equalsIgnoreCase(astrKeySet[1]) || null == astrKeySet[2] || astrKeySet[2].isEmpty() || strNULLString.equalsIgnoreCase(astrKeySet[2])) continue; org.drip.analytics.support.CaseInsensitiveTreeMap< org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>> map3D = map4D.get(astrKeySet[0]); if (null == map3D) map3D = new org.drip.analytics.support.CaseInsensitiveTreeMap< org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>(); org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> map2D = map3D.get(astrKeySet[1]); if (null == map2D) map2D = new org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>(); map2D.put(astrKeySet[2], new java.lang.Double(astrKVPairOut[1])); map3D.put(astrKeySet[1], map2D); map4D.put(astrKeySet[0], map3D); } if (0 == map4D.size()) return null; return map4D; }
public java.lang.Object[] getListofActivities() { java.lang.Object[] listofActivities = null; java.util.Vector listActVector = new java.util.Vector(1, 1); try { java.sql.Statement stmt1 = connectDB.createStatement(); if (balnc.equalsIgnoreCase("both")) { java.sql.PreparedStatement pSet1 = connectDB.prepareStatement( "SELECT DISTINCT CASE WHEN (account_no IS NULL) THEN '-' ELSE account_no END AS account_no,sum(debit-credit) as balance,payee FROM ac_debtors WHERE date::date <= '" + endDate + "' and account_no is not null group by account_no,payee HAVING sum(debit-credit) <> 0 order by 3 ASC"); // java.sql.PreparedStatement pSet1 = connectDB.prepareStatement("SELECT DISTINCT // account_no FROM debtors_account where account_no IS NOT NULL and account_no !='' and bal // <> 0 order by account_no"); java.sql.ResultSet rSet1 = pSet1.executeQuery(); while (rSet1.next()) { System.out.println(rSet1.getObject(1).toString()); listActVector.addElement(rSet1.getObject(1).toString()); } } else { if (balnc.equalsIgnoreCase("neg")) { // java.sql.PreparedStatement pSet1 = connectDB.prepareStatement("SELECT DISTINCT // account_no FROM debtors_account where account_no IS NOT NULL and account_no !='' and // bal < 0 order by account_no"); java.sql.PreparedStatement pSet1 = connectDB.prepareStatement( "SELECT DISTINCT CASE WHEN (account_no IS NULL) THEN '-' ELSE account_no END AS account_no,sum(debit-credit) as balance FROM ac_debtors WHERE date::date <= '" + endDate + "' group by account_no HAVING sum(debit-credit) < 0 order by 2 desc"); java.sql.ResultSet rSet1 = pSet1.executeQuery(); while (rSet1.next()) { System.out.println(rSet1.getObject(1).toString()); listActVector.addElement(rSet1.getObject(1).toString()); } } else { java.sql.PreparedStatement pSet1 = connectDB.prepareStatement( "SELECT DISTINCT CASE WHEN (account_no IS NULL) THEN '-' ELSE account_no END AS account_no,sum(debit-credit) as balance FROM ac_debtors WHERE date::date <= '" + endDate + "' group by account_no HAVING sum(debit-credit) > 0 order by 2 desc"); // java.sql.PreparedStatement pSet1 = connectDB.prepareStatement("SELECT DISTINCT // account_no FROM debtors_account where account_no IS NOT NULL and account_no !='' and // bal > 0 order by account_no"); java.sql.ResultSet rSet1 = pSet1.executeQuery(); while (rSet1.next()) { System.out.println(rSet1.getObject(1).toString()); listActVector.addElement(rSet1.getObject(1).toString()); } } } } catch (java.sql.SQLException sqlExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), sqlExec.getMessage()); } listofActivities = listActVector.toArray(); System.out.println("Done list of activities ..."); return listofActivities; }
public void generatePdf() { java.lang.Process wait_for_Pdf2Show; java.util.Calendar cal = java.util.Calendar.getInstance(); java.util.Date dateStampPdf = cal.getTime(); java.lang.String pdfDateStamp = dateStampPdf.toString(); try { java.io.File tempFile = java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf"); tempFile.deleteOnExit(); java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.String debitTotal = null; java.lang.String creditTotal = null; com.lowagie.text.Document docPdf = new com.lowagie.text.Document(); try { try { com.lowagie.text.pdf.PdfWriter.getInstance( docPdf, new java.io.FileOutputStream(tempFile)); String compName = null; String date = null; String Activity = null; try { java.sql.Statement st3 = connectDB.createStatement(); java.sql.Statement st5 = connectDB.createStatement(); java.sql.ResultSet rset5 = st5.executeQuery( "SELECT activity from pb_activity where code ilike '" + bank + "'"); java.sql.Statement st4 = connectDB.createStatement(); java.sql.Statement st2x = connectDB.createStatement(); java.sql.ResultSet rset2x = st2x.executeQuery("SELECT rep_currency from pb_hospitalprofile"); while (rset2x.next()) { ks = rset2x.getObject(1).toString(); } java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from pb_hospitalprofile"); java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date"); while (rset2.next()) { compName = rset2.getObject(1).toString(); } while (rset5.next()) { Activity = rset5.getObject(1).toString(); } while (rset4.next()) { date = rset4.getObject(1).toString(); } com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter( new Phrase("" + compName, pFontHeader), false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, // Font.BOLDITALIC,java.awt.Color.blue))); // com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new // Phrase(""+compName+""),false);// // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, // Font.BOLDITALIC,java.awt.Color.blue))); headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER); headerFoter.setRight(5); docPdf.setHeader(headerFoter); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), SqlExec.getMessage()); } com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter( new Phrase("Transaction By Account - Page: ", pFontHeader), true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, // Font.BOLDITALIC,java.awt.Color.blue)); docPdf.setFooter(footer); docPdf.open(); double Debit = 0.00; double Credit = 0.00; double bal = 0.00; int nos = 0; double acBal = 0.00; try { com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9); int headerwidths[] = {5, 12, 10, 20, 15, 10, 13, 13, 13}; table.setWidths(headerwidths); table.setWidthPercentage((100)); table.setHeaderRows(2); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setColspan(9); Phrase phrase = new Phrase("", pFontHeader); try { java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM); java.util.Date endDate1 = dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString()); java.util.Date endDate11 = dateFormat.parse(beginDate.toLocaleString()); // dateInstance.toLocaleString()); System.out.println("" + endDate1); // phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate), // pFontHeader); // table.addCell(phrase); table.getDefaultCell().setColspan(7); phrase = new Phrase( bank + " " + Activity + " : Transactions Report [" + paType + "] Period : From " + dateFormat.format(endDate11) + " To " + dateFormat.format(endDate1), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(2); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase("Printed On :" + date, pFontHeader); table.addCell(phrase); } catch (java.text.ParseException psExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), psExec.getMessage()); } table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); table.getDefaultCell().setColspan(1); phrase = new Phrase("No", pFontHeader); table.addCell(phrase); phrase = new Phrase("Date", pFontHeader); table.addCell(phrase); phrase = new Phrase("Trans No.", pFontHeader); table.addCell(phrase); phrase = new Phrase("Description", pFontHeader); table.addCell(phrase); phrase = new Phrase("Narration", pFontHeader); table.addCell(phrase); phrase = new Phrase("Doc. No", pFontHeader); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase("Debit", pFontHeader); table.addCell(phrase); phrase = new Phrase("Credit " + ks, pFontHeader); table.addCell(phrase); phrase = new Phrase("Balance " + ks, pFontHeader); table.addCell(phrase); table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE); table.getDefaultCell().setBorderColor(java.awt.Color.WHITE); try { // java.sql.Connection conDb1 = // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner"); java.sql.Statement st = connectDB.createStatement(); java.sql.Statement stx = connectDB.createStatement(); java.sql.Statement st2 = connectDB.createStatement(); if (paType.equalsIgnoreCase("OP")) { java.sql.ResultSet rset = st.executeQuery( "select date,transaction_no,description,transaction_type,voucher_no,sum(debit),sum(credit) from ac_ledger WHERE date BETWEEN '" + beginDate + "' AND '" + endDate + "' AND activity_code = '" + bank + "' AND drawer = 'OP' GROUP BY date,description,transaction_no,transaction_type,voucher_no ORDER BY date,transaction_no ASC"); java.sql.ResultSet rset1 = stx.executeQuery( "select sum(debit-credit) from ac_ledger WHERE date < '" + beginDate + "' AND activity_code = '" + bank + "' AND drawer = 'OP'"); while (rset1.next()) { table.getDefaultCell().setColspan(7); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("BBF", pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); bal = bal + rset1.getDouble(1); table.getDefaultCell().setColspan(2); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(bal)), pFontHeader); table.addCell(phrase); } while (rset.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); nos = nos + 1; table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(java.lang.String.valueOf(nos), pFontHeader1); table.addCell(phrase); phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new // com.afrisoftech.sys.Format2Currency().Format2Currency(rsetTotals.getString(1)),pFontHeader); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(6)), pFontHeader); Debit = Debit + rset.getDouble(6); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(7)), pFontHeader); Credit = Credit + rset.getDouble(7); table.addCell(phrase); acBal = acBal + (bal + Debit - Credit); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(acBal)), pFontHeader); table.addCell(phrase); } } else { if (paType.equalsIgnoreCase("IP")) { java.sql.ResultSet rset = st.executeQuery( "select date,transaction_no,description,transaction_type,voucher_no,sum(debit),sum(credit) from ac_ledger WHERE date BETWEEN '" + beginDate + "' AND '" + endDate + "' AND activity_code = '" + bank + "' AND drawer = 'IP' GROUP BY date,description,transaction_no,transaction_type,voucher_no ORDER BY date ASC"); // tn,debit_note db WHERE tn.policy_no != '' and tn.policy_no = db.policy_no GROUP BY tn.policy_no,db.policy_class"); while (rset.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new // com.afrisoftech.sys.Format2Currency().Format2Currency(rsetTotals.getString(1)),pFontHeader); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(6)), pFontHeader); Debit = Debit + rset.getDouble(6); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(7)), pFontHeader); Credit = Credit + rset.getDouble(7); table.addCell(phrase); } } else { java.sql.ResultSet rset = st.executeQuery( "select date,transaction_no,description,transaction_type,invoice_no,sum(debit),sum(credit) from transaction_list_view WHERE date BETWEEN '" + beginDate + "' AND '" + endDate + "' AND activity_code = '" + bank + "' GROUP BY date,description,transaction_no,transaction_type,invoice_no ORDER BY date ASC"); // tn,debit_note db WHERE tn.policy_no != '' and tn.policy_no = db.policy_no GROUP BY tn.policy_no,db.policy_class"); while (rset.next()) { table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); // phrase = new Phrase(new // com.afrisoftech.sys.Format2Currency().Format2Currency(rsetTotals.getString(1)),pFontHeader); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(6)), pFontHeader); Debit = Debit + rset.getDouble(6); table.addCell(phrase); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(rset.getString(7)), pFontHeader); Credit = Credit + rset.getDouble(7); table.addCell(phrase); } } } // java.sql.ResultSet rset = st.executeQuery("select // date,transaction_no,description,transaction_type,invoice_no,sum(debit),sum(credit) // from transaction_list_view WHERE date BETWEEN '"+beginDate+"' AND '"+endDate+"' AND // activity_code = '"+bank+"' GROUP BY // date,description,transaction_no,transaction_type,invoice_no ORDER BY date ASC");// // tn,debit_note db WHERE tn.policy_no != '' and tn.policy_no = db.policy_no GROUP BY // tn.policy_no,db.policy_class"); table.getDefaultCell().setBorderColor(java.awt.Color.BLACK); table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP); // while (rsetTotals.next()) { table.getDefaultCell().setColspan(6); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Total", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(1); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(Debit)), pFontHeader); table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(Credit)), pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(4); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); phrase = new Phrase("Debit - Credit", pFontHeader); table.addCell(phrase); table.getDefaultCell().setColspan(3); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(Debit - Credit)), pFontHeader); table.addCell(phrase); phrase = new Phrase( new com.afrisoftech.sys.Format2Currency() .Format2Currency(java.lang.String.valueOf(acBal)), pFontHeader); table.addCell(phrase); // } docPdf.add(table); } catch (java.sql.SQLException SqlExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), SqlExec.getMessage()); } } catch (com.lowagie.text.BadElementException BadElExec) { javax.swing.JOptionPane.showMessageDialog( new javax.swing.JFrame(), BadElExec.getMessage()); } } catch (java.io.FileNotFoundException fnfExec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage()); } } catch (com.lowagie.text.DocumentException lwDocexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage()); } docPdf.close(); docPdf.close(); com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile); } catch (java.io.IOException IOexec) { javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage()); } }