Package erjang

Examples of erjang.ETuple


  protected void insert_many(final ESeq values) {
    in_tx(new WithMap<Object>() {
      @Override
      protected Object run(IPersistentMap map) {   
        for (ESeq seq = values; !seq.isNil(); seq = seq.tail()) {
          ETuple value = seq.head().testTuple();
          if (value == null) throw ERT.badarg(values);
          map = map.assoc(get_key(value), value);
        }
        set(map);
        return null;
View Full Code Here


  @Override
  protected boolean insert_new_many(final ESeq values) {
    // Input verification outside of transaction:
    for (ESeq seq = values; !seq.isNil(); seq = seq.tail()) {
      ETuple value = seq.head().testTuple();
      if (value == null) throw ERT.badarg(values);
      EObject key = get_key(value);
    }

    return in_tx(new WithMap<Boolean>() {
      @Override
      protected Boolean run(IPersistentMap map) {
        for (ESeq seq = values; !seq.isNil(); seq = seq.tail()) {
          ETuple value = seq.head().testTuple();
          EObject key = get_key(value);
          if (map.containsKey(key)) {
            return false;
          }
        }
 
        for (ESeq seq = values; !seq.isNil(); seq = seq.tail()) {
          ETuple value = seq.head().testTuple();
          EObject key = get_key(value);
          map = map.assoc(key, value);
        }
 
        set(map);
View Full Code Here

    EObject key = matcher.getKey(keypos1);
    if (key == null) {
      res = matcher.match(res, (Map<EObject, ETuple>) map);
      if (ordered) res = res.reverse();
    } else {
      ETuple candidate = (ETuple) map.valAt(key);
      if (candidate != null) {
        res =  matcher.match(res, candidate);
      }
    }
   
View Full Code Here

    EObject key = matcher.getKey(keypos1);
    if (key == null) {
      res = matcher.match_members(res, (Map<EObject, ETuple>) map);
      if (ordered) res = res.reverse();
    } else {
      ETuple candidate = (ETuple) map.valAt(key);
      if (candidate != null) {
        res =  matcher.match_members(res, candidate);
      }
    }
   
View Full Code Here

    if (key == null) {
      ESetCont cont0 = new ESetCont(matcher, map.seq(), ordered, limit);
      return cont0.select();
     
    } else {
      ETuple candidate = (ETuple) map.valAt(key);
      if (candidate == null) return Native.am_$end_of_table;
      EObject res;
      if ((res = matcher.match(candidate)) != null) {
        return new ETuple2(ERT.NIL.cons(res), Native.am_$end_of_table);
      }
View Full Code Here

        EObject key = matcher.getTupleKey(keypos1);
        int count = 0;
       
        if (key == null) {
          for (Map.Entry<EObject, ETuple> ent : ((Map<EObject, ETuple>) map).entrySet()) {   
            ETuple val = ent.getValue();
            if (matcher.matches(val)) {
              try {
                map = map.without(ent.getKey());
              } catch (Exception e) {
                throw new RuntimeException(e);
              }
              count += 1;
            }
          }
        } else {
          ETuple candidate = (ETuple) map.valAt(key);
          if (candidate != null && matcher.matches(candidate)) {
            try {
              map = map.without(key);
            } catch (Exception e) {
              throw new RuntimeException(e);
View Full Code Here

  public EObject update_counter(final EObject key, final EObject upd) {
    return in_tx(new WithMap<EObject>() {

      @Override
      protected EObject run(IPersistentMap map) {
        ETuple rec = (ETuple) map.valAt(key);
        if (rec == null)
          return null; // fail with badarg
       
        // TODO: figure out match/equals semantics
        if (type == Native.am_set) {
          if (!key.equalsExactly( get_key(rec) )) {
            return null;
          }
        }

        EInteger incr;
        ETuple one;
        if ((incr=upd.testInteger()) != null) {
          int idx = keypos1+1;
         
          rec = update(rec, idx, incr);
          if (rec == null) return null;
          map = map.assoc(get_key(rec), rec);
         
          set(map);
          return rec.elm(idx);
         
        } else if ((one=upd.testTuple()) != null) {
         
          if (one.arity() == 2) {
            ESmall eidx = one.elm(1).testSmall();
            incr = one.elm(2).testInteger();
            if (eidx == null || eidx.value > rec.arity() || incr == null) return null;
            int idx = eidx.value;
           
            rec = update(rec, idx, incr);
            if (rec == null) return null;
            map = map.assoc(get_key(rec), rec);
           
            set(map);
            return rec.elm(idx);

          } else if (one.arity() == 4){
           
            ESmall eidx = one.elm(1).testSmall();
            incr = one.elm(2).testInteger();
            EInteger threshold = one.elm(3).testInteger();
            EInteger setvalue = one.elm(4).testInteger();
            if (eidx == null || eidx.value > rec.arity() || incr == null
                || threshold == null || setvalue == null) return null;
            int idx = eidx.value;
           
            rec = update(rec, idx, incr, threshold, setvalue);
View Full Code Here

  public EObject update_element(final EObject key, final ESeq upd) {
    return in_tx(new WithMap<EObject>() {

      @Override
      protected EObject run(IPersistentMap map) {
        ETuple rec = (ETuple) map.valAt(key);
        if (rec == null)
          return ERT.FALSE;
       
        // TODO: figure out match/equals semantics
        if (type == Native.am_set) {
          if (!key.equalsExactly( get_key(rec) )) {
            return ERT.FALSE;
          }
        }

        ETuple rep = null;
       
        for (ESeq next = upd ; !next.isNil() ; next = next.tail()) {
          ETuple2 update = ETuple2.cast(next.head());
          if (update == null) return null;
          ESmall idx1 = update.elem1.testSmall();
          if (idx1 == null
              || idx1.value < 1
              || idx1.value > rec.arity()
              || idx1.value == keypos1) return null;
         
          if (rep == null) {
            rep = rec.setelement(idx1.value, update.elem2);
          } else {
            rep.set(idx1.value, update.elem2);
          }
        }
       
        if (rep != null) {
          map = map.assoc(get_key(rec), rep);
View Full Code Here

    for (; settings != null && !settings.isNil(); settings = settings
        .tail().testCons()) {

      EObject val = settings.head();
      ETuple tup;
      if ((tup = val.testTuple()) != null) {
        ETuple2 tup2;
        if ((tup2 = ETuple2.cast(tup)) != null) {

          if (tup2.elem1 == am_args) {
View Full Code Here

      } catch (Throwable e) {

        e.printStackTrace();

        ESeq erl_trace = ErlangError.decodeTrace(e.getStackTrace());
        ETuple java_ex = ETuple.make(am_java_exception, EString
            .fromString(ERT.describe_exception(e)));

        result = ETuple.make(java_ex, erl_trace);
       
        if (log.isLoggable(Level.FINER)) {
View Full Code Here

TOP

Related Classes of erjang.ETuple

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.