text:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.IO;
using System.Reflection;

using Duality.Serialization;
using Duality.Cloning;
using Duality.Properties;
using Duality.IO;
using Duality.Editor;
using Duality.Editor.AssetManagement;

namespace Duality
{
	/// <summary>
	/// The abstract Resource class is inherited by any kind of Duality content. Instances of it or one of its subclasses
	/// are usually handled wrapped inside a <see cref="ContentRef{T}"/> and requested from the <see cref="ContentProvider"/>.
	/// </summary>
	/// <seealso cref="ContentRef{T}"/>
	/// <seealso cref="ContentProvider"/>
	[CloneBehavior(CloneBehavior.Reference)]
	[EditorHintImage(CoreResNames.ImageResource)]
	public abstract class Resource : IManageableObject, IDisposable, ICloneExplicit
	{
		/// <summary>
		/// A Resource files extension.
		/// </summary>
		internal static readonly string FileExt = ".res";
		/// <summary>
		/// (Virtual) base path for Duality's embedded default content.
		/// </summary>
		public static readonly string DefaultContentBasePath = "Default:";

		private	static	List<Resource>	finalizeSched	= new List<Resource>();

		public static event EventHandler<ResourceEventArgs>	ResourceDisposing = null;
		public static event EventHandler<ResourceEventArgs>	ResourceLoaded = null;
		public static event EventHandler<ResourceSaveEventArgs>	ResourceSaved = null;
		public static event EventHandler<ResourceSaveEventArgs>	ResourceSaving = null;

		/// <summary>
		/// Contains information on how this <see cref="Resource"/> should be treated during
		/// Asset import operations in the editor.
		/// </summary>
		[CloneField(CloneFieldFlags.Skip)]
		protected AssetInfo assetInfo = null;
		/// <summary>
		/// The path of this Resource.
		/// </summary>
		[DontSerialize]
		protected string path = null;
		/// <summary>
		/// The initialization state of the Resource. Also specifies a disposed-state.
		/// </summary>
		[DontSerialize]
		private InitState initState = InitState.Initialized;

