Exemple #1
0
 /**
  * PDF has a wacky grammar which must be a legacy of PostScript's postfix syntax. A keyword of R
  * means that the two previous objects are really part of an indirect object reference. This means
  * that when a vector of objects is complete, it has to be read backwards so that indirect object
  * references can be collapsed out. In the case of a dictionary, this has to be done before the
  * content can be interpreted as key-value pairs.
  */
 private void collapseObjectVector(Vector v) throws PdfException {
   for (int i = v.size() - 1; i >= 2; i--) {
     PdfObject obj = (PdfObject) v.elementAt(i);
     if (obj instanceof PdfSimpleObject) {
       Token tok = ((PdfSimpleObject) obj).getToken();
       if (tok instanceof Keyword) {
         if ("R".equals(((Keyword) tok).getValue())) {
           // We're in the key of 'R'.  The two previous tokens
           // had better be Numerics.  Three objects in the Vector
           // are replaced by one.
           try {
             PdfSimpleObject nobj = (PdfSimpleObject) v.elementAt(i - 2);
             Numeric ntok = (Numeric) nobj.getToken();
             int objNum = ntok.getIntegerValue();
             nobj = (PdfSimpleObject) v.elementAt(i - 1);
             ntok = (Numeric) nobj.getToken();
             int genNum = ntok.getIntegerValue();
             v.set(i - 2, new PdfIndirectObj(objNum, genNum, _objectMap));
             v.removeElementAt(i);
             v.removeElementAt(i - 1);
             i -= 2;
           } catch (Exception e) {
             throw new PdfMalformedException("Malformed indirect object reference");
           }
         }
       }
     }
   }
 }
  /* (non-Javadoc)
   * @see com.lexst.db.head.Field#resolve(byte[], int)
   */
  @Override
  public int resolve(byte[] b, int offset) {
    int off = offset;

    dataType = b[off];
    off += 1;
    columnId = Numeric.toShort(b, off, 2);
    off += 2;

    byte sz = b[off];
    off += 1;
    byte[] nm = new byte[sz];
    System.arraycopy(b, off, nm, 0, sz);
    name = new String(nm, 0, nm.length);
    off += sz;

    indexType = b[off];
    off += 1;

    allowNull = (b[off] == 1 ? true : false);
    off += 1;

    function = b[off];
    off += 1;
    value = Numeric.toLong(b, off, 8);
    off += 8;

    return off - offset;
  }
Exemple #3
0
 /** {@inheritDoc} */
 @Override
 public int compareTo(Numeric other) {
   if (this.value == other.intValue()) {
     return 0;
   } else {
     return (other.intValue() < this.value) ? 1 : -1;
   }
 }
  /* (non-Javadoc)
   * @see com.lexst.db.head.Field#build()
   */
  @Override
  public byte[] build() {
    ByteArrayOutputStream buf = new ByteArrayOutputStream(128);
    buf.write(dataType); // data type
    byte[] b = Numeric.toBytes(columnId);
    buf.write(b, 0, b.length); // column id

    byte[] bs = name.getBytes();
    byte sz = (byte) (bs.length & 0xFF);
    buf.write(sz); // name size

    buf.write(bs, 0, bs.length); // name bytes

    buf.write(indexType); // index type
    byte tag = (byte) (allowNull ? 1 : 0);
    buf.write(tag); // allow null

    buf.write(function); // function type
    b = Numeric.toBytes(value);
    buf.write(b, 0, b.length); // default value

    return buf.toByteArray();
  }
Exemple #5
0
  /**
   * Reads an object definition, given the first numeric object, which has already been read and is
   * passed as an argument. This is called by the no-argument readObjectDef; the only other case in
   * which it will be called is for a cross-reference stream, which can be distinguished from a
   * cross-reference table only once the first token is read.
   */
  public PdfObject readObjectDef(Numeric objNumTok) throws IOException, PdfException {
    String invDef = "Invalid object definition";
    reset();
    // The start of an object must be <num> <num> obj
    // Numeric objNumTok = (Numeric) getNext (Numeric.class, invDef);
    Numeric genNumTok = (Numeric) getNext(Numeric.class, invDef);
    Keyword objKey = (Keyword) getNext(Keyword.class, invDef);
    if (!"obj".equals(objKey.getValue())) {
      throw new PdfMalformedException(invDef);
    }
    if (_tokenizer.getWSString().length() > 1) {
      _pdfACompliant = false;
    }
    PdfObject obj = readObject();

    // Now a special-case check to read a stream object, which
    // consists of a dictionary followed by a stream token.
    if (obj instanceof PdfDictionary) {
      Stream strm = null;
      try {
        strm = (Stream) getNext(Stream.class, "");
      } catch (Exception e) {
        // if we get an exception, it just means it wasn't a stream
      }
      if (strm != null) {
        // Assimilate the dictionary and the stream token into the
        // object to be returned
        PdfStream strmObj = new PdfStream((PdfDictionary) obj, strm);
        obj = strmObj;
      }
    }

    obj.setObjNumber(objNumTok.getIntegerValue());
    obj.setGenNumber(genNumTok.getIntegerValue());
    return obj;
  }
Exemple #6
0
 public void setData(ItemCaract caract, Numeric value) {
   if (caract.getNumericType() != value.getNumericType()) {
     throw new IllegalArgumentException();
   }
   if (data.containsKey(caract.getNumericType())) {
     throw new IllegalStateException();
   }
   data.put(caract, value);
   boolean change = false;
   do {
     change = false;
     change = eventuallyUseBeginComplete() || change;
     change = eventuallyUseBeginDuration() || change;
     change = eventuallyUseCompleteDuration() || change;
     change = eventuallyUseDurationWork() || change;
     change = eventuallyUseDurationLoad() || change;
     change = eventuallyUseLoadWork() || change;
   } while (change);
 }
Exemple #7
0
    public Map<String, Construct> evaluate(BindableEvent e) throws EventException {
      Map<String, Construct> retn = new HashMap<String, Construct>();

      if (e instanceof Numeric) {
        Numeric msg = (Numeric) e;

        retn.put("id", new CString(msg.getBot().getID(), Target.UNKNOWN));
        retn.put("numeric", new CString(msg.getNumeric().getName(), Target.UNKNOWN));
        retn.put("numericid", new CInt(msg.getNumeric().getCode(), Target.UNKNOWN));
        retn.put("args", Construct.GetConstruct(msg.getArgs()));
        retn.put("message", new CString(msg.getMessage(), Target.UNKNOWN));
      }

      return retn;
    }
 public Double summarize(Double[] a) {
   return Numeric.mean(a);
 }