<commit_before>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.dao;

import foam.core.ClassInfo;
import foam.core.FObject;
import foam.core.PropertyInfo;
import foam.core.X;
import foam.mlang.MLang;
import foam.mlang.sink.Max;

public class SequenceNumberDAO
  extends ProxyDAO
{
  protected long         value_      = 1;
  protected boolean      isValueSet_ = false;
  protected String       property    = "id";
  protected PropertyInfo property_   = null;

  public SequenceNumberDAO(DAO delegate) {
    setDelegate(delegate);
  }

  public SequenceNumberDAO(PropertyInfo property, DAO delegate) {
    setDelegate(delegate);
    property_ = property;
    this.property = property.getName();
  }

  public AbstractDAO setOf(ClassInfo of) {
    AbstractDAO ret = super.setOf(of);

    property_ = null;

    return ret;
  }

  public SequenceNumberDAO setProperty(String property) {
    this.property = property;
    property_ = null;

    return this;
  }

  public SequenceNumberDAO setValue(long value) {
    value_ = value;
    return this;
  }

  private PropertyInfo getProperty_() {
    if ( property_ == null )
      property_ = (PropertyInfo) this.of_.getAxiomByName(property);

    return property_;
  }

  /**
   * Calculates the next largest value in the sequence
   */
  private void calcDelegateMax_() {
    Sink sink = MLang.MAX(getProperty_());
    sink = getDelegate().select(sink);
    setValue((long) (((Max) sink).getValue() + 1.0));
    isValueSet_ = true;
  }

  public FObject put_(X x, FObject obj) {
    synchronized (this) {
      if ( ! isValueSet_ ) calcDelegateMax_();

      Number val = (Number) obj.getProperty(property);
      if ( val.longValue() < 1 ) {
        getProperty_().set(obj, value_++);
      } else if ( val.longValue() >= value_ ) {
        setValue(val.longValue() + 1);
      }
    }

    return getDelegate().put(obj);
  }
}
<commit_msg>Fixed null exception in SequenceNumberDAO<commit_after>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.dao;

import foam.core.ClassInfo;
import foam.core.FObject;
import foam.core.PropertyInfo;
import foam.core.X;
import foam.mlang.MLang;
import foam.mlang.sink.Max;

public class SequenceNumberDAO
  extends ProxyDAO
{
  protected long         value_      = 1;
  protected boolean      isValueSet_ = false;
  protected String       property    = "id";
  protected PropertyInfo property_   = null;

  public SequenceNumberDAO(DAO delegate) {
    setDelegate(delegate);
  }

  public SequenceNumberDAO(PropertyInfo property, DAO delegate) {
    setDelegate(delegate);
    property_ = property;
    this.property = property.getName();
  }

  public AbstractDAO setOf(ClassInfo of) {
    AbstractDAO ret = super.setOf(of);

    property_ = null;

    return ret;
  }

  public SequenceNumberDAO setProperty(String property) {
    this.property = property;
    property_ = null;

    return this;
  }

  public SequenceNumberDAO setValue(long value) {
    value_ = value;
    return this;
  }

  private PropertyInfo getProperty_() {
    if ( property_ == null )
      property_ = (PropertyInfo) getDelegate().getOf().getAxiomByName(property);

    return property_;
  }

  /**
   * Calculates the next largest value in the sequence
   */
  private void calcDelegateMax_() {
    Sink sink = MLang.MAX(getProperty_());
    sink = getDelegate().select(sink);
    setValue((long) (((Max) sink).getValue() + 1.0));
    isValueSet_ = true;
  }

  public FObject put_(X x, FObject obj) {
    synchronized (this) {
      if ( ! isValueSet_ ) calcDelegateMax_();

      Number val = (Number) obj.getProperty(property);
      if ( val.longValue() < 1 ) {
        getProperty_().set(obj, value_++);
      } else if ( val.longValue() >= value_ ) {
        setValue(val.longValue() + 1);
      }
    }

    return getDelegate().put_(x, obj);
  }
}

{'fraction_non_alphanumeric': 0.11533650237678258, 'fraction_numerical': 0.0055041280960720545, 'mean_word_length': 3.0465587044534415, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6420841', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1249, 'n_words': 305}