		/// <summary>
		/// [GET] Returns whether the Resource has been disposed.
		/// Disposed Resources are not to be used and are treated the same as a null value by most methods.
		/// </summary>
		[EditorHintFlags(MemberFlags.Invisible)]
		public bool Disposed
		{
			get { return this.initState == InitState.Disposed; }
		}
		/// <summary>
		/// [GET] The path where this Resource has been originally loaded from or was first saved to.
		/// It is also the path under which this Resource is registered at the <see cref="ContentProvider"/>.
		/// </summary>
		[EditorHintFlags(MemberFlags.Invisible)]
		public string Path
		{
			get { return this.path; }
			internal set { this.path = value; }
		}
		/// <summary>
		/// [GET / SET] Provides information on the way this <see cref="Duality.Resource"/> should be treated during
		/// Asset import operations in the editor. This information is not available at runtime and can only be
		/// accessed or set outside a <see cref="DualityApp.ExecutionEnvironment.Launcher"/> environment.
		/// </summary>
		[EditorHintFlags(MemberFlags.Invisible)]
		public AssetInfo AssetInfo
		{
			get
			{
				if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Launcher)
					return null;
				else
					return this.assetInfo;
			}
			set
			{
				if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Launcher)
					throw new NotSupportedException("This property cannot be set at runtime.");
				else
					this.assetInfo = value;
			}
		}
		/// <summary>
		/// [GET] The name of the Resource.
		/// </summary>
		[EditorHintFlags(MemberFlags.Invisible)]
		public string Name
		{
			get
			{
				if (this.IsRuntimeResource)
					return this.GetHashCode().ToString(CultureInfo.InvariantCulture);
				else
					return Resource.GetNameFromPath(this.path);
			}
		}
		/// <summary>
		/// [GET] The full name of the Resource, including its path but not its file extension
		/// </summary>
		[EditorHintFlags(MemberFlags.Invisible)]
		public string FullName
		{
			get
			{
				if (this.IsRuntimeResource)
					return this.GetHashCode().ToString(CultureInfo.InvariantCulture);
				else
					return Resource.GetFullNameFromPath(this.path);
			}
		}
		/// <summary>
		/// [GET] Returns whether the Resource is part of Duality's embedded default content.
		/// </summary>
		[EditorHintFlags(MemberFlags.Invisible)]
		public bool IsDefaultContent
		{
			get { return Resource.IsDefaultContentPath(this.path); }
		}
		/// <summary>
		/// [GET] Returns whether the Resource has been generated at runtime and  cannot be retrieved via content path.
		/// </summary>
		[EditorHintFlags(MemberFlags.Invisible)]
		public bool IsRuntimeResource
		{
			get { return string.IsNullOrEmpty(this.path); }
		}
		bool IManageableObject.Active
		{
			get { return !this.Disposed; }
		}

		/// <summary>
		/// Saves the Resource to the specified path.
		/// </summary>
		/// <param name="saveAsPath">The path to which this Resource is saved to. If null, the Resources <see cref="Path"/> is used as destination.</param>
		/// <param name="makePermanent">
		/// When true, the Resource will be made permanently available from now on. If it has been generated at runtime
		/// or was loaded explicitly outside the ContentProvider, this will set the Resources <see cref="Path"/> Property
		/// and register it in the <see cref="ContentProvider"/>. If the Resource already is a permanent, this parameter will be ignored.
		/// </param>
		public void Save(string saveAsPath = null, bool makePermanent = true)
		{
			if (this.Disposed) throw new ObjectDisposedException("Can't save a Resource that has been disposed.");
			if (string.IsNullOrWhiteSpace(saveAsPath))
			{
				saveAsPath = this.path;
				if (string.IsNullOrWhiteSpace(saveAsPath))
					throw new ArgumentException("Can't save a Resource to an undefined path.", "saveAsPath");
			}

			// Prepare saving the Resource and abort if an error occurred in the process
			bool preparedSuccessfully = this.CheckedOnSaving(saveAsPath);
			if (!preparedSuccessfully) return;

			// We're saving a new Resource for the first time: Register it in the library
			bool isPermanent = !string.IsNullOrWhiteSpace(this.path);
			if (makePermanent && !isPermanent)
			{
				this.path = saveAsPath;
				ContentProvider.AddContent(this.path, this);
			}

			string dirName = PathOp.GetDirectoryName(saveAsPath);
			if (!string.IsNullOrEmpty(dirName) && !DirectoryOp.Exists(dirName)) DirectoryOp.Create(dirName);
			using (Stream str = FileOp.Create(saveAsPath))
			{
				this.WriteToStream(str);
			}
			this.CheckedOnSaved(saveAsPath);
		}
		/// <summary>
		/// Saves the Resource to the specified stream.
		/// </summary>
		/// <param name="str"></param>
		public void Save(Stream str)
		{
			if (this.Disposed) throw new ObjectDisposedException("Can't save a Resource that has been disposed.");

			this.CheckedOnSaving(null);
			this.WriteToStream(str);
			this.CheckedOnSaved(null);
		}
		private void WriteToStream(Stream str)
		{
			using (Serializer serializer = Serializer.Create(str, Serializer.DefaultType))
			{
				serializer.AddFieldBlocker(Resource.DontSerializeResourceBlocker);
				if (this is Duality.Resources.Scene) // This is an unfortunate hack. Refactor when necessary.
					serializer.AddFieldBlocker(Resource.PrefabLinkedFieldBlocker);
				serializer.WriteObject(this);
			}
		}
		private bool CheckedOnSaving(string saveAsPath)
		{
			if (this.initState != InitState.Initialized) return true;
			try
			{
				if (ResourceSaving != null) ResourceSaving(this, new ResourceSaveEventArgs(this, saveAsPath));
				this.OnSaving(saveAsPath);
				return true;
			}
			catch (Exception e)
			{
				Logs.Core.WriteError("OnSaving() of {0} failed: {1}", this, LogFormat.Exception(e));
				return false;
			}
		}
		private bool CheckedOnSaved(string saveAsPath)
		{
			if (this.initState != InitState.Initialized) return true;
			try
			{
				this.OnSaved(saveAsPath);
				if (ResourceSaved != null) ResourceSaved(this, new ResourceSaveEventArgs(this, saveAsPath));
				return true;
			}
			catch (Exception e)
			{
				Logs.Core.WriteError("OnSaved() of {0} failed: {1}", this, LogFormat.Exception(e));
				return false;
			}
		}

		/// <summary>
		/// Creates a deep copy of this Resource.
		/// </summary>
		public Resource Clone()
		{
			return this.DeepClone();
		}
		/// <summary>
		/// Deep-copies this Resource to the specified target Resource. The target Resource's Type must
		/// match this Resource's Type.
		/// </summary>
		/// <param name="target">The target Resource to copy this Resource's data to</param>
		public void CopyTo(Resource target)
		{
			this.DeepCopyTo(target);
		}

		void ICloneExplicit.SetupCloneTargets(object target, ICloneTargetSetup setup)
		{
			setup.HandleObject(this, target);
			this.OnSetupCloneTargets(target, setup);
		}
		void ICloneExplicit.CopyDataTo(object target, ICloneOperation operation)
		{
			operation.HandleObject(this, target);
			this.OnCopyDataTo(target, operation);
		}
		/// <summary>
		/// This method prepares the <see cref="CopyTo"/> operation for custom Resource Types.
		/// It uses reflection to prepare the cloning operation automatically, but you can implement
		/// this method in order to handle certain fields and cases manually. See <see cref="ICloneExplicit.SetupCloneTargets"/>
		/// for a more thorough explanation.
		/// </summary>
		protected virtual void OnSetupCloneTargets(object target, ICloneTargetSetup setup) {}
		/// <summary>
		/// This method performs the <see cref="CopyTo"/> operation for custom Resource Types.
		/// It uses reflection to perform the cloning operation automatically, but you can implement
		/// this method in order to handle certain fields and cases manually. See <see cref="ICloneExplicit.CopyDataTo"/>
		/// for a more thorough explanation.
		/// </summary>
		/// <param name="target">The target Resource where this Resources data is copied to.</param>
		/// <param name="operation"></param>
		protected virtual void OnCopyDataTo(object target, ICloneOperation operation) {}
		/// <summary>
		/// Called when this Resource is now beginning to be saved.
		/// </summary>
		protected virtual void OnSaving(string saveAsPath) {}
		/// <summary>
		/// Called when this Resource has just been saved.
		/// </summary>
		protected virtual void OnSaved(string saveAsPath) {}
		/// <summary>
		/// Called when this Resource has just been loaded.
		/// </summary>
		protected virtual void OnLoaded() {}

		~Resource()
		{
			lock (finalizeSched)
			{
				finalizeSched.Add(this);
			}
		}
		/// <summary>
		/// Disposes the Resource. Please don't do something silly, like disposing a Scene while it is updated.. use <see cref="ExtMethodsIManageableObject.DisposeLater"/> instead!
		/// </summary>
		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}
		private void Dispose(bool manually)
		{
			if (this.initState == InitState.Initialized)
			{
				this.initState = InitState.Disposing;

				// Invoke external and internal handlers for resource disposal
				if (ResourceDisposing != null)
					ResourceDisposing(this, new ResourceEventArgs(this));
				this.OnDisposing(manually);

				this.initState = InitState.Disposed;

				// Remove the resource from the central registry
				ContentProvider.RemoveContent(this, false);
			}
		}
		/// <summary>
		/// Called when beginning to dispose the Resource.
		/// </summary>
		/// <param name="manually"></param>
		protected virtual void OnDisposing(bool manually) {}

		/// <summary>
		/// Creates a <see cref="ContentRef{T}"/> referring to this Resource.
		/// </summary>
		/// <returns>A <see cref="ContentRef{T}"/> referring to this Resource.</returns>
		public IContentRef GetContentRef()
		{
			Type refType = typeof(ContentRef<>).MakeGenericType(this.GetType());
			return Activator.CreateInstance(refType, this) as IContentRef;
		}

		public override string ToString()
		{
			return string.Format("{0} \"{1}\"", this.GetType().Name, this.FullName);
		}

		/// <summary>
		/// Loads the Resource that is located at the specified path. You shouldn't need this method in almost all cases.
		/// Only use it when you know exactly what you're doing. Consider requesting the Resource from the <see cref="ContentProvider"/> instead.
		/// </summary>
		/// <typeparam name="T">
		/// Desired Type of the returned reference. Does not affect the loaded Resource in any way - it is simply returned as T.
		/// Results in returning null if the loaded Resource's Type isn't assignable to T.
		/// </typeparam>
		/// <param name="path">The path to load the Resource from.</param>
		/// <param name="loadCallback">An optional callback that is invoked right after loading the Resource, but before initializing it.</param>
		/// <param name="initResource">
		/// Specifies whether or not the Resource is initialized by calling <see cref="Resource.OnLoaded"/>. Never attempt to use
		/// uninitialized Resources or register them in the <see cref="ContentProvider"/>.
		/// </param>
		/// <returns>The Resource that has been loaded.</returns>
		public static T Load<T>(string path, Action<T> loadCallback = null, bool initResource = true) where T : Resource
		{
			if (!FileOp.Exists(path)) return null;

			T newContent;
			using (Stream str = FileOp.Open(path, FileAccessMode.Read))
			{
				newContent = Load<T>(str, path, loadCallback, initResource);
			}
			return newContent;
		}
		/// <summary>
		/// Loads the Resource from the specified <see cref="Stream"/>. You shouldn't need this method in almost all cases.
		/// Only use it when you know exactly what you're doing. Consider requesting the Resource from the <see cref="ContentProvider"/> instead.
		/// </summary>
		/// <typeparam name="T">
		/// Desired Type of the returned reference. Does not affect the loaded Resource in any way - it is simply returned as T.
		/// Results in returning null if the loaded Resource's Type isn't assignable to T.
		/// </typeparam>
		/// <param name="str">The stream to load the Resource from.</param>
		/// <param name="resPath">The path that is assumed as the loaded Resource's origin.</param>
		/// <param name="loadCallback">An optional callback that is invoked right after loading the Resource, but before initializing it.</param>
		/// <param name="initResource">
		/// Specifies whether or not the Resource is initialized by calling <see cref="Resource.OnLoaded"/>. Never attempt to use
		/// uninitialized Resources or register them in the <see cref="ContentProvider"/>.
		/// </param>
		/// <returns>The Resource that has been loaded.</returns>
		public static T Load<T>(Stream str, string resPath = null, Action<T> loadCallback = null, bool initResource = true) where T : Resource
		{
			using (Serializer serializer = Serializer.Create(str))
			{
				return Load<T>(serializer, resPath, loadCallback, initResource);
			}
		}
		/// <summary>
		/// Loads the Resource from the specified <see cref="Stream"/>. You shouldn't need this method in almost all cases.
		/// Only use it when you know exactly what you're doing. Consider requesting the Resource from the <see cref="ContentProvider"/> instead.
		/// </summary>
		/// <typeparam name="T">
		/// Desired Type of the returned reference. Does not affect the loaded Resource in any way - it is simply returned as T.
		/// Results in returning null if the loaded Resource's Type isn't assignable to T.
		/// </typeparam>
		/// <param name="formatter"></param>
		/// <param name="resPath">The path that is assumed as the loaded Resource's origin.</param>
		/// <param name="loadCallback">An optional callback that is invoked right after loading the Resource, but before initializing it.</param>
		/// <param name="initResource">
		/// Specifies whether or not the Resource is initialized by calling <see cref="Resource.OnLoaded"/>. Never attempt to use
		/// uninitialized Resources or register them in the <see cref="ContentProvider"/>.
		/// </param>
		/// <returns>The Resource that has been loaded.</returns>
		public static T Load<T>(Serializer formatter, string resPath = null, Action<T> loadCallback = null, bool initResource = true) where T : Resource
		{
			T newContent = null;

			try
			{
				Resource res = formatter.ReadObject<Resource>();
				if (res == null) throw new Exception("Deserializing Resource failed.");

				res.initState = InitState.Initializing;
				res.path = resPath;
				if (loadCallback != null) loadCallback(res as T); // Callback before initializing.
				if (initResource) Init(res);
				newContent = res as T;
			}
			catch (Exception e)
			{
				Logs.Core.WriteError("Can't load {0} from '{1}', because an error occurred: {3}{2}",
					LogFormat.Type(typeof(T)),
					resPath ?? formatter.ToString(),
					LogFormat.Exception(e),
					Environment.NewLine);
			}

			return newContent;
		}

		/// <summary>
		/// Initializes a Resource that has been loaded without initialization. You shouldn't need this method in almost all cases.
		/// Only use it when you know exactly what you're doing. Consider requesting the Resource from the <see cref="ContentProvider"/> instead.
		/// </summary>
		/// <param name="res">The Resource to initialize.</param>
		public static void Init(Resource res)
		{
			if (res.initState != InitState.Initializing) return;

			res.OnLoaded();
			res.initState = InitState.Initialized;

			if (ResourceLoaded != null)
				ResourceLoaded(res, new ResourceEventArgs(res));
		}

		/// <summary>
		/// Determines the name of a Resource based on its path.
		/// </summary>
		/// <param name="resPath"></param>
		public static string GetNameFromPath(string resPath)
		{
			if (string.IsNullOrEmpty(resPath)) return "null";
			if (IsDefaultContentPath(resPath)) resPath = resPath.Replace(':', PathOp.DirectorySeparatorChar);
			return PathOp.GetFileNameWithoutExtension(PathOp.GetFileNameWithoutExtension(resPath));
		}
		/// <summary>
		/// Determines the full (hierarchical) name of a Resource based on its path.
		/// </summary>
		/// <param name="resPath"></param>
		public static string GetFullNameFromPath(string resPath)
		{
			if (string.IsNullOrEmpty(resPath)) return "null";
			if (IsDefaultContentPath(resPath)) resPath = resPath.Replace(':', PathOp.DirectorySeparatorChar);
			return PathOp.Combine(PathOp.GetDirectoryName(resPath), GetNameFromPath(resPath));
		}

		/// <summary>
		/// Returns whether or not the specified path points to Duality default content.
		/// </summary>
		/// <param name="resPath"></param>
		public static bool IsDefaultContentPath(string resPath)
		{
			return
				resPath != null &&
				resPath.StartsWith(DefaultContentBasePath, StringComparison.Ordinal);
		}

		/// <summary>
		/// Determines whether or not the specified path points to a Duality Resource file.
		/// </summary>
		/// <param name="filePath"></param>
		public static bool IsResourceFile(string filePath)
		{
			return string.Equals(PathOp.GetExtension(filePath), FileExt, StringComparison.OrdinalIgnoreCase);
		}
		/// <summary>
		/// Returns all Resource files that are located in the specified directory. This doesn't affect
		/// any actual content- or load states.
		/// </summary>
		/// <param name="folderPath"></param>
		public static IEnumerable<string> GetResourceFiles(string folderPath = null)
		{
			if (string.IsNullOrEmpty(folderPath)) folderPath = DualityApp.DataDirectory;
			IEnumerable<string> resFiles = DirectoryOp.GetFiles(folderPath, true);
			return resFiles.Where(path => path.EndsWith(Resource.FileExt, StringComparison.OrdinalIgnoreCase));
		}
		/// <summary>
		/// Returns the Resource file extension for a specific Resource Type.
		/// </summary>
		/// <param name="resType">The Resource Type to return the file extension from.</param>
		/// <returns>The specified Resource Type's file extension.</returns>
		public static string GetFileExtByType(Type resType)
		{
			if (resType == null || resType == typeof(Resource))
				return FileExt;
			else
				return "." + resType.Name + FileExt;
		}
		/// <summary>
		/// Returns the Resource file extension for a specific Resource Type.
		/// </summary>
		/// <typeparam name="T">The Resource Type to return the file extension from.</typeparam>
		/// <returns>The specified Resource Type's file extension.</returns>
		public static string GetFileExtByType<T>() where T : Resource
		{
			if (typeof(T) == typeof(Resource))
				return FileExt;
			else
				return "." + typeof(T).Name + FileExt;
		}
		/// <summary>
		/// Returns the Resource Type that is associated with the specified file, based on its extension.
		/// </summary>
		/// <param name="filePath">Path to the file of whichs Resource Type will be returned</param>
		/// <returns>The Resource Type of the specified file</returns>
		public static Type GetTypeByFileName(string filePath)
		{
			// Early-out if we don't have a valid resource path
			if (string.IsNullOrEmpty(filePath) || Resource.IsDefaultContentPath(filePath))
				return null;

			// Determine the (double) extension of the resource path
			filePath = PathOp.GetFileNameWithoutExtension(filePath);
			string[] token = filePath.Split('.');
			if (token.Length < 2)
				return null;

			// Extract the type extension and match it with the available resource types
			string typeName = token[token.Length - 1];
			TypeInfo matchingInfo =
				DualityApp.GetAvailDualityTypes(typeof(Resource))
				.FirstOrDefault(t => t.Name == typeName);
			if (matchingInfo == null)
				return null;

			// Return the result
			return matchingInfo.AsType();
		}

		/// <summary>
		/// A <see cref="Duality.Serialization.Serializer.FieldBlockers">FieldBlocker</see> to prevent
		/// fields flagged with a <see cref="DontSerializeResourceAttribute"/> from being serialized.
		/// </summary>
		/// <param name="field"></param>
		/// <param name="obj"></param>
		public static bool DontSerializeResourceBlocker(FieldInfo field, object obj)
		{
			return field.HasAttributeCached<DontSerializeResourceAttribute>();
		}
		/// <summary>
		/// A <see cref="Duality.Serialization.Serializer.FieldBlockers">FieldBlocker</see> to prevent
		/// fields of <see cref="Duality.Resources.PrefabLink">PrefabLink-ed</see> objects from being serialized unnecessarily.
		/// </summary>
		/// <param name="field"></param>
		/// <param name="obj"></param>
		public static bool PrefabLinkedFieldBlocker(FieldInfo field, object obj)
		{
			Component cmp = obj as Component;
			if (cmp == null || cmp.GameObj == null) return false;

			Resources.PrefabLink link = cmp.GameObj.AffectedByPrefabLink;
			if (link == null || !link.AffectsObject(cmp)) return false;

			return field.DeclaringType != typeof(Component);
		}

		internal static void RunCleanup()
		{
			Resource[] finalizeSchedArray;
			lock (finalizeSched)
			{
				if (finalizeSched.Count == 0) return;
				finalizeSchedArray = finalizeSched.ToArray();
				finalizeSched.Clear();
			}

			foreach (Resource res in finalizeSchedArray)
			{
				if (res == null) continue;
				res.Dispose(false);
			}
		}
	}

	/// <summary>
	/// Indicates that a field will be assumed null when serializing it as part of a Resource serialization.
	/// </summary>
	[AttributeUsage(AttributeTargets.Field)]
	public class DontSerializeResourceAttribute : Attribute { }

	/// <summary>
	/// Allows to explicitly specify what kinds of Resources a certain Resource Type is able to reference.
	/// This is an optional attribute that is used for certain runtime optimizations.
	/// </summary>
	[AttributeUsage(AttributeTargets.Class)]
	public class ExplicitResourceReferenceAttribute : Attribute
	{
		private	Type[]	referencedTypes	= null;

		public IEnumerable<Type> ReferencedTypes
		{
			get { return this.referencedTypes; }
		}

		public ExplicitResourceReferenceAttribute(params Type[] referencedTypes)
		{
			if (referencedTypes == null) throw new ArgumentNullException("referencedTypes");
			TypeInfo resourceTypeInfo = typeof(Resource).GetTypeInfo();
			for (int i = 0; i < referencedTypes.Length; ++i)
			{
				if (referencedTypes[i] == null || !resourceTypeInfo.IsAssignableFrom(referencedTypes[i].GetTypeInfo()))
					throw new ArgumentException("Only Resource Types are valied in this Attribute");
			}
			this.referencedTypes = referencedTypes;
		}
	}
}


