Package com.extentech.toolkit

Examples of com.extentech.toolkit.CompatibleVector


   * @throws CalculationException
   */
   protected static Ptg calcFrequency(Ptg[] operands) throws CalculationException{
     Ptg[] firstArr = PtgCalculator.getAllComponents(operands[0]);
     Ptg[] secondArr =   PtgCalculator.getAllComponents(operands[1]);
    CompatibleVector t = new CompatibleVector();
    for (int i=0;i<secondArr.length;i++){
      Ptg p = secondArr[i];
      try{
          Double d = new Double(String.valueOf(p.getValue()));
          t.addOrderedDouble(d);
      }catch(NumberFormatException e){};
    }
    Double[] binsArr = new Double[t.size()];
    double[] dataArr;
      dataArr = PtgCalculator.getDoubleValueArray(firstArr);
      if (dataArr==null) return new PtgErr(PtgErr.ERROR_NA);//20090130 KSC: propagate error
    t.toArray(binsArr);
    int[] retvals = new int[secondArr.length +1];
    for (int i=0;i<dataArr.length;i++){
      for (int x=0;x<binsArr.length;x++){
        if (dataArr[i] <= binsArr[x].doubleValue()){
          retvals[x]++;
View Full Code Here


    if (array.length==0) return new PtgErr(PtgErr.ERROR_NUM);
    int k= new Double(PtgCalculator.getDoubleValueArray(operands[1])[0]).intValue();
    if (k<=0 || k > array.length)
      return new PtgErr(PtgErr.ERROR_NUM);
   
    CompatibleVector sortedValues = new CompatibleVector();
    for (int i=0;i<array.length;i++){
       Ptg p = array[i];
       try{
         Double d = new Double(String.valueOf(p.getValue()));
         sortedValues.addOrderedDouble(d);
       }catch(NumberFormatException e){};
    }
    // reverse array
    Double[] dubRefs= new Double[sortedValues.size()];
    for (int i=0; i < dubRefs.length; i++){
      dubRefs[i] = (Double)sortedValues.last();
      sortedValues.remove(sortedValues.size()-1);
    }
       
    return new PtgNumber((dubRefs[k-1]).doubleValue());
/*  
  
View Full Code Here

Returns the median of the given numbers
*/
protected static Ptg calcMedian(Ptg[] operands){
   if (operands.length<1) return new PtgErr(PtgErr.ERROR_VALUE);
    Ptg[] alloperands = PtgCalculator.getAllComponents(operands);
    CompatibleVector t = new CompatibleVector();
    double retval = 0;
    for (int i=0;i<alloperands.length;i++){
      Ptg p = alloperands[i];
      try{
          Double d = new Double(String.valueOf(p.getValue()));
         t.addOrderedDouble(d);
      }catch(NumberFormatException e){};
    }

    try {
      Double[] dub = new Double[t.size()];
      t.toArray(dub);
      double dd = (double)t.size()%2;
      if ((double)t.size()%2 == 0){
      int firstValLoc = ((t.size())/2)-1;
      int lastValLoc = firstValLoc + 1;
      double firstVal = dub[firstValLoc].doubleValue();
      double lastVal = dub[lastValLoc].doubleValue();
      retval = (firstVal + lastVal)/2;
      }else{
        // it's odd
        int firstValLoc = ((t.size()-1)/2);
        double firstVal = dub[firstValLoc].doubleValue();
        retval = firstVal;
      }
      PtgNumber pnum = new PtgNumber(retval);
      return pnum;
View Full Code Here

*/
protected static Ptg calcQuartile(Ptg[] operands){
    Ptg[] aveoperands = new Ptg[1];
    aveoperands[0] = operands[0];
    Ptg[] allVals =PtgCalculator.getAllComponents(aveoperands);
    CompatibleVector t = new CompatibleVector();
    double retval = 0;
    for (int i=0;i<allVals.length;i++){
      Ptg p = allVals[i];
      try{
          Double d = new Double(String.valueOf(p.getValue()));
          t.addOrderedDouble(d);
      }catch(NumberFormatException e){
        Logger.logErr(e);
      };
    }

    Double[] dub = new Double[t.size()];
    t.toArray(dub);
    Integer quart;
    Object o= operands[1].getValue();
    if (o instanceof Integer)
      quart = (Integer)operands[1].getValue();
    else
      quart = Integer.valueOf(((Double)operands[1].getValue()).intValue());
     
    float quartile = quart.floatValue();
    if (quart.intValue() == 0){  // return minimum value
      return new PtgNumber(dub[0].doubleValue());
    }else if (quart.intValue() == 4){  // return maximum value
      return new PtgNumber(dub[t.size()-1].doubleValue());
    }else if (quart.intValue() > 4 || quart.intValue()<0){
      return new PtgErr(PtgErr.ERROR_NUM);
    }
    // find the kth smallest
    float kk = (float)(quartile/4);
View Full Code Here

      if (i==0)ascending = false;
    }   
     Ptg[] aveoperands = new Ptg[1];
     aveoperands[0] = operands[1];
     Ptg[] refs =PtgCalculator.getAllComponents(aveoperands);
     CompatibleVector retList = new CompatibleVector();
     double retval = 0;
     for (int i=0;i<refs.length;i++){
       Ptg p = refs[i];
       try{
           Double d = new Double(String.valueOf(p.getValue()));
           retList.addOrderedDouble(d);
       }catch(NumberFormatException e){};
     }
    Double[] dubRefs = new Double[retList.size()];
    if (ascending){
      retList.toArray(dubRefs);
    }else{
      for (int i=0; i < dubRefs.length; i++){
        dubRefs[i] = (Double)retList.last();
        retList.remove(retList.size()-1);
      }
    }
    int res = -1;
    for (int i=0;i<dubRefs.length;i++){
      if (dubRefs[i].toString().equalsIgnoreCase(theNum.toString())){
View Full Code Here

    if (array.length==0) return new PtgErr(PtgErr.ERROR_NUM);
    int k= new Double(PtgCalculator.getDoubleValueArray(operands[1])[0]).intValue();
    if (k<=0 || k > array.length)
      return new PtgErr(PtgErr.ERROR_NUM);
   
    CompatibleVector sortedValues = new CompatibleVector();
    for (int i=0;i<array.length;i++){
       Ptg p = array[i];
       try{
         Double d = new Double(String.valueOf(p.getValue()));
         sortedValues.addOrderedDouble(d);
       }catch(NumberFormatException e){};
    }
    try {       
      return new PtgNumber(((Double)sortedValues.get(k-1)).doubleValue());
    } catch (Exception e) {
      return new PtgErr(PtgErr.ERROR_VALUE);     
    }
}
View Full Code Here

 
  /**
   * return an array of ALL cell references of the chart
   */
  public Ptg[] getCellRangePtgs() {
    CompatibleVector locptgs = new CompatibleVector();
    for (int i= 0; i < series.size(); i++) {
           Series s= (Series) ((Object[])series.get(i))[0];
           for (int j= 0; j < s.chartArr.size(); j++) {
             BiffRec br = (BiffRec)s.chartArr.get(j);
             if (br.getOpcode()==XLSConstants.AI) {
               try {
                 Ptg[] ps = ((Ai)br).getCellRangePtgs();              
                 for(int t=0;t<ps.length;t++)locptgs.add(ps[t]);
               } catch (Exception e) {      }
             }
           }
       }   
       Ptg[] ret = new Ptg[locptgs.size()];
       locptgs.toArray(ret);
       return ret;   
  }
View Full Code Here

    }
    }
   
    void resetDBCells() {
      dbnum= 0;
      dbcells= new CompatibleVector();
    }
View Full Code Here

  protected static double[] getDoubleValueArray(Ptg[] operands) throws CalculationException
  {

    Double d = null
    // we don't know the size ahead of time, so use a vector for now.
    CompatibleVector cv = new CompatibleVector();
   
    for (int i=0;i<operands.length;i++){
      // is it multidimensional?
        Ptg[] pthings = operands[i].getComponents(); // optimized -- do it once!  -jm
      if (pthings!= null){
        for (int x=0;x<pthings.length; x++){
          cv.add(pthings[x]);
        }
      }else{
        cv.add(operands[i]);
      }
    }

    double[] darr = new double[cv.size()];
    int i=0;
    Enumeration en = cv.elements();
    while(en.hasMoreElements()){
      d= null;//new Double(0.0);    // 20081229 KSC: reset
      Ptg pthing = (Ptg)en.nextElement();
      Object ob = pthing.getValue();
      if (ob == null || ob.toString().trim().equals("")){  // 20060802 KSC: added trim
View Full Code Here

   
   * * @see javax.naming.Name#clone()
   */
  public Object clone() {
    NameImpl nimple = new NameImpl();
    CompatibleVector newvals = new CompatibleVector();
    newvals.addAll(vals);
    nimple.vals = newvals;
    return nimple;
  }
View Full Code Here

TOP

Related Classes of com.extentech.toolkit.CompatibleVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.