<commit_before>/*
Copyright 2011-present <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

//
//  NSManagedObject+OneWaySynchronization.swift
//  SFCoreDataOneWaySynchronization
//

import Foundation
import CoreData

extension NSManagedObject {
  /**
   Sets the object priority
   
   - parameter priority: the priority of the object
   - parameter object:   the object for which to set the priority
   - parameter key:      the key used to set the priority of the object
   */
  public func sfSetObjectPriority(priority: NSNumber, object: AnyObject, key: String) {
  }
  
  /**
   Do the unique comparison between the source object and the destination object.
   Objects should be unique in a certain way. It means that a key exist that identifies them uniquely,
   event if the content of each object is different.
   
   - parameter srcObject: the source object
   - parameter dstObject: the destination object
   - parameter context:   a context, if needed for the comparison
   
   - returns: `true` if the keys that identify the objects are equal, otherwise returns `false`.
   */
  public class func sfCompareUniqueKeyFrom(
    srcObject: AnyObject,
    with dstObject: AnyObject,
    context: AnyObject?) -> Bool {
      return true
  }
  
  /**
   Insert the object referenced by data
   
   - parameter data:    the object involved in the operation
   - parameter moc:     the managed object context associated to the operation
   - parameter context: a context, if needed for the operation
   
   - returns: the newly inserted managed object
   */
  public class func sfCreateObjectWithData(
    data: AnyObject,
    managedObjectContext moc: NSManagedObjectContext,
    context: AnyObject?
    ) -> NSManagedObject? {
      fatalError("createObjectWithData(data:managedObjectContext:context:) has not been implemented")
  }
  
  /**
   Updates the object referenced by data
   
   - parameter data:    the object involved in the operation
   - parameter moc:     the managed object context associated to the operation
   - parameter context: a context, if needed for the operation
   
   - returns: the updated managed object
   */
  public class func sfUpdateObjectWithData(
    data: AnyObject,
    updatedObject: AnyObject,
    managedObjectContext moc: NSManagedObjectContext,
    context: AnyObject?
    ) -> NSManagedObject? {
      fatalError("updateObjectWithData(data:managedObjectContext:context:) has not been implemented")
  }
  
  /**
   Deletes the object referenced by data
   
   - parameter data:    the object involved in the operation
   - parameter moc:     the managed object context associated to the operation
   - parameter context: a context, if needed for the operation
   
   - returns: the deleted managed object
   */
  public class func sfDeleteObjectWithData(
    data: AnyObject,
    managedObjectContext moc: NSManagedObjectContext,
    context: AnyObject?
    ) -> NSManagedObject? {
      fatalError("deleteObjectWithData(data:managedObjectContext:context:) has not been implemented")
  }
  
  /**
   do the whole synchronization
   
   - parameter inputObjects: source (master)
   - parameter existingData: destination (slave)
   - parameter key:          the priority key
   - parameter moc:          the managed object context in which to operate the synchronization
   - parameter context:      the context if any needed
   
   - returns: the resulting set 
   */
  public class func synchronizeSortedInputData(
    inputObjects: [AnyObject],
    withSortedExistingData existingData: [AnyObject],
    priorityKey key: String,
    managedObjectContext moc: NSManagedObjectContext,
    context: AnyObject? = nil) -> NSSet {
      
      var srcIndex = 0 // Source index
      var dstIndex = 0 // Destination index
      
      var resultSet = NSMutableSet()
      
      // While source index does not reach the upper bound of the existing data count
      while srcIndex < inputObjects.count {
        // We treat the current source object
        let srcMO: AnyObject = inputObjects[srcIndex]
        
        // Have we reached yet the end of the source array?
        if existingData.sfIsIndexOutOfBounds(dstIndex) {
          
          // There we are out of bounds, so this is an insertion --> Create the object
          self.owsInsertObject(object: srcMO, resultSet: &resultSet, key: key, managedObjectContext: moc, syncContext: context)<commit_msg>⚙️ Missing prefix for function to prevent interferences<commit_after>/*
Copyright 2011-present <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

//
//  NSManagedObject+OneWaySynchronization.swift
//  SFCoreDataOneWaySynchronization
//

import Foundation
import CoreData

extension NSManagedObject {
  /**
   Sets the object priority
   
   - parameter priority: the priority of the object
   - parameter object:   the object for which to set the priority
   - parameter key:      the key used to set the priority of the object
   */
  public func sfSetObjectPriority(priority: NSNumber, object: AnyObject, key: String) {
  }
  
  /**
   Do the unique comparison between the source object and the destination object.
   Objects should be unique in a certain way. It means that a key exist that identifies them uniquely,
   event if the content of each object is different.
   
   - parameter srcObject: the source object
   - parameter dstObject: the destination object
   - parameter context:   a context, if needed for the comparison
   
   - returns: `true` if the keys that identify the objects are equal, otherwise returns `false`.
   */
  public class func sfCompareUniqueKeyFrom(
    srcObject: AnyObject,
    with dstObject: AnyObject,
    context: AnyObject?) -> Bool {
      return true
  }
  
  /**
   Insert the object referenced by data
   
   - parameter data:    the object involved in the operation
   - parameter moc:     the managed object context associated to the operation
   - parameter context: a context, if needed for the operation
   
   - returns: the newly inserted managed object
   */
  public class func sfCreateObjectWithData(
    data: AnyObject,
    managedObjectContext moc: NSManagedObjectContext,
    context: AnyObject?
    ) -> NSManagedObject? {
      fatalError("createObjectWithData(data:managedObjectContext:context:) has not been implemented")
  }
  
  /**
   Updates the object referenced by data
   
   - parameter data:    the object involved in the operation
   - parameter moc:     the managed object context associated to the operation
   - parameter context: a context, if needed for the operation
   
   - returns: the updated managed object
   */
  public class func sfUpdateObjectWithData(
    data: AnyObject,
    updatedObject: AnyObject,
    managedObjectContext moc: NSManagedObjectContext,
    context: AnyObject?
    ) -> NSManagedObject? {
      fatalError("updateObjectWithData(data:managedObjectContext:context:) has not been implemented")
  }
  
  /**
   Deletes the object referenced by data
   
   - parameter data:    the object involved in the operation
   - parameter moc:     the managed object context associated to the operation
   - parameter context: a context, if needed for the operation
   
   - returns: the deleted managed object
   */
  public class func sfDeleteObjectWithData(
    data: AnyObject,
    managedObjectContext moc: NSManagedObjectContext,
    context: AnyObject?
    ) -> NSManagedObject? {
      fatalError("deleteObjectWithData(data:managedObjectContext:context:) has not been implemented")
  }
  
  /**
   do the whole synchronization
   
   - parameter inputObjects: source (master)
   - parameter existingData: destination (slave)
   - parameter key:          the priority key
   - parameter moc:          the managed object context in which to operate the synchronization
   - parameter context:      the context if any needed
   
   - returns: the resulting set 
   */
  public class func sfSynchronizeSortedInputData(
    inputObjects: [AnyObject],
    withSortedExistingData existingData: [AnyObject],
    priorityKey key: String,
    managedObjectContext moc: NSManagedObjectContext,
    context: AnyObject? = nil) -> NSSet {
      
      var srcIndex = 0 // Source index
      var dstIndex = 0 // Destination index
      
      var resultSet = NSMutableSet()
      
      // While source index does not reach the upper bound of the existing data count
      while srcIndex < inputObjects.count {
        // We treat the current source object
        let srcMO: AnyObject = inputObjects[srcIndex]
        
        // Have we reached yet the end of the source array?
        if existingData.sfIsIndexOutOfBounds(dstIndex) {
          
          // There we are out of bounds, so this is an insertion --> Create the object
          self.owsInsertObject(object: srcMO, resultSet: &resultSet, key: key, managedObjectContext: moc, syncContext: context)
{'fraction_non_alphanumeric': 0.06087133550488599, 'fraction_numerical': 0.002035830618892508, 'mean_word_length': 3.1281512605042017, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '366375', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2452, 'n_words': 1046}