text:
<?php

require_once 'structure.php';

class AbricosStructureData extends AbricosItem {

    protected $_data = array();

    /**
     * @var AbricosStructure
     */
    protected $_structure;

    public function __construct($structure, $d){
        if (!($structure instanceof AbricosStructure)){
            throw new Exception('Structure not found in AbricosStructureData');
        }
        $this->_structure = $structure;

        if (is_object($d)){
            $d = get_object_vars($d);
        }

        if (isset($structure->idField)){
            unset($this->id); // hack for use method __get('id')
            $this->id = isset($d[$structure->idField]) ? $d[$structure->idField] : 0;
        }

        $this->Update($d);
    }

    public function Update($d){
        $struct = $this->_structure;
        $count = $struct->Count();

        for ($i = 0; $i < $count; $i++){
            $field = $struct->GetByIndex($i);
            $name = $field->name;

            if ($field->type === 'multiLang'){
                $this->__set($name, $d);
            } else {
                $val = null;
                if (isset($d[$name])){
                    $val = $d[$name];
                } else if (isset($field->dbField) && isset($d[$field->dbField])){
                    $val = $d[$field->dbField];
                }
                $this->__set($name, $val);
            }
        }
    }

    public function __set($name, $value){
        /** @var AbricosModelStructureField $field */
        $field = $this->_structure->Get($name);

        if (empty($field)){
            $this->_data[$name] = $value;
            return;
        }

        if ($field->type === 'multiLang'){
            if (isset($this->_data[$name])){
                $this->_data[$name]->Set($value);
            } else {
                $this->_data[$name] = new AbricosMultiLangValue($name, $value);
            }
        } else if ($field->type === 'object'){
            if (empty($value)){
                unset($this->_data[$name]);
            } else if (is_array($value)){
                $this->_data[$name] = array_to_object($value);
            } else {
                $this->_data[$name] = $value;
            }
        } else if ($field->type === 'array'){
            if (empty($value)){
                unset($this->_data[$name]);
            } else if (is_array($value)){
                $this->_data[$name] = $value;
            } else if (is_object($value)){
                $this->_data[$name] = get_object_vars($value);
            } else if (isset($this->_data[$name])){
                $this->_data[$name] = $value;
            } else {
                $this->_data[$name] = $value;
            }
        } else if ($field->type === 'model'){
            if (empty($value) && !$field->notNULL){
                unset($this->_data[$name]);
            } else if ($value instanceof AbricosModel){
                $this->_data[$name] = $value;
            } else if (isset($this->_data[$name])){
                $this->_data[$name]->Update($value);
            } else {
                $manager = isset($field->typeModule) ?
                    AbricosModelManager::GetManager($field->typeModule) :
                    $this->_structure->manager;

                $this->_data[$name] = $manager->InstanceClass($field->typeClass, $value);
            }
        } else if ($field->type === 'modelList'
            || $field->type === 'list' // TODO: deprecated
        ){
            if (empty($value) && !$field->notNULL){
                unset($this->_data[$name]);
            } else if ($value instanceof AbricosModelList){
                $this->_data[$name] = $value;
            } else if (isset($this->_data[$name])){
                $this->_data[$name]->Update($value);
            } else {
                $manager = isset($field->typeModule) ?
                    AbricosModelManager::GetManager($field->typeModule) :
                    $this->_structure->manager;

                $this->_data[$name] = $manager->InstanceClass($field->typeClass, $value);
            }
        } else if ($field->type === 'string'){
            $value = $field->TypeVal($value);
            if (!is_null($value)){
                $this->_data[$name] = $value;
            }
        } else {
            $this->_data[$name] = $field->TypeVal($value);
        }
    }

    public function __get($name){
        if (isset($this->_data[$name])){
            /*
            if ($this->_data[$name] instanceof AbricosMultiLangValue){
                return $this->_data[$name]->Get();
            }
            /**/

            return $this->_data[$name];
        }
        $field = !empty($this->_structure) ? $this->_structure->Get($name) : null;
        if (!empty($field) && isset($field->default)){
            return $field->default;
        }
        return null;
    }

    public function __isset($name){
        return isset($this->_data[$name]);
    }

    public function ToJSON(){
        $ret = parent::ToJSON();

        $struct = $this->_structure;
        if (empty($struct)){
            return $ret;
        }

        $useridField = $struct->Get('userid');
        $isPersonalAccess = false;
        if (!empty($useridField) && isset($this->_data['userid'])){
            $userid = $this->_data['userid'];
            if ($userid > 0 && intval($userid) === intval(Abricos::$user->id)){
                $isPersonalAccess = true;
            }
        }

        $moduleManager = $struct->manager->module->GetManager();

        $count = $struct->Count();
        for ($i = 0; $i < $count; $i++){
            $field = $struct->GetByIndex($i);
            if (!isset($this->_data[$field->name])){
                continue;
            }

            $pDefine = $field->personal;
            $pAccess = true;
            if ($pDefine){
                $pAccess = $isPersonalAccess;
            }

            $rDefine = is_string($field->rolefn);
            $rAccess = true;

            if ($rDefine){
                $rAccess = false;
                if (method_exists($moduleManager, $field->rolefn)){
                    $funcName = $field->rolefn;
                    if ($moduleManager->$funcName()){
                        $rAccess = true;
                    }
                }
            }

            if ((!$pAccess && !$rAccess) ||
                ($pDefine && !$pAccess && !$rDefine) ||
                ($rDefine && !$rAccess && !$pDefine)
            ){
                continue;
            }

            if ($field->type === 'multiLang'
                || $field->type === 'list' // TODO: deprecated in [Structure].json
                || $field->type === 'model'
                || $field->type === 'modelList'
            ){
                $value = $this->_data[$field->name]->ToJSON();
            } else {
                $value = $this->_data[$field->name];
            }
            if (empty($value)){
                continue;
            }
            $jsonName = isset($field->json) ? $field->json : $field->name;
            $ret->$jsonName = $value;
        }

        return $ret;
    }
}

class AbricosModel extends AbricosStructureData {

    /**
     * @var AbricosApplication
     */
    public $app;

    /**
     * @var Ab_Module
     */
    protected $_structModule;

    /**
     * @var string
     */
    protected $_structName;

    public function __construct($d){
        if (is_string($this->_structModule)){
            $this->_structModule = Abricos::GetModule($this->_structModule);
        }

        if (!($this->_structModule instanceof Ab_Module)){
            throw new Exception('Module not found in AbricosModel');
        }

        $moduleManager = AbricosModelManager::GetManager($this->_structModule);
        $structure = $moduleManager->GetStructure($this->_structName);

        parent::__construct($structure, $d);
    }

    public function ToArray($fieldName = ''){
        $struct = $this->_structure;
        if (empty($struct)){
            return array('id' => $this->id);
        }

        $ret = array();

        if (!empty($fieldName)){
            $field = $struct->Get($fieldName);
            $ret[$fieldName] = isset($this->_data[$fieldName])
                ? $this->_data[$fieldName]
                : $field->default;
            return $ret;
        }

        $count = $struct->Count();
        for ($i = 0; $i < $count; $i++){
            $field = $struct->GetByIndex($i);
            if (!isset($this->_data[$field->name])){
                continue;
            }
            if ($field->type === 'multiLang'){
                $value = $this->_data[$field->name]->ToArray();
            } else {
                $value = $this->_data[$field->name];
            }
            $ret[$field->name] = $value;
        }

        return $ret;
    }

}

class AbricosModelList extends AbricosList {

    /**
     * @var AbricosApplication
     */
    public $app;

    /**
     * @var Ab_Module
     */
    protected $_structModule;

    /**
     * @var string
     */
    protected $_structName;

    /**
     * @var string
     */
    protected $_structData;

    /**
     * @var AbricosModelListStructure|null
     */
    protected $_structure = null;

    public function __construct($items = null){
        parent::__construct();

        if (is_string($this->_structModule)){
            $this->_structModule = Abricos::GetModule($this->_structModule);

            if (!($this->_structModule instanceof Ab_Module)){
                throw new Exception('Module not found in AbricosModelList');
            }

            $models = AbricosModelManager::GetManager($this->_structModule);

            if (empty($this->_structure) && !empty($this->_structModule) && !empty($this->_structName)){
                $this->_structure = $models->GetStructure($this->_structName);
            }

            if (!($this->_structure instanceof AbricosModelStructure)){
                throw new Exception('Structure not found in AbricosModelList');
            }

            if (isset($this->_structData)){
                $data = $models->GetData($this->_structData);

                if (is_object($data) && isset($data->items) && is_array($data->items)){
                    $this->Update($data->items);
                }
            }
        }

        $this->Update($items);
    }

