coercionToStruct

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    coercionToStruct

    Code:
    public static IStructResult coercionToStruct(IAbstractQueryResult res){
    
         IStructResult s=null;
        s=(IStructResult)res; 
        System.out.println(s.toString());
        return s;
      
    }
    how do i make a coercion ?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    You will need to give more information than that.

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      Code:
       QResStack qres = new QResStack();
      qres.push(new IntegerResult(1)); // (1)
      qres.push(new DoubleResult(2.1)); // (2)
      { // (3)
      IAbstractQueryResult resRight = qres.pop();
      IAbstractQueryResult resLeft = qres.pop();
      //iloczyn kartezjanski - operator przecinka
      IBagResult commaRes = QExecUtils.cartesianProduct(resLeft, resRight);
      qres.push(commaRes);
      }
      qres.push(new IntegerResult(3)); // (4)
      qres.push(new IntegerResult(4)); // (5)
      { // (6)
      IntegerResult resRight = (IntegerResult) qres.pop();
      IntegerResult resLeft = (IntegerResult) qres.pop();
      IntegerResult plusRes = new IntegerResult(resLeft.getValue() + resRight.getValue());
      qres.push(plusRes);
      }
      { // (7)
      IAbstractQueryResult resRight = qres.pop();
      IAbstractQueryResult resLeft = qres.pop();
      //iloczyn kartezjanski - operator przecinka
      IBagResult commaRes = QExecUtils.cartesianProduct(resLeft, resRight);
      qres.push(commaRes);
      }
      { // (8)
      IAbstractQueryResult res = qres.pop();
      //sprawdzenie i ew. zamiana pojedynczego elementu
      //na strukture jednoelementowa
      [B]IStructResult struct = QExecUtils.coercionToStruct(res);[/B] [B]<--- here i get  null pointer exception[/B]
      IBagResult bagRes = new BagResult();
      for(ISingleResult sr : struct.elements()) {
      bagRes.getElements().add(sr);
      }
      qres.push(bagRes); 
      }

      Comment

      • oll3i
        Contributor
        • Mar 2007
        • 679

        #4
        how do i check if passed variable res is of IStructResult type?

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          You can use the instanceof operator.

          Comment

          • Nepomuk
            Recognized Expert Specialist
            • Aug 2007
            • 3111

            #6
            There's a description of the instanceof operator that might help you.

            Comment

            Working...