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

foam.CLASS({
  package: 'foam.nanos.crunch.ruler',
  name: 'IsDataUpdate',
  
  extends: 'foam.mlang.predicate.AbstractPredicate',
  implements: ['foam.core.Serializable'],
  
  documentation: `Returns true if ucj data has been updated`,
  
  javaImports: [
    'foam.core.FObject',
    'foam.core.X',
    'foam.nanos.crunch.UserCapabilityJunction',
    'static foam.mlang.MLang.*'
  ],

  methods: [
    {
      name: 'f',
      javaCode: `
        X x = (X) obj;
        UserCapabilityJunction old = (UserCapabilityJunction) x.get("OLD");
        UserCapabilityJunction ucj = (UserCapabilityJunction) x.get("NEW");
        FObject oldData = old.getData();
        FObject newData = ucj.getData();

        if ( oldData == null && newData == null ) return false;
        if ( ( oldData == null && newData != null ) || ( oldData != null && newData == null ) ) {
          return true;
        } else {
          java.util.List<foam.core.PropertyInfo> props = oldData.getClassInfo().getAxiomsByClass(foam.core.PropertyInfo.class);
          for ( foam.core.PropertyInfo prop : props ) {
            if ( prop.getStorageTransient() ) 
              continue;
            if ( ! prop.f(oldData).equals(prop.f(newData)) ) 
              return true;
          }
        }
<commit_msg>fix npe on isdataupdate predicate<commit_after>/**
 * @license
 * Copyright 2020 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

foam.CLASS({
  package: 'foam.nanos.crunch.ruler',
  name: 'IsDataUpdate',
  
  extends: 'foam.mlang.predicate.AbstractPredicate',
  implements: ['foam.core.Serializable'],
  
  documentation: `Returns true if ucj data has been updated`,
  
  javaImports: [
    'foam.core.FObject',
    'foam.core.X',
    'foam.nanos.crunch.UserCapabilityJunction',
    'static foam.mlang.MLang.*'
  ],

  methods: [
    {
      name: 'f',
      javaCode: `
        X x = (X) obj;
        UserCapabilityJunction old = (UserCapabilityJunction) x.get("OLD");
        UserCapabilityJunction ucj = (UserCapabilityJunction) x.get("NEW");
        FObject oldData = old.getData();
        FObject newData = ucj.getData();

        if ( oldData == null && newData == null ) return false;
        if ( ( oldData == null && newData != null ) || ( oldData != null && newData == null ) ) {
          return true;
        } else {
          java.util.List<foam.core.PropertyInfo> props = oldData.getClassInfo().getAxiomsByClass(foam.core.PropertyInfo.class);
          for ( foam.core.PropertyInfo prop : props ) {
            if ( prop.getStorageTransient() ) 
              continue;
            Object newProp = prop.f(newData);
            Object oldProp = prop.f(oldData);
            if ( newProp == null && oldProp == null ) continue;
            if ( newProp == null || oldProp == null || ! oldProp.equals(newProp) ) 
              return true;
          }
        }

{'fraction_non_alphanumeric': 0.13866930171277997, 'fraction_numerical': 0.003952569169960474, 'mean_word_length': 2.3669623059866964, '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': '2483654', 'n_tokens_mistral': 981, 'n_tokens_neox': 969, 'n_words': 200}