    /**
     * @param array $data
     */
    public function Update($items){
        if (!is_array($items) || empty($this->_structure)){
            return;
        }

        $models = AbricosModelManager::GetManager($this->_structModule);
        $itemType = $this->_structure->itemType;
        for ($i = 0; $i < count($items); $i++){
            $item = $models->InstanceClass($itemType, $items[$i]);
            $this->Add($item);
        }
    }

    public function ToArray($fieldName = ''){
        $ret = array();
        $count = $this->Count();
        for ($i = 0; $i < $count; $i++){
            /** @var AbricosModel $item */
            $item = $this->GetByIndex($i);

            if (empty($fieldName)){
                $ret[] = $item->ToArray();
            } else {
                $ret[] = $item->$fieldName;
            }
        }
        return $ret;
    }
}

/**
 * Class AbricosResponse
 */
class AbricosResponse extends AbricosModel {
    const ERR_BAD_REQUEST = 400;
    const ERR_UNAUTHORIZED = 401;
    const ERR_FORBIDDEN = 403;
    const ERR_NOT_FOUND = 404;
    const ERR_SERVER_ERROR = 500;

    /**
     * @var AbricosStructureData
     */
    public $vars;

    /**
     * Error code
     * @var int
     */
    public $error = 0;

    /**
     * Detail code
     * @var int
     */
    public $code = 0;

    /**
     * @var AbricosResponseStructureCodeList
     */
    public $codes;

    /**
     * Source data
     * @var object
     */
    public $srcData;

    public function __construct($varsData, $d){
        parent::__construct($d);

        $this->srcData = $varsData;

        /** @var AbricosResponseStructure $structure */
        $structure = $this->_structure;

        if (!($structure instanceof AbricosResponseStructure)){
            throw new Exception(
                'Structure must be AbricosResponseStructure '.
                '(module: '.$this->_structModule->name.", name=".$this->_structName.")"
            );
        }

        $this->codes = $structure->codes;

        $this->vars = new AbricosStructureData($structure->vars, $varsData);
    }

    public static function IsError($response){
        if ($response instanceof AbricosResponse){
            return $response->error > 0;
        }

        if (is_integer($response)){
            return true;
        }
        return false;
    }

    public function SetError($error, $code = 0){
        $this->error = $error;
        if (!empty($code)){
            $this->code = intval($code);
        }
        return $this;
    }

    public function AddCode(){
        $count = func_num_args();
        for ($i = 0; $i < $count; $i++){
            $this->code |= intval(func_get_arg($i));
        }
    }

    public function IsSetCode($code){
        return $code & $this->code;
    }

    public function ToJSON(){
        $ret = parent::ToJSON();
        unset($ret->id);
        if ($this->code > 0){
            $ret->code = $this->code;
        }
        return $ret;
    }

}

class AbricosMultiLangValue {
    public $name;
    protected $_data = array();
    private $_actualLang;

    public function __construct($name, $d = ''){
        $this->name = $name;
        $this->Set($d);
    }

    public static function FieldName($name, $lng = ''){
        if (empty($lng)){
            $lng = Abricos::$LNG;
        }
        return $name."_".$lng;
    }

    public function Set($d){
        if (is_array($d)){
            $name = $this->name;
            if (isset($d[$name])){
                $this->_data[Abricos::$LNG] = strval($d[$name]);
            } else {
                foreach (Abricos::$supportLanguageList as $lng){
                    $fieldName = AbricosMultiLangValue::FieldName($name, $lng);
                    $this->_data[$lng] = isset($d[$fieldName]) ? $d[$fieldName] : '';
                }
            }
        } else if (is_string($d)){
            $this->_data[Abricos::$LNG] = $d;
        }
        unset($this->_actualLang);
        $this->_UpdateActualLang();
    }

    // TODO: refactor: modify to static function
    private function _UpdateActualLang(){
        if (isset($this->_actualLang)){
            return;
        }
        $this->_actualLang = Abricos::$LNG;
        if (!isset($this->_data[$this->_actualLang])){
            $this->_data[$this->_actualLang] = '';
        }

        if (!empty($this->_data[$this->_actualLang])){
            return;
        }
        foreach (Abricos::$supportLanguageList as $lng){
            if ($this->_actualLang === $lng){
                continue;
            }
            if (isset($this->_data[$lng]) && !empty($this->_data[$lng])){
                $this->_actualLang = $lng;
                return;
            }
        }
    }

    public function Get(){
        $this->_UpdateActualLang();
        return $this->_data[$this->_actualLang];
    }

    public function ToJSON(){
        return $this->_data;
    }

    public function ToArray(){
        return $this->_data;
    }
}

class AbricosModelManager {

    private static $_managers = array();

    /**
     * @var Ab_Module
     */
    public $module;

    protected $structures = array();

    protected $classes = array();

    /**
     * @var array[string]
     */
    public $appExtends = array();

    public function __construct(Ab_Module $module){
        $this->module = $module;
    }

    /**
     * @param Ab_Module|string $module
     * @return AbricosModelManager
     * @throws Exception
     */
    public static function GetManager($module){
        if (is_string($module)){
            $name = $module;

            $module = Abricos::GetModule($module);
            if (empty($module)){
                throw new Exception("Module `$name` not found in AbricosModelManager::GetManager");
            }
        }

        $modName = $module->name;
        if (!isset(AbricosModelManager::$_managers[$modName])){
            AbricosModelManager::$_managers[$modName] = new AbricosModelManager($module);
        }
        return AbricosModelManager::$_managers[$modName];
    }

    public function RegisterClass($structName, $className){
        $this->classes[$structName] = $className;
        for ($i = 0; $i < count($this->appExtends); $i++){
            $extModels = AbricosModelManager::GetManager($this->appExtends[$i]);
            $extModels->RegisterClass($structName, $className);
        }
    }

    public function InstanceClass($structName){
        if (!isset($this->classes[$structName])){
            $modName = $this->module->name;
            throw new Exception("Class $structName not registered in AbricosModelManager: module: $modName");
        }
        $className = $this->classes[$structName];

        $args = func_get_args();
        $p0 = isset($args[1]) ? $args[1] : null;
        $p1 = isset($args[2]) ? $args[2] : null;
        $p2 = isset($args[3]) ? $args[3] : null;

        return new $className($p0, $p1, $p2);
    }

    /**
     * @param $name
     * @return AbricosModelStructure|null
     */
    public function GetStructure($name){
        $name = trim($name);
        if (isset($this->structures[$name])){
            return $this->structures[$name];
        }
        $file = realpath(CWD."/modules/".$this->module->name."/model/".$name.".json");
        if (!$file){
            for ($i = 0; $i < count($this->appExtends); $i++){
                $moduleName = $this->appExtends[$i];
                $extModels = AbricosModelManager::GetManager($moduleName);
                $struct = $extModels->GetStructure($name);
                if ($struct){
                    return $this->structures[$name] = $struct;
                }
            }
            return null;
        }
        $json = file_get_contents($file);
        $data = json_decode($json);

        if (isset($data->type) && $data->type === 'modelList'){
            $struct = new AbricosModelListStructure($this, $name, $data);
        } else if (isset($data->type) && $data->type === 'response'){
            $struct = new AbricosResponseStructure($this, $name, $data);
        } else {
            $struct = new AbricosModelStructure($this, $name, $data);
        }
        $this->structures[$name] = $struct;
        return $struct;
    }

    public function GetData($name){
        $name = trim($name);
        $file = realpath(CWD."/modules/".$this->module->name."/data/".$name.".json");
        if (!$file){
            for ($i = 0; $i < count($this->appExtends); $i++){
                $file = realpath(CWD."/modules/".$this->appExtends[$i]."/data/".$name.".json");
                if ($file){
                    break;
                }
            }
            if (!$file){
                return null;
            }
        }
        $json = file_get_contents($file);
        $data = json_decode($json);
        return $data;
    }

    public function ToJSON($names){
        if (is_string($names)){
            $names = explode(",", $names);
        }
        $ret = new stdClass();
        $ret->structures = array();

        foreach ($names as $name){
            $struct = $this->GetStructure($name);
            if (empty($struct)){
                continue;
            }
            $ret->structures[] = $struct->ToJSON();
        }
        return $ret;
    }
}

redpajama_set_name: RedPajamaGithub


text:
package org.gradle.language.nativeplatform.internal;

public enum IncludeType {
    /**
     * A system include path, eg {@code <hello.h>}
     */
    SYSTEM,
    /**
     * A quoted include path eg {@code "hello.h"}
     */
    QUOTED,
    /**
     * An identifier that should be macro expanded. These appear in the body of a directive eg {@code #define HEADER ABC}.
     */
    MACRO,
    /**
     * A macro function invocation that should be expanded. These appear in the body of a directive and as arguments to another function eg {@code #define HEADER ABC(X, Y)}.
     */
    MACRO_FUNCTION,
    /**
     * An identifier that should not be macro expanded. These appear as the arguments to a {@link #MACRO_FUNCTION} or {@link #TOKEN_CONCATENATION} eg {@code #include ABC(X, Y)}
     */
    IDENTIFIER,
    /**
     * A macro function argument list. These appear in the body of a directive or as the arguments to a {@link #MACRO_FUNCTION} eg {@code #include ABC(a b c)}.
     */
    ARGS_LIST,
    /**
     * A sequence of expressions. These appear as the arguments to a {@link #MACRO_FUNCTION} eg {@code #include ABC(a b c)}.
     */
    EXPRESSIONS,
    /**
     * A token concatenation expression whose value should not be macro expanded. These appear in the body of macro directives or as the arguments to a {@link #MACRO_FUNCTION} eg {@code #define ABC(X, Y) X ## Y}.
     */
    TOKEN_CONCATENATION,
    /**
     * A token concatenation expression whose value should be macro expanded.
     */
    EXPAND_TOKEN_CONCATENATION,
    /**
     * A single character that is not an identifier. These appear as the arguments to a {@link #MACRO_FUNCTION} eg {@code #include ABC((a b, c))}.
     */
    TOKEN,
    /**
     * All other expressions. These things cannot be resolved to an include path.
     */
    OTHER
}


text:
var login = require('./login');
var signup = require('./signup');
var mongoDbConnection = require('../db.js');
var ObjectId = require('mongodb').ObjectID;

module.exports = function(passport) {

    // Passport needs to be able to serialize and deserialize users to support persistent login sessions
    passport.serializeUser(function(user, done) {
        console.log(user);
        done(null, user._id);
    });

    passport.deserializeUser(function(id, done) {
        mongoDbConnection(function(pdb) {
            pdb.collection("users", function(err, collection) {
                collection.findOne({
                    '_id': new ObjectId(id)
                }, function(err, user) {
                    done(err, user);
                });
            });
        });
    });

    // Setting up Passport Strategies for Login and SignUp/Registration
    login(passport);
    //signup(passport);
}


text:
import typescript from 'rollup-plugin-typescript2'
import uglify from 'rollup-plugin-uglify'
import cleanup from 'rollup-plugin-cleanup'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import html from 'rollup-plugin-html'
import scss from 'rollup-plugin-scss'

const entry = process.env.entry

export default {
  entry: `packages/${entry}.ts`,
  dest: `packages/${entry}.js`,
  format: entry === 'gaws/test' ? 'es' : 'iife',
  moduleName: 'gaws',
  // external: [ 'react' ],
  plugins: [
    html({
      include: '**/*.html',
      htmlMinifierOptions: {
				collapseWhitespace: true,
				collapseBooleanAttributes: true,
				conservativeCollapse: true,
				minifyJS: true
			}
    }),
    scss({output: false}),
    resolve({
      module: true,
      jsnext: true,
      extensions: ['.js','.jsx','.ts','.tsx','.html']
    }),
    commonjs(),
    typescript({
      // typescript: require('typescript'),
      // jsx: 'react'
    }),
    cleanup({
      comments: 'none',
      extensions: ['.js','.ts','.tsx']
    }),
    (process.env.NODE_ENV === 'production' && uglify())
  ]
}


text:
package me.huding.io.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * Created By hujianhong
 * Date: 2018/11/24
 */
public class DiscardServer {

    private int port;

    public DiscardServer(int port) {
        this.port = port;
    }

    public void run() throws InterruptedException {
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        try {
            // NIO服务辅助启动类
            ServerBootstrap b = new ServerBootstrap();
            b.group(bossGroup, workerGroup)
                    // 如何接收进来的连接
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
                            ch.pipeline().addLast(new DiscardServerHandler());
                        }
                    })
                    // 设置指定Channel实现的参数
                    // option() 是提供给NioServerSocketChannel 用来接收进来的连接
                    .option(ChannelOption.SO_BACKLOG, 128)
                    // childOption() 是提供给由父管道 ServerChannel 接收到的连接,在这个例子中也是 NioServerSocketChannel
                    .childOption(ChannelOption.SO_KEEPALIVE, true);

            ChannelFuture f = b.bind(this.port).sync();

            // 等待socket关闭,这里不会发生,
            f.channel().closeFuture().sync();

        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        int port = 7878;

        if (args != null && args.length > 0) {
            port = Integer.parseInt(args[0]);
        }
        new DiscardServer(port).run();
    }
}


text:
package com.tinkerpop.blueprints.impls.sparksee;

import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.KeyIndexableGraph;
import com.tinkerpop.blueprints.TestSuite;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.GraphTest;
import com.tinkerpop.blueprints.util.StringFactory;
import com.tinkerpop.blueprints.util.io.graphml.GraphMLReader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 */
public class SparkseeGraphSpecificTestSuite extends TestSuite {

    public SparkseeGraphSpecificTestSuite() {
    }

    public SparkseeGraphSpecificTestSuite(final GraphTest graphTest) {
        super(graphTest);
    }

    public void testSparkseeVertexLabel() throws Exception {
        Graph graph = graphTest.generateGraph();
        this.stopWatch();

        assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals(SparkseeGraph.DEFAULT_SPARKSEE_VERTEX_LABEL));
        ((SparkseeGraph) graph).label.set("people");
        assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals("people"));
        ((SparkseeGraph) graph).label.set("thing");
        assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals("thing"));
        assertTrue(graph.addVertex("whatever").getProperty(StringFactory.LABEL).equals("thing"));
        ((SparkseeGraph) graph).label.set(null);
        assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals(SparkseeGraph.DEFAULT_SPARKSEE_VERTEX_LABEL));

        ((SparkseeGraph) graph).label.set("mylabel");
        Vertex v1 = graph.addVertex("mylabel");
        boolean excep = false;
        try {
            v1.setProperty(StringFactory.LABEL, "otherlabel");
        } catch (IllegalArgumentException e) {
            excep = true;
        } finally {
            assertTrue(excep);
        }

        printPerformance(graph.toString(), null, "testSparkseeVertexLabel", this.stopWatch());
        graph.shutdown();
    }

    public void testKeyIndex() {
        KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
        this.stopWatch();

        ((SparkseeGraph) graph).label.set("people");
        graph.createKeyIndex("name", Vertex.class);

        ((SparkseeGraph) graph).label.set("thing");
        graph.createKeyIndex("name", Vertex.class);

        assertTrue(graph.getIndexedKeys(Edge.class).isEmpty());
        assertTrue(graph.getIndexedKeys(Vertex.class).size() == 1);
        assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));

        ((SparkseeGraph) graph).label.set("people");
        Vertex v1 = graph.addVertex(null);
        v1.setProperty("name", "foo");
        Vertex v2 = graph.addVertex(null);
        v2.setProperty("name", "boo");

        ((SparkseeGraph) graph).label.set("thing");
        Vertex v10 = graph.addVertex(null);
        v10.setProperty("name", "foo");
        Vertex v20 = graph.addVertex(null);
        v20.setProperty("name", "boo");

        ((SparkseeGraph) graph).label.set("people");
        assertTrue(graph.getVertices("name", "foo").iterator().next().equals(v1));
        ((SparkseeGraph) graph).label.set("thing");
        assertTrue(graph.getVertices("name", "foo").iterator().next().equals(v10));

        ArrayList<Vertex> result = new ArrayList<Vertex>(Arrays.asList(v1, v10));
        ((SparkseeGraph) graph).label.set(null); // all types!
        for (Vertex current : graph.getVertices("name", "foo")) {
            assertTrue(result.contains(current));
            result.remove(current);
        }
        assertTrue(result.size() == 0);

        result = new ArrayList<Vertex>(Arrays.asList(v1, v2));
        for (Vertex current : graph.getVertices(StringFactory.LABEL, "people")) {
            assertTrue(result.contains(current));
            result.remove(current);
        }
        assertTrue(result.size() == 0);

        // table scan
        v1.setProperty("age", 99);
        ((SparkseeGraph) graph).label.set("people");
        assertTrue(graph.getVertices("age", 99).iterator().next().equals(v1));

        printPerformance(graph.toString(), null, "testKeyIndex", this.stopWatch());
        graph.shutdown();
    }

    public void testTx() {
        TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();
        this.stopWatch();

        graph.commit();

        graph.addVertex(null).setProperty("name", "sergio");
        graph.addVertex(null).setProperty("name", "marko");
        assertTrue(graph.getVertices("name", "sergio").iterator().next()
                .getProperty("name").equals("sergio"));
        graph.commit();
        assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);

        assertTrue(graph.getVertices("name", "sergio").iterator().next().getProperty("name").equals("sergio"));
        graph.commit();
        assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);
        graph.commit();
        assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);

        graph.addVertex(null);
        graph.shutdown();
        assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);
        printPerformance(graph.toString(), null, "testTx", this.stopWatch());
        graph.shutdown();
    }

    private static class SessionThread extends Thread {
        private TransactionalGraph tg = null;
        public volatile boolean stop = false;
        public volatile boolean finished = false;
        public int counter = 0;

        public SessionThread(TransactionalGraph g) {
            tg = g;
        }

        @Override
        public void run() {
            while (!stop) {
                for (Vertex vertex : tg.getVertices()) {
                    for (Edge edge : vertex.getEdges(Direction.OUT)) {
                        counter++;
                    }
                }
            }
            tg.commit();
            finished = true;
        }
    }

    public void testMultipleSessions() throws InterruptedException, IOException {
        TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();
        this.stopWatch();

        // This test requires a multiple sessions license,
        // so just executed if a license has been given,
        // see SparkseeGraphTest#generateGraph(...) -> blueprints-sparksee.cfg

        com.sparsity.sparksee.gdb.SparkseeConfig cfg = new com.sparsity.sparksee.gdb.SparkseeConfig();
        if (cfg.getLicense() == null || cfg.getLicense().length() == 0) {
            printPerformance(graph.toString(), null, "skip because no license", this.stopWatch());
            graph.shutdown();
            return;
        }

        new GraphMLReader(graph).inputGraph(GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        printPerformance(graph.toString(), null, "load", this.stopWatch());

        List<SessionThread> threads = new ArrayList<SessionThread>();
        for (int i = 0; i < 10; i++)
            threads.add(new SessionThread(graph));
        this.stopWatch();
        for (SessionThread th : threads)
            th.start();

        Thread.sleep(5000);

        for (SessionThread th : threads)
            th.stop = true;
        int acum = 0;
        for (SessionThread th : threads) {
            while (!th.finished)
                ;
            acum += th.counter;
        }

        printPerformance(graph.toString(), acum, "tx (sessions)", this.stopWatch());
        graph.shutdown();
    }
}


text:
package co.cask.cdap.etl.common;

import co.cask.cdap.api.Resources;
import co.cask.cdap.etl.api.Transform;
import co.cask.cdap.etl.api.Transformation;
import co.cask.cdap.etl.api.batch.BatchSink;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.ipc.trace.TimestampedEvent;
import org.junit.Assert;
import org.junit.Test;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Testing the Validation of etl stage hookups.
 */
public class PipelineRegistererTest {

  @Test(expected = IllegalArgumentException.class)
  public void testSimpleInvalidMatch() throws Exception {
    // String --> Integer
    ArrayList<Type> typeList = Lists.newArrayList();
    typeList.add(String.class);
    typeList.add(Integer.class);
    PipelineRegisterer.validateTypes(typeList);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testAnotherInvalidMatch() throws Exception {
    // String --> Object | Object --> T | List<T> --> List<String>
    // List<Object> -> List<String> should fail.
    ArrayList<Type> typeList = Lists.newArrayList();
    typeList.add(String.class);
    typeList.add(Object.class);
    typeList.add(Object.class);
    typeList.addAll(getBothParameters(ParamToListParam.class));
    typeList.add(getFirstTypeParameter(StringListSink.class));
    PipelineRegisterer.validateTypes(typeList);
  }

  @Test
  public void testSimpleValidType() throws Exception {
    // Child --> Parent | Integer --> Object
    ArrayList<Type> typeList = Lists.newArrayList();
    typeList.add(TimestampedEvent.class);
    typeList.add(GenericRecord.class);
    typeList.add(Integer.class);
    typeList.add(Object.class);
    PipelineRegisterer.validateTypes(typeList);
  }

  @Test
  public void testParameterType() throws Exception {
    // String --> T | List<T> --> List<String>
    ArrayList<Type> typeList = Lists.newArrayList();
    typeList.add(String.class);
    typeList.addAll(getBothParameters(ParamToListParam.class));
    typeList.add(getFirstTypeParameter(StringListSink.class));
    PipelineRegisterer.validateTypes(typeList);
  }

  @Test
  public void testRepeatStageType() throws Exception {
    // String --> T | List<T> --> T | List<T> --> T | List<T> --> Object
    ArrayList<Type> typeList = Lists.newArrayList();
    typeList.add(String.class);
    typeList.addAll(getBothParameters(ParamToListParam.class));
    typeList.addAll(getBothParameters(ParamToListParam.class));
    typeList.addAll(getBothParameters(ParamToListParam.class));
    typeList.add(getFirstTypeParameter(NoOpSink.class));
    PipelineRegisterer.validateTypes(typeList);
  }

  @Test
  public void testGenericArrayType() throws Exception {
    // String[] --> E[] | List<E[]> --> Object
    ArrayList<Type> typeList = Lists.newArrayList();
    typeList.add(String[].class);
    typeList.addAll(getBothParameters(ArrayToListArray.class));
    typeList.add(getFirstTypeParameter(NoOpSink.class));
    PipelineRegisterer.validateTypes(typeList);
  }

  @Test
  public void testGenericParameterType() throws Exception {
    // String[] --> E[] | List<E[]> --> T | List<T> --> Object
    ArrayList<Type> typeList = Lists.newArrayList();
    typeList.add(String[].class);
    typeList.addAll(getBothParameters(ArrayToListArray.class));
    typeList.addAll(getBothParameters(ParamToListParam.class));
    typeList.add(getFirstTypeParameter(NoOpSink.class));
    PipelineRegisterer.validateTypes(typeList);
  }

  @Test
  public void testSourceParamType() throws Exception {
    // T --> N | List<N> --> M
    ArrayList<Type> typeList = Lists.newArrayList();
    typeList.add(getFirstTypeParameter(ParamToListParam.class));
    typeList.addAll(getBothParameters(ParamToListParam.class));
    typeList.add(getFirstTypeParameter(ParamToListParam.class));
    PipelineRegisterer.validateTypes(typeList);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testDuplicateStageName() throws Exception {
    ETLStage source = new ETLStage("DBSource", new Plugin("db", ImmutableMap.<String, String>of()));
    ETLStage transform1 = new ETLStage("TableValidation", new Plugin("validator", ImmutableMap.<String, String>of()));
    //duplicate transform name
    ETLStage transform2 = new ETLStage("TableValidation", new Plugin("script", ImmutableMap.<String, String>of()));
    ETLStage sink = new ETLStage("AvroSink", new Plugin("tpfsAvro", ImmutableMap.<String, String>of()));
    PipelineRegisterer.validateStageNames(source,
                                          ImmutableList.of(transform1, transform2), ImmutableList.of(sink));
  }

  @Test(expected = IllegalArgumentException.class)
  public void testCycleInConfig() throws Exception {
    ETLStage source = new ETLStage("DBSource", new Plugin("db", ImmutableMap.<String, String>of()));
    ETLStage transform1 = new ETLStage("TableValidation1", new Plugin("validator", ImmutableMap.<String, String>of()));
    //duplicate transform name
    ETLStage transform2 = new ETLStage("TableValidation2", new Plugin("script", ImmutableMap.<String, String>of()));
    ETLStage transform3 = new ETLStage("TableValidation3", new Plugin("script", ImmutableMap.<String, String>of()));
    ETLStage sink = new ETLStage("AvroSink", new Plugin("tpfsAvro", ImmutableMap.<String, String>of()));

    List<ETLStage> transforms = ImmutableList.of(transform1, transform2, transform3);
    List<Connection> connections = ImmutableList.of(new Connection("DBSource", "TableValidation1"),
                                                    new Connection("TableValidation1", "TableValidation2"),
                                                    new Connection("TableValidation1", "TableValidation3"),
                                                    // cycle connection
                                                    new Connection("TableValidation3", "TableValidation1"),
                                                    new Connection("TableValidation2", "AvroSink")
    );
    ETLConfig config = new ETLConfig(source, ImmutableList.of(sink), transforms, connections, new Resources());
    PipelineRegisterer.validateConnections(config);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testUnconnectedSinkConfig() throws Exception {
    ETLStage source = new ETLStage("DBSource", new Plugin("db", ImmutableMap.<String, String>of()));
    ETLStage transform1 = new ETLStage("TableValidation1", new Plugin("validator", ImmutableMap.<String, String>of()));
    //duplicate transform name
    ETLStage transform2 = new ETLStage("TableValidation2", new Plugin("script", ImmutableMap.<String, String>of()));
    ETLStage transform3 = new ETLStage("TableValidation3", new Plugin("script", ImmutableMap.<String, String>of()));

    ETLStage sink1 = new ETLStage("AvroSink1", new Plugin("tpfsAvro", ImmutableMap.<String, String>of()));
    ETLStage sink2 = new ETLStage("AvroSink2", new Plugin("tpfsAvro", ImmutableMap.<String, String>of()));

    List<ETLStage> transforms = ImmutableList.of(transform1, transform2, transform3);
    List<ETLStage> sinks = ImmutableList.of(sink1, sink2);

    List<Connection> connections = ImmutableList.of(new Connection("DBSource", "TableValidation1"),
                                                    new Connection("TableValidation1", "TableValidation2"),
                                                    new Connection("TableValidation1", "TableValidation3"),
                                                    new Connection("TableValidation2", "AvroSink1"),
                                                    new Connection("TableValidation3", "AvroSink1")
                                                    // sink2 is unconnected
    );
    ETLConfig config = new ETLConfig(source, sinks, transforms, connections, new Resources());
    PipelineRegisterer.validateConnections(config);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testUnconnectedTransformConfig() throws Exception {
    ETLStage source = new ETLStage("DBSource", new Plugin("db", ImmutableMap.<String, String>of()));
    ETLStage transform1 = new ETLStage("TableValidation1", new Plugin("validator", ImmutableMap.<String, String>of()));
    //duplicate transform name
    ETLStage transform2 = new ETLStage("TableValidation2", new Plugin("script", ImmutableMap.<String, String>of()));
    ETLStage transform3 = new ETLStage("TableValidation3", new Plugin("script", ImmutableMap.<String, String>of()));

    ETLStage sink1 = new ETLStage("AvroSink1", new Plugin("tpfsAvro", ImmutableMap.<String, String>of()));
    ETLStage sink2 = new ETLStage("AvroSink2", new Plugin("tpfsAvro", ImmutableMap.<String, String>of()));

    List<ETLStage> transforms = ImmutableList.of(transform1, transform2, transform3);
    List<ETLStage> sinks = ImmutableList.of(sink1, sink2);

    List<Connection> connections = ImmutableList.of(new Connection("DBSource", "TableValidation1"),
                                                    new Connection("TableValidation1", "AvroSink1"),
                                                    new Connection("TableValidation1", "AvroSink2"),
                                                    new Connection("TableValidation1", "TableValidation2"),
                                                    new Connection("TableValidation2", "TableValidation3")
                                                    // TablValidation3 is not connected to a sink
    );
    ETLConfig config = new ETLConfig(source, sinks, transforms, connections, new Resources());
    PipelineRegisterer.validateConnections(config);
  }

  @Test
  public void testTopologySorting() throws Exception {

    // linear
    Map<String, List<String>> connectionsMap = new HashMap<>();
    connectionsMap.put("source", ImmutableList.of("trA"));
    connectionsMap.put("trA", ImmutableList.of("trB"));
    connectionsMap.put("trB", ImmutableList.of("trC"));
    connectionsMap.put("trC", ImmutableList.of("sink"));

    Assert.assertEquals(ImmutableList.of("source", "trA", "trB", "trC", "sink") ,
                        PipelineRegisterer.getStagesAfterTopologicalSorting(connectionsMap, "source"));

    connectionsMap.clear();
    connectionsMap.put("sourceA", ImmutableList.of("transformB", "transformC"));
    connectionsMap.put("transformB", ImmutableList.of("transformD"));
    connectionsMap.put("transformC", ImmutableList.of("transformB", "transformD"));
    connectionsMap.put("transformD", ImmutableList.of("sinkE"));

    Assert.assertEquals(ImmutableList.of("sourceA", "transformC", "transformB", "transformD", "sinkE") ,
                        PipelineRegisterer.getStagesAfterTopologicalSorting(connectionsMap, "sourceA"));

    connectionsMap.clear();
    connectionsMap.put("sourceA", ImmutableList.of("transformB", "transformC", "transformD"));
    connectionsMap.put("transformB", ImmutableList.of("transformD", "sink1"));
    connectionsMap.put("transformC", ImmutableList.of("transformB", "transformE"));
    connectionsMap.put("transformD", ImmutableList.of("sink1"));
    connectionsMap.put("transformE", ImmutableList.of("transformB", "sink1"));

    Assert.assertEquals(ImmutableList.of("sourceA", "transformC", "transformE", "transformB", "transformD", "sink1") ,
                        PipelineRegisterer.getStagesAfterTopologicalSorting(connectionsMap, "sourceA"));
  }

  @Test(expected = IllegalArgumentException.class)
  public void testCycleInTopologySorting() throws Exception {

    // linear
    Map<String, List<String>> connectionsMap = new HashMap<>();
    connectionsMap.put("source", ImmutableList.of("trA", "trB"));
    connectionsMap.put("trA", ImmutableList.of("trB", "sink1"));
    connectionsMap.put("trB", ImmutableList.of("trC"));
    connectionsMap.put("trC", ImmutableList.of("trB", "sink2"));
    PipelineRegisterer.getStagesAfterTopologicalSorting(connectionsMap, "source");

  }

  @Test
  public void testValidSinkConfigs() throws Exception {
    ETLStage source = new ETLStage("DBSource", new Plugin("db", ImmutableMap.<String, String>of()));
    ETLStage transform1 = new ETLStage("TableValidation1", new Plugin("validator", ImmutableMap.<String, String>of()));
    //duplicate transform name
    ETLStage transform2 = new ETLStage("TableValidation2", new Plugin("script", ImmutableMap.<String, String>of()));
    ETLStage transform3 = new ETLStage("TableValidation3", new Plugin("script", ImmutableMap.<String, String>of()));
    ETLStage transform4 = new ETLStage("TableValidation4", new Plugin("script", ImmutableMap.<String, String>of()));
    ETLStage sink1 = new ETLStage("AvroSink1", new Plugin("tpfsAvro", ImmutableMap.<String, String>of()));
    ETLStage sink2 = new ETLStage("AvroSink2", new Plugin("tpfsAvro", ImmutableMap.<String, String>of()));

    List<ETLStage> transforms = ImmutableList.of(transform1, transform2, transform3, transform4);
    List<ETLStage> sinks = ImmutableList.of(sink1, sink2);

    List<Connection> connections = ImmutableList.of(new Connection("DBSource", "TableValidation1"),
                                                    new Connection("TableValidation1", "TableValidation2"),
                                                    new Connection("TableValidation1", "TableValidation3"),
                                                    new Connection("TableValidation2", "AvroSink1"),
                                                    new Connection("TableValidation3", "AvroSink1"),
                                                    new Connection("TableValidation3", "AvroSink2")
    );
    ETLConfig config = new ETLConfig(source, sinks, transforms, connections, new Resources());
    PipelineRegisterer.validateConnections(config);
    // test without any connections, the default should be used.
    config = new ETLConfig(source, sinks, transforms, new ArrayList<Connection>(), new Resources());
    PipelineRegisterer.validateConnections(config);

    // test with complex connections
    connections = ImmutableList.of(new Connection("DBSource", "TableValidation1"),
                                   new Connection("DBSource", "TableValidation2"),
                                   new Connection("TableValidation1", "TableValidation3"),
                                   new Connection("TableValidation2", "TableValidation1"),
                                   new Connection("TableValidation2", "TableValidation4"),
                                   new Connection("TableValidation4", "TableValidation3"),
                                   new Connection("TableValidation3", "AvroSink1"),
                                   new Connection("TableValidation4", "AvroSink1"),
                                   new Connection("TableValidation4", "AvroSink2")
    );
    config = new ETLConfig(source, sinks, transforms, connections, new Resources());
    PipelineRegisterer.validateConnections(config);

    // simple source to sink connections, no transforms and no connections
    config = new ETLConfig(source, sinks, new ArrayList<ETLStage>(), new ArrayList<Connection>(), new Resources());
    PipelineRegisterer.validateConnections(config);
  }

  private static List<Type> getBothParameters(Class klass) {
    return Lists.newArrayList(getFirstTypeParameter(klass), getSecondTypeParameter(klass));
  }

  private static Type getTypeParameter(Class klass, int index) {
    return TypeToken.of(klass).resolveType(Transformation.class.getTypeParameters()[index]).getType();
  }

  private static Type getFirstTypeParameter(Class klass) {
    return getTypeParameter(klass, 0);
  }

  private static Type getSecondTypeParameter(Class klass) {
    return getTypeParameter(klass, 1);
  }

  private abstract static class ParamToListParam<T> extends Transform<T, List<T>> {

  }

  private abstract static class ArrayToListArray<E> extends Transform<E[], List<E[]>> {

  }

  private abstract static class StringListSink<A, B> extends BatchSink<List<String>, A, B> {

  }

  private abstract static class NoOpSink<X, Y> extends BatchSink<Object, X, Y> {

  }
}


text: Experiments with yum inside docker containers.


text:
package com.unidev.proxymanager.data;

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ProxyHistoryRepository extends ElasticsearchRepository<ProxyHistory, Long> {
}


text:
using System.Collections.ObjectModel;
using Noside.Wyvern.Weather.Models;

namespace Noside.Wyvern.Weather.Interfaces
{
	internal interface IWeatherViewModel
	{
		string CityName { get; set; }
		string Icon { get; set; }
		double Tempature { get; set; }
		ObservableCollection<Forecast> FourDay { get; set; }
	}
}


text:
package org.seasar.doma.internal.apt.domain;

import org.seasar.doma.Domain;
import org.seasar.doma.internal.apt.lombok.Value;

/**
 * @author nakamura-to
 *
 */
@Domain(valueType = String.class)
@Value
public class LombokValueNoField {

}


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>Using as: MSP430 Syntax</title>

<meta name="description" content="Using as: MSP430 Syntax">
<meta name="keywords" content="Using as: MSP430 Syntax">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="MSP430_002dDependent.html#MSP430_002dDependent" rel="up" title="MSP430-Dependent">
<link href="MSP430_002dMacros.html#MSP430_002dMacros" rel="next" title="MSP430-Macros">
<link href="MSP430-Options.html#MSP430-Options" rel="prev" title="MSP430 Options">

Next: MSP430 Floating Point, Previous: MSP430 Options, Up: MSP430-Dependent   [Contents][Index]

9.29.2 Syntax

• MSP430-Macros:	  	Macros

• MSP430-Chars:	  	Special Characters

• MSP430-Regs:	  	Register Names

• MSP430-Ext:	  	Assembler Extensions


text:
package edu.uci.ics.hyracks.algebricks.rewriter.rules;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.mutable.Mutable;
import org.apache.commons.lang3.mutable.MutableObject;

import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.common.utils.ListSet;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil;
import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;

/**
 * This rule pushes an array of subplans on top of a group-by into the
 * nested plan of the group-by.
 *
 * @author yingyib
 */

public class PushSubplanIntoGroupByRule implements IAlgebraicRewriteRule {
    /** Stores used variables above the current operator. */
    private final Set<LogicalVariable> usedVarsSoFar = new HashSet<LogicalVariable>();

    @Override
    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
            throws AlgebricksException {
        return false;
    }

    @Override
    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
        ILogicalOperator parentOperator = opRef.getValue();
        if (context.checkIfInDontApplySet(this, parentOperator)) {
            return false;
        }
        context.addToDontApplySet(this, parentOperator);
        VariableUtilities.getUsedVariables(parentOperator, usedVarsSoFar);
        if (parentOperator.getInputs().size() <= 0) {
            return false;
        }
        boolean changed = false;
        GroupByOperator gby = null;
        for (Mutable<ILogicalOperator> ref : parentOperator.getInputs()) {
            AbstractLogicalOperator op = (AbstractLogicalOperator) ref.getValue();
            /** Only processes subplan operator. */
            List<SubplanOperator> subplans = new ArrayList<SubplanOperator>();
            if (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
                while (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
                    SubplanOperator currentSubplan = (SubplanOperator) op;
                    subplans.add(currentSubplan);
                    op = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
                }
                /** Only processes the case a group-by operator is the input of the subplan operators. */
                if (op.getOperatorTag() == LogicalOperatorTag.GROUP) {
                    gby = (GroupByOperator) op;
                    List<ILogicalPlan> newGbyNestedPlans = new ArrayList<ILogicalPlan>();
                    for (SubplanOperator subplan : subplans) {
                        List<ILogicalPlan> subplanNestedPlans = subplan.getNestedPlans();
                        List<ILogicalPlan> gbyNestedPlans = gby.getNestedPlans();
                        List<ILogicalPlan> subplanNestedPlansToRemove = new ArrayList<ILogicalPlan>();
                        for (ILogicalPlan subplanNestedPlan : subplanNestedPlans) {
                            List<Mutable<ILogicalOperator>> rootOpRefs = subplanNestedPlan.getRoots();
                            List<Mutable<ILogicalOperator>> rootOpRefsToRemove = new ArrayList<Mutable<ILogicalOperator>>();
                            for (Mutable<ILogicalOperator> rootOpRef : rootOpRefs) {
                                /** Gets free variables in the root operator of a nested plan and its descent. */
                                Set<LogicalVariable> freeVars = new ListSet<LogicalVariable>();
                                VariableUtilities.getUsedVariablesInDescendantsAndSelf(rootOpRef.getValue(), freeVars);
                                Set<LogicalVariable> producedVars = new ListSet<LogicalVariable>();
                                VariableUtilities.getProducedVariablesInDescendantsAndSelf(rootOpRef.getValue(),
                                        producedVars);
                                freeVars.removeAll(producedVars);
                                /** * Checks whether the above freeVars are all contained in live variables * of one nested plan inside the group-by operator. * If yes, then the subplan can be pushed into the nested plan of the group-by. */
                                for (ILogicalPlan gbyNestedPlanOriginal : gbyNestedPlans) {
                                    // add a subplan in the original gby
                                    if (!newGbyNestedPlans.contains(gbyNestedPlanOriginal)) {
                                        newGbyNestedPlans.add(gbyNestedPlanOriginal);
                                    }

                                    // add a pushed subplan
                                    ILogicalPlan gbyNestedPlan = OperatorManipulationUtil.deepCopy(
                                            gbyNestedPlanOriginal, context);
                                    List<Mutable<ILogicalOperator>> gbyRootOpRefs = gbyNestedPlan.getRoots();
                                    for (int rootIndex = 0; rootIndex < gbyRootOpRefs.size(); rootIndex++) {
                                        //set the nts for a original subplan
                                        Mutable<ILogicalOperator> originalGbyRootOpRef = gbyNestedPlanOriginal
                                                .getRoots().get(rootIndex);
                                        Mutable<ILogicalOperator> originalGbyNtsRef = downToNts(originalGbyRootOpRef);
                                        NestedTupleSourceOperator originalNts = (NestedTupleSourceOperator) originalGbyNtsRef
                                                .getValue();
                                        originalNts.setDataSourceReference(new MutableObject<ILogicalOperator>(gby));

                                        //push a new subplan if possible
                                        Mutable<ILogicalOperator> gbyRootOpRef = gbyRootOpRefs.get(rootIndex);
                                        Set<LogicalVariable> liveVars = new ListSet<LogicalVariable>();
                                        VariableUtilities.getLiveVariables(gbyRootOpRef.getValue(), liveVars);
                                        if (liveVars.containsAll(freeVars)) {
                                            /** Does the actual push. */
                                            Mutable<ILogicalOperator> ntsRef = downToNts(rootOpRef);
                                            ntsRef.setValue(gbyRootOpRef.getValue());
                                            // Removes unused vars.
                                            AggregateOperator aggOp = (AggregateOperator) gbyRootOpRef.getValue();
                                            for (int varIndex = aggOp.getVariables().size() - 1; varIndex >= 0; varIndex--) {
                                                if (!freeVars.contains(aggOp.getVariables().get(varIndex))) {
                                                    aggOp.getVariables().remove(varIndex);
                                                    aggOp.getExpressions().remove(varIndex);
                                                }
                                            }

                                            gbyRootOpRef.setValue(rootOpRef.getValue());
                                            rootOpRefsToRemove.add(rootOpRef);

                                            // Sets the nts for a new pushed plan.
                                            Mutable<ILogicalOperator> oldGbyNtsRef = downToNts(gbyRootOpRef);
                                            NestedTupleSourceOperator nts = (NestedTupleSourceOperator) oldGbyNtsRef
                                                    .getValue();
                                            nts.setDataSourceReference(new MutableObject<ILogicalOperator>(gby));

                                            newGbyNestedPlans.add(gbyNestedPlan);
                                            changed = true;
                                            continue;
                                        }
                                    }
                                }
                            }
                            rootOpRefs.removeAll(rootOpRefsToRemove);
                            if (rootOpRefs.size() == 0) {
                                subplanNestedPlansToRemove.add(subplanNestedPlan);
                            }
                        }
                        subplanNestedPlans.removeAll(subplanNestedPlansToRemove);
                    }
                    if (changed) {
                        ref.setValue(gby);
                        gby.getNestedPlans().clear();
                        gby.getNestedPlans().addAll(newGbyNestedPlans);
                    }
                }
            }
        }
        if (changed) {
            cleanup(gby);
        }
        return changed;
    }

    /**
     * Removes unused aggregation variables (and expressions)
     *
     * @param gby
     * @throws AlgebricksException
     */
    private void cleanup(GroupByOperator gby) throws AlgebricksException {
        for (ILogicalPlan nestedPlan : gby.getNestedPlans()) {
            for (Mutable<ILogicalOperator> rootRef : nestedPlan.getRoots()) {
                AggregateOperator aggOp = (AggregateOperator) rootRef.getValue();
                for (int varIndex = aggOp.getVariables().size() - 1; varIndex >= 0; varIndex--) {
                    if (!usedVarsSoFar.contains(aggOp.getVariables().get(varIndex))) {
                        aggOp.getVariables().remove(varIndex);
                        aggOp.getExpressions().remove(varIndex);
                    }
                }
            }

        }
    }

    private Mutable<ILogicalOperator> downToNts(Mutable<ILogicalOperator> opRef) {
        Mutable<ILogicalOperator> currentOpRef = opRef;
        while (currentOpRef.getValue().getInputs().size() > 0) {
            currentOpRef = currentOpRef.getValue().getInputs().get(0);
        }
        return currentOpRef;
    }

}


text:
<?php

namespace Thumbtack\Crankshaft;

/**
 * Internal: An iterator that implements map_keys().
 */
class KeyMappingIterator extends \IteratorIterator {
    private $map_fn;

    public function __construct($traversable, callable $map_fn) {
        parent::__construct($traversable);
        $this->map_fn = $map_fn;
    }

    public function key() {
        $iterator = $this->getInnerIterator();
        return call_user_func($this->map_fn, $iterator->key(), $iterator->current());
    }
}


text:
package my.bhooshan.cdap;

import co.cask.cdap.test.TestBase;
import co.cask.cdap.test.TestConfiguration;
import com.google.gson.Gson;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Job;
import org.junit.ClassRule;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.net.URI;

/**
 * Test for {@link WordCountWithStopwords}.
 */
public class WordCountWithStopwordsTest {

  @Test
  public void test() throws IOException {
    URI uri = URI.create("file:///path/to/file.txt");
    System.out.println(uri.getPath());
    Job job = Job.getInstance();
    job.addCacheArchive(
      URI.create("file:///Users/bhooshanmogal/Documents/tmpcdap/cdap/cdap-examples/Purchase/" +
                   "target/Purchase-3.3.0-SNAPSHOT.jar#Purchase.jar"));
    job.addCacheFile(
      URI.create("file:///Users/bhooshanmogal/Documents/tmpcdap/cdap/cdap-examples/Purchase/" +
                   "resources/purchases.txt#purchases.txt")
    );

    for (URI archive : job.getCacheArchives()) {
      System.out.println("archive = " + archive);
    }

    for (URI file : job.getCacheFiles()) {
      System.out.println("file = " + file);
    }

    Configuration conf = new Configuration();
    DistributedCache.addCacheArchive(
      URI.create("file:///Users/bhooshanmogal/Documents/tmpcdap/cdap/cdap-examples/Purchase/" +
                   "target/Purchase-3.3.0-SNAPSHOT.jar#Purchase.jar"),
      conf);

    for (URI path : DistributedCache.getCacheArchives(conf)) {
      System.out.println("path = " + path);
    }

    DistributedCache.addCacheFile(
      URI.create("file:///Users/bhooshanmogal/Documents/tmpcdap/cdap/cdap-examples/Purchase/" +
                   "resources/purchases.txt#purchases.txt"),
      conf
    );
    for (URI file : DistributedCache.getCacheFiles(conf)) {
      System.out.println("file = " + file);
    }

    File file = new File("/Users/bhooshanmogal/work/git/cdap/pom.xml");
    Gson gson = new Gson();
    String string = gson.toJson(file);
    System.out.println("######File = " + string);
    File file1 = gson.fromJson(string, File.class);
  }

}


text:
local path = (...):match("(.-)[^%.]+$")
local color_conversion = require(path .. "color")
local utils = require(path .. "utils")
local calc = require(path .. "calc")

---------------------------------------------------------
-- Image functions
---------------------------------------------------------
local function create_image(width, height, func, options)
	local options = options or {}

	local image = love.image.newImageData(width, height)
	image:mapPixel(function(x, y) return func(x, y, width, height, options) end)
	return love.graphics.newImage(image)
end

local image_functions = {}

image_functions.hsv_colorspace = function(x, y, width, height)
	return color_conversion.hsv2rgb(x/width, 1, 1 - y/height)
end

image_functions._gradient = function(x, y, width, height, options)
	assert(options.from, "Color table is nil!")

	local start = options.from or false
	local ending = options.to or from
	start[4] = start[4] or 255
	ending[4] = ending[4] or 255

	local i = 1-x/width
	local r = calc.interpolate(i, ending[1], start[1])
	local g = calc.interpolate(i, ending[2], start[2])
	local b = calc.interpolate(i, ending[3], start[3])
	local a = calc.interpolate(i, ending[4], start[4])

	return r, g, b, a
end

image_functions.gradient = function(x, y, width, height, options)
	assert(options.colors, "Color table is nil!")

	local tbl = utils.sort_by_value(options.colors, "position")
	local smoothness = 0
	if options.smoothness then
		smoothness = 1 - options.smoothness
	end
	smoothness = calc.transition.ease_in(smoothness, 6, 1, 500)

	local theta = options.rotate or 0
	local scale = options.scale or 1
	local pos

	if options.type == "radial" then
		local center = calc.center_of_line({x=0, y=0}, {x=width, y=height})
		pos = calc.distance_from_point({x=x, y=y}, center) / calc.magnitude(center.x, center.y)*math.abs(2 - scale/2)
	elseif options.type == "reflected" then
		local center = calc.center_of_line({x=0, y=0}, {x=width, y=height})
		local origin = calc.rotate_point({x=0, y=0}, center, theta + math.pi/2)
		local ending = calc.rotate_point({x=width, y=0}, center, theta + math.pi/2)
		local line_distance = calc.distance_from_line({x=x, y=y}, origin, ending)*2
		pos = math.abs(width + line_distance) / width

		if line_distance < -width*2 or line_distance > 0 then
			return unpack(tbl[#tbl].color)
		end
	elseif theta ~= 0 or options.type == "linear" then
		local center = calc.center_of_line({x=0, y=0}, {x=width, y=height})
		local origin = calc.rotate_point({x=0, y=0}, center, -theta - math.pi/2)
		local ending = calc.rotate_point({x=width, y=0}, center, -theta - math.pi/2)
		local line_distance = calc.distance_from_line({x=x, y=y}, origin, ending)
		pos = math.abs(line_distance) / calc.magnitude(math.max(width, height), 0)

		if pos > 1 then
			return unpack(tbl[#tbl].color)
		elseif line_distance > 0 then
			return unpack(tbl[1].color)
		end
	else
		pos = x / width
	end

	for index, from in ipairs(tbl) do
		local to = tbl[index+1] or {}

		if pos <= (to.position or 1) and pos >= from.position then
			local length = ((to.position or 1) - from.position)
			local i = pos - from.position
			i = calc.transition.ease_in_out(i / length, smoothness, 0, length)

			return image_functions._gradient(i, i, length, length, {
				from = from.color,
				to  = to.color or from.color,
				direction = options.direction
			})
		end
	end
	return unpack(tbl[1].color)
end

image_functions.relief = function(x, y, width, height, options)
	local size = options.size or 0

	if size and x >= size and x < width-size and y >= size and y < height-size then
		return unpack(options.background or {0, 0, 0, 0}) -- center
	elseif x < width/2 and x < y and x < height-y then
		return 100, 100, 100, 255	-- left
	elseif x >= width/2 and width-x <= y and width-x <= height-y then
		return 255, 255, 255, 255	-- right
	elseif y < height/2 then
		return 100, 100, 100, 255	-- up
	elseif y >= height/2 then
		return 255, 255, 255, 255	-- down
	end
end

image_functions.border = function(x, y, width, height, options)
	local text_offset = options.text_offset or 0
	local text_width = options.text_width or 0

	if x > text_offset and x < text_offset+text_width and y < height-2 then
		return unpack(options.background or {0, 0, 0, 0})
	elseif (x == 1 and y > 0 and y < height-2) or (y == 1 and x > 0) or (x == width-1 and y > 0) or (y == height-1) then
		return 255, 255, 255, 255
	elseif x == 0 or y == 0 or x == width-2 or y == height-2 then
		return 150, 150, 150, 255
	else
		return unpack(options.background or {0, 0, 0, 0})
	end
end

image_functions.cursor_circle = function(x, y, width, height, options)
	local size = options.size or 0

	if math.floor(calc.magnitude(x - width/2, y - height/2) + 0.5) == size then
		return 255, 255, 255, 255
	else
		return 0, 0, 0, 0
	end
end

---------------------------------------------------------
-- Shaders
---------------------------------------------------------
local shaders = {}

shaders.hsv2rgb = [[
	vec3 hsv2rgb(float h, float s, float v) {
		return mix(vec3(1.),clamp((abs(fract(h+vec3(3.,2.,1.)/3.)*6.-3.)-1.),0.,1.),s)*v;
	}
]]

shaders.hsv_colorspace = [[
	extern float saturation;

	vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
		return vec4(hsv2rgb(texture_coords.x, saturation, 1 - texture_coords.y), 1.0);
	}
]]

shaders.hsv_slider = [[
	extern float hue;
	extern float value;

	vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
		return vec4(hsv2rgb(hue, 1 - texture_coords.y, clamp(value, 0.4, 1.)), 1.0);
	}
]]

---------------------------------------------------------
-- Return
---------------------------------------------------------
return {
	["create_image"] 	= create_image,
	["image_functions"] = image_functions,
	["shaders"] 		= shaders,
}


text:
version=$( cat version/VERSION )
branch=$( git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown' )

rm -rf release && mkdir release
cp cadvisor release/cadvisor
go get -u github.com/progrium/gh-release
gh-release create google/cadvisor ${version} ${branch} ${version}


text:
class SomervilleX2Importers

  def initialize(options = {})
    @school_scope = options["school"]
    @first_time = options["first_time"]
    @x2_file_importers = options["x2_file_importers"]
    @progress_bar = options["progress_bar"]
    @log = options["test_mode"] ? LogHelper::Redirect.instance.file : STDOUT
  end

  def sftp_client
    @client ||= SftpClient.for_x2
  end

  def self.file_importer_options
    {
      'students' => StudentsImporter,
      'assessments' => X2AssessmentImporter,
      'behavior' => BehaviorImporter,
      'educators' => EducatorsImporter,
      'attendance' => AttendanceImporter,
      'courses_sections' => CoursesSectionsImporter,
      'student_section_assignments' => StudentSectionAssignmentsImporter,
      'educator_section_assignments' => EducatorSectionAssignmentsImporter
    }
  end

  def self.file_importer_names
    self.file_importer_options.keys
  end

  def file_importer_classes
    @x2_file_importers.map do |importer_option|
      SomervilleX2Importers.file_importer_options.fetch(importer_option)
    end.compact.uniq
  end

  def file_importers
    file_importer_classes.map do |file_importer_class|
      file_importer_class.new(@school_scope, sftp_client, @log, @progress_bar)
    end
  end

end