text:
package org.fugerit.java.core.db.daogen;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.fugerit.java.core.db.dao.FieldList;
import org.fugerit.java.core.lang.helpers.StringUtils;

public class SelectHelper extends QueryHelper {

	public static final String MODE_NONE = "";

	public static final String MODE_AND = " AND ";

	public static final String MODE_OR = " OR ";

	public static final String COMPARE_EQUAL = " = ";

	public static final String COMPARE_DIFFERENT = " <> ";

	public static final String COMPARE_LT = " < ";

	public static final String COMPARE_GT = " > ";

	public static final String COMPARE_LIKE = " LIKE ";

	public static final String COMPARE_LT_EQUAL = " <= ";

	public static final String COMPARE_GT_EQUAL = " >= ";

	public static final String ORDER_ASC = "ASC";

	public static final String ORDER_DESC = "DESC";

	/**
	 *
	 */
	private static final long serialVersionUID = -4923486564445809747L;

	private boolean firstParam;

	private List<OrderByHandler> orderByList;

	public SelectHelper( String table, FieldList fl ) {
		super( table, fl );
		this.firstParam = true;
		this.orderByList = new ArrayList<OrderByHandler>();
	}

	public void initSelectEntity() {
		this.getQuery().append( "SELECT * FROM " );
		this.getQuery().append( this.getTable() );
	}

	public boolean addParam( String columnName, Object value, String mode, String compare ) {
		boolean added = (value != null);
		if ( added ) {
			if ( this.firstParam ) {
				this.firstParam = false;
				this.getQuery().append( " WHERE " );
			} else {
				this.getQuery().append( mode );
			}
			this.getQuery().append( columnName );
			this.getQuery().append( compare );
			this.getQuery().append( QUESTION_MARK );
			this.getFields().addField( value );
		}
		return added;
	}

	public boolean orEqualParam( String columnName, Object value ) {
		return this.addParam( columnName , value, MODE_OR, COMPARE_EQUAL );
	}

	public boolean orLikeParam( String columnName, Object value ) {
		return this.addParam( columnName , value, MODE_OR, COMPARE_LIKE );
	}

	public boolean andEqualParam( String columnName, Object value ) {
		return this.addParam( columnName , value, MODE_AND, COMPARE_EQUAL );
	}

	public boolean andLikeParam( String columnName, Object value ) {
		return this.addParam( columnName , value, MODE_AND, COMPARE_LIKE );
	}

	public void addOrderBy( String columnName, String orderByMode ) {
		this.orderByList.add( new OrderByHandler(columnName, orderByMode) );
	}

	public void addOrderBy( String orderBy ) {
		if ( StringUtils.isNotEmpty( orderBy ) ) {
			this.appendToQuery( " ORDER BY " );
			this.appendToQuery( orderBy );
			this.appendToQuery( " " );
		}
	}

	@Override
	public String getQueryContent() {
		StringBuilder query = new StringBuilder();
		query.append( super.getQueryContent() );
		if ( !this.orderByList.isEmpty() ) {
			query.append( " ORDER BY " );
			boolean firstOderBy = true;
			Iterator<OrderByHandler> itOrderBy = this.orderByList.iterator();
			while ( itOrderBy.hasNext() ) {
				OrderByHandler current = itOrderBy.next();
				query.append( current.getColumnName() );
				query.append( " " );
				query.append( current.getOrderByMode() );
				query.append( " " );
				if ( firstOderBy ) {
					firstOderBy = false;
				} else {
					query.append( ", " );
				}
			}
		}
		return query.toString();
	}

}

class OrderByHandler {

	private String columnName;

	private String orderByMode;

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public String getOrderByMode() {
		return orderByMode;
	}

	public void setOrderByMode(String orderByMode) {
		this.orderByMode = orderByMode;
	}

	public OrderByHandler(String columnName, String orderByMode) {
		super();
		this.columnName = columnName;
		this.orderByMode = orderByMode;
	}

}


text:
    <title>Git Look Up</title>

Git Look Up

    Enter a search term <input type="text" data-bind="value: searchTerm" />.

    <button data-bind="click: search">Search</button>

redpajama_set_name: RedPajamaGithub


text:
package camelinaction;

import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * The Spring based example of {@link SplitterBeanTest}.
 * See this class for more details.
 */
public class SpringSplitterBeanTest extends CamelSpringTestSupport {

    @Override
    protected AbstractXmlApplicationContext createApplicationContext() {
        return new ClassPathXmlApplicationContext("META-INF/spring/splitter-bean.xml");
    }

    @Test
    public void testSplitBean() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:split");
        mock.expectedMessageCount(3);

        Customer customer = CustomerService.createCustomer();

        template.sendBody("direct:start", customer);

        assertMockEndpointsSatisfied();
    }

}


text:
interface Job {
  _id?: string;
  name: string;
  description?: string;
  location: string;
  owner?: string;
}


text:
@implementation SPLoginMobileModel

@end


text:
using System.Collections.Generic;
using System.Linq;
using MoreTraps.Helpers;
using RimWorld;
using UnityEngine;
using Verse;

namespace MoreTraps.Things.Building.Security
{
    /// <summary>
    ///     Trap: An arrow trap.
    /// </summary>
    public class Building_ArrowTrap : Building_TrapRearmable
    {
        /// <summary>
        ///     The damage variation
        /// </summary>
        protected const float DamageVariation = 5f;

        /// <summary>
        ///     The maximum trigger count
        /// </summary>
        protected const int MaxTriggerCount = 5;

        /// <summary>
        ///     The number of cells the trap can be triggered by.
        /// </summary>
        protected const int TrapTriggerSize = 5;

        /// <summary>
        ///     The tick count
        /// </summary>
        private static int tickCount;

        private float _baseDamageStat;
        private FloatRange _damageRange;
        private List<Building_TrapTrigger> _trapTriggers = new List<Building_TrapTrigger>();
        private List<IntVec3> _trapTriggerCells = new List<IntVec3>();

        /// <summary>
        ///     Initializes a new instance of the <see cref="Building_ArrowTrap" /> class.
        /// </summary>
        public Building_ArrowTrap()
        {
            OnAfterRearmAction += OnAfterRearm;
        }

        /// <summary>
        ///     Gets or sets the damage range.
        /// </summary>
        /// <value>
        ///     The damage range.
        /// </value>
        protected FloatRange DamageRange => _damageRange;

        /// <summary>
        ///     Gets or sets the trigger count.
        /// </summary>
        /// <value>
        ///     The trigger count.
        /// </value>
        protected int TriggerCount { get; set; }

        /// <summary>
        ///     Calculates the trigger cells.
        /// </summary>
        /// <param name="center">The center.</param>
        /// <param name="rotation">The rotation.</param>
        /// <returns></returns>
        public static IEnumerable<IntVec3> CalculateTriggerCells(IntVec3 center, Rot4 rotation)
        {
            // Include cells for length of trigger zone in rotated direction.
            for (var i = 1; i <= TrapTriggerSize; i++)
            {
                var cell = (center + (IntVec3.North.RotatedBy(rotation)*i));

                if (cell.Impassable())
                    break;

                yield return cell;
            }
        }

        /// <summary>
        ///     Destroys the specified mode.
        /// </summary>
        /// <param name="mode">The mode.</param>
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            // Destroy triggers.
            for (var i = 0; i < _trapTriggers.Count; i++)
            {
                var trapTrigger = _trapTriggers[i];

                if (trapTrigger.Destroyed == false)
                {
                    trapTrigger.Destroy(mode);
                }

                _trapTriggers.Remove(trapTrigger);
            }

            base.Destroy(mode);
        }

        /// <summary>
        ///     Exposes the data.
        /// </summary>
        public override void ExposeData()
        {
            base.ExposeData();

            Scribe_Values.LookValue(ref _baseDamageStat, "_baseDamageStat", 0f);
            Scribe_Values.LookValue(ref _damageRange, "_damageRange", new FloatRange(0f, 0f));
            Scribe_Collections.LookList(ref _trapTriggers, "_trapTriggers", LookMode.MapReference);
        }

        /// <summary>
        ///     Spawns the setup.
        /// </summary>
        public override void SpawnSetup()
        {
            base.SpawnSetup();

            if (_trapTriggerCells == null || _trapTriggerCells.Count == 0)
            {
                _trapTriggerCells = CalculateTriggerCells(Position, Rotation).ToList();

                // Spawn triggers to handle pathing.
                SpawnTrapTriggers();
            }

            // Get base trap damage.
            _baseDamageStat = this.GetStatValue(StatDefOf.TrapMeleeDamage);

            // Get base damage range.
            _damageRange = new FloatRange(_baseDamageStat - DamageVariation, _baseDamageStat + DamageVariation);
        }

        /// <summary>
        ///     Gets the pawns to test.
        /// </summary>
        /// <returns></returns>
        protected override List<Pawn> GetPawnsToTest()
        {
            return _trapTriggerCells.SelectMany(trapTriggerCell => trapTriggerCell.GetThingList().OfType<Pawn>().Where(pawn => !testees.Contains(pawn))).Distinct().ToList();
        }

        /// <summary>
        ///     Gets the trap trigger cells.
        /// </summary>
        /// <returns></returns>
        protected override List<IntVec3> GetTrapTriggerCells()
        {
            return _trapTriggerCells;
        }

        /// <summary>
        ///     Damages the pawn.
        /// </summary>
        /// <param name="pawn">The pawn.</param>
        protected override void InteractWithPawn(Pawn pawn)
        {
            if (TriggerCount >= MaxTriggerCount)
                return;

            TriggerCount++;

            pawn.TakeDamage(new DamageInfo(TrapDef.TrapDamageDef, Mathf.CeilToInt(_damageRange.RandomInRange), this));
        }

        /// <summary>
        ///     Determine whether the trap should disarm itself.
        /// </summary>
        /// <returns></returns>
        protected override bool ShouldDisarm()
        {
            return (TriggerCount >= MaxTriggerCount);
        }

        /// <summary>
        ///     Determine whether the trap should rearm itself.
        /// </summary>
        /// <returns></returns>
        protected override bool ShouldRearm()
        {
            return (TriggerCount >= MaxTriggerCount);
        }

        /// <summary>
        ///     Ticks the trap.
        /// </summary>
        protected override void TickTrap(int ticks)
        {
            base.TickTrap(ticks);

            tickCount -= ticks;
            if (tickCount >= 0)
            {
                return;
            }
            tickCount = 250;

            // Update trigger cells.
            _trapTriggerCells = CalculateTriggerCells(Position, Rotation).ToList();

            // Spawn triggers to handle pathing.
            SpawnTrapTriggers();
        }

        /// <summary>
        ///     Called when after trap is rearmed.
        /// </summary>
        private void OnAfterRearm()
        {
            TriggerCount = 0;
        }

        /// <summary>
        ///     Spawns the trap triggers.
        /// </summary>
        private void SpawnTrapTriggers()
        {
            // Remove existing triggers.
            for (var i = 0; i < _trapTriggers.Count; i++)
            {
                var trapTrigger = _trapTriggers[i];

                if (trapTrigger.Destroyed == false)
                {
                    trapTrigger.Destroy();
                }

                _trapTriggers.Remove(trapTrigger);
            }

            // Spawn new triggers.
            foreach (var trapTrigger in _trapTriggerCells.Select(TrapHelpers.SpawnTrapTrigger))
            {
                trapTrigger.TrapBuilding = this;

                _trapTriggers.Add(trapTrigger);
            }
        }
    }
}


text:
export interface Address {
    line1: string;
    line2?: string;
    line3?: string;

    postal_code?: string;
    city: string;
    country_subdivision?: string;
    country: string;
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;

namespace Aras.Model
{
    public class Session
    {
        public Database Database { get; private set; }

        public Boolean OptimiseAML { get; set; }

        public IO.Session IO { get; private set; }

        public String ID
        {
            get
            {
                return this.IO.UserID;
            }
        }

        private readonly object _cacheDirectoryLock = new object();
        private DirectoryInfo _cacheDirectory;
        internal DirectoryInfo CacheDirectory
        {
            get
            {
                lock (this._cacheDirectory)
                {
                    if (this._cacheDirectory == null)
                    {
                        this._cacheDirectory = new DirectoryInfo(Path.GetTempPath() + "\\Aras\\Session\\Cache\\" + this.ID);

                        if (!this._cacheDirectory.Exists)
                        {
                            this._cacheDirectory.Create();
                        }
                    }

                    return this._cacheDirectory;
                }
            }
        }

        public Transaction BeginTransaction()
        {
            return new Transaction(this);
        }

        private Dictionary<String, ItemType> ItemTypeNameCache;
        private Dictionary<String, ItemType> ItemTypeIDCache;

        public ItemType ItemType(String Name)
        {
            if (this.ItemTypeNameCache.ContainsKey(Name))
            {
                return this.ItemTypeNameCache[Name];
            }
            else
            {
                throw new Exceptions.ArgumentException("Invalid ItemType Name: " + Name);
            }
        }

        public ItemType ItemTypeByID(String ID)
        {
            if (this.ItemTypeIDCache.ContainsKey(ID))
            {
                return this.ItemTypeIDCache[ID];
            }
            else
            {
                throw new Exceptions.ArgumentException("Invalid ItemType ID: " + ID);
            }
        }

        private readonly object ItemTypeCacheLock = new object();
        private void BuildCaches()
        {
            lock (this.ItemTypeCacheLock)
            {
                this.ItemTypeNameCache = new Dictionary<String, ItemType>();
                this.ItemTypeIDCache = new Dictionary<String, ItemType>();

                // Build ItemType Cache
                IO.Request itemtyperequest = this.IO.Request(Aras.IO.Request.Operations.ApplyItem);
                IO.Item itemtypequery = itemtyperequest.NewItem("ItemType", "get");
                itemtypequery.Select = "id,name,is_relationship,class_structure,label,label_plural";

                IO.Item lifecyclemapquery = itemtyperequest.NewItem("ItemType Life Cycle", "get");
                lifecyclemapquery.Select = "class_path,related_id";
                itemtypequery.AddRelationship(lifecyclemapquery);

                IO.Response itemtyperesponse = itemtyperequest.Execute();

                if (!itemtyperesponse.IsError)
                {
                    foreach (IO.Item dbitem in itemtyperesponse.Items)
                    {
                        ItemType itemtype = null;

                        if (dbitem.GetProperty("is_relationship").Equals("1"))
                        {
                            itemtype = new RelationshipType(this, dbitem.ID, dbitem.GetProperty("name"), dbitem.GetProperty("label"), dbitem.GetProperty("label_plural"), dbitem.GetProperty("class_structure"));
                        }
                        else
                        {
                            itemtype = new ItemType(this, dbitem.ID, dbitem.GetProperty("name"), dbitem.GetProperty("label"), dbitem.GetProperty("label_plural"), dbitem.GetProperty("class_structure"));
                        }

                        this.ItemTypeIDCache[itemtype.ID] = itemtype;
                        this.ItemTypeNameCache[itemtype.Name] = itemtype;

                        foreach (IO.Item itemtypelifecyclemap in dbitem.Relationships)
                        {
                            itemtype.AddLifeCycleMap(itemtypelifecyclemap.GetProperty("class_path"), itemtypelifecyclemap.GetPropertyItem("related_id").ID);
                        }
                    }
                }
                else
                {
                    throw new Exceptions.ServerException(itemtyperesponse);
                }

                // Build RelationshipType Cache
                IO.Request relationshiptyperequest = this.IO.Request(Aras.IO.Request.Operations.ApplyItem);
                IO.Item relationshiptypequery = relationshiptyperequest.NewItem("RelationshipType", "get");
                relationshiptypequery.Select = "relationship_id,source_id(id),related_id(id),grid_view";
                IO.Response relationshiptyperesponse = relationshiptyperequest.Execute();

                if (!relationshiptyperesponse.IsError)
                {
                    foreach (IO.Item dbitem in relationshiptyperesponse.Items)
                    {
                        RelationshipType relationshiptype = (RelationshipType)this.ItemTypeIDCache[dbitem.GetProperty("relationship_id")];

                        String source_id = dbitem.GetProperty("source_id");

                        if (!String.IsNullOrEmpty(source_id))
                        {
                            relationshiptype.Source = this.ItemTypeIDCache[source_id];
                            relationshiptype.Source.AddRelationshipType(relationshiptype);
                        }

                        String related_id = dbitem.GetProperty("related_id");

                        if (!String.IsNullOrEmpty(related_id))
                        {
                            relationshiptype.Related = this.ItemTypeIDCache[related_id];
                        }

                        switch (dbitem.GetProperty("grid_view"))
                        {
                            case "right":
                                relationshiptype.RelationshipGridView = RelationshipGridViews.Right;
                                break;
                            case "intermix":
                                relationshiptype.RelationshipGridView = RelationshipGridViews.InterMix;
                                break;
                            default:
                                relationshiptype.RelationshipGridView = RelationshipGridViews.Left;
                                break;
                        }
                    }
                }
                else
                {
                    throw new Exceptions.ServerException(relationshiptyperesponse);
                }
            }
        }

        public Query Query(ItemType ItemType)
        {
            return new Query(ItemType);
        }

        public Query Query(String ItemType)
        {
            return this.Query(this.ItemType(ItemType));
        }

        private readonly object _lifeCycleMapsLock = new object();
        private Queries.LifeCycleMap _lifeCycleMaps;
        public Queries.LifeCycleMap LifeCycleMaps
        {
            get
            {
                lock (this._lifeCycleMapsLock)
                {
                    if (this._lifeCycleMaps == null)
                    {
                        this._lifeCycleMaps = new Queries.LifeCycleMap(this);
                    }

                    return this._lifeCycleMaps;
                }
            }
        }

        private readonly object _listsLock = new object();
        private Queries.List _lists;
        public Queries.List Lists
        {
            get
            {
                lock (this._listsLock)
                {
                    if (this._lists == null)
                    {
                        this._lists = new Queries.List(this);
                    }

                    return this._lists;
                }
            }
        }

        private readonly object _usersLock = new object();
        private Queries.User _users;
        public Queries.User Users
        {
            get
            {
                lock (this._usersLock)
                {
                    if (this._users == null)
                    {
                        this._users = new Queries.User(this);
                    }

                    return this._users;
                }
            }
        }

        private readonly object ItemCacheLock = new object();
        private Dictionary<String, Cache.Item> ItemCache;

        internal Cache.Item GetItemCache(ItemType ItemType)
        {
            lock (this.ItemCacheLock)
            {
                Cache.Item cacheitem = new Cache.Item(ItemType);
                this.ItemCache[cacheitem.ID] = cacheitem;
                return cacheitem;
            }
        }

        internal Cache.Item GetItemCache(ItemType ItemType, String ID, String ConfigID, Int32 Generation, Boolean IsCurrent)
        {
            lock (this.ItemCacheLock)
            {
                if (!this.ItemCache.ContainsKey(ID))
                {
                    this.ItemCache[ID] = new Cache.Item(ItemType, ID, ConfigID, Generation, IsCurrent);
                }

                return this.ItemCache[ID];
            }
        }

        internal Session(Database Database, IO.Session IO)
        {
            this.ItemCache = new Dictionary<String, Cache.Item>();
            this.OptimiseAML = true;
            this.Database = Database;
            this.IO = IO;
            this.BuildCaches();
        }
    }
}


text:
from msrest.serialization import Model

class WindowsConfiguration(Model):
    """Describes Windows Configuration of the OS Profile.

    :param provision_vm_agent: Indicates whether the virtual machine agent
     should be provisioned on the Virtual Machine. If not specified, then the
     default behavior is to set it to true.
    :type provision_vm_agent: bool
    :param enable_automatic_updates: Indicates whether Windows updates are
     automatically installed on the VM.
    :type enable_automatic_updates: bool
    :param time_zone: The time zone of the VM
    :type time_zone: str
    :param additional_unattend_content: Additional base-64 encoded XML
     formatted information that can be included in the Unattend.xml file.
    :type additional_unattend_content: list of
     :class:`AdditionalUnattendContent
     <azure.mgmt.compute.compute.v2017_03_30.models.AdditionalUnattendContent>`
    :param win_rm: The Windows Remote Management configuration of the VM
    :type win_rm: :class:`WinRMConfiguration
     <azure.mgmt.compute.compute.v2017_03_30.models.WinRMConfiguration>`
    """

    _attribute_map = {
        'provision_vm_agent': {'key': 'provisionVMAgent', 'type': 'bool'},
        'enable_automatic_updates': {'key': 'enableAutomaticUpdates', 'type': 'bool'},
        'time_zone': {'key': 'timeZone', 'type': 'str'},
        'additional_unattend_content': {'key': 'additionalUnattendContent', 'type': '[AdditionalUnattendContent]'},
        'win_rm': {'key': 'winRM', 'type': 'WinRMConfiguration'},
    }

    def __init__(self, provision_vm_agent=None, enable_automatic_updates=None, time_zone=None, additional_unattend_content=None, win_rm=None):
        self.provision_vm_agent = provision_vm_agent
        self.enable_automatic_updates = enable_automatic_updates
        self.time_zone = time_zone
        self.additional_unattend_content = additional_unattend_content
        self.win_rm = win_rm


text:
"""

"""

from . import util as orm_util
from .attributes import QueryableAttribute
from .base import _class_to_mapper
from .base import _is_aliased_class
from .base import _is_mapped_class
from .base import InspectionAttr
from .interfaces import MapperOption
from .interfaces import PropComparator
from .path_registry import _DEFAULT_TOKEN
from .path_registry import _WILDCARD_TOKEN
from .path_registry import PathRegistry
from .path_registry import TokenRegistry
from .util import _orm_full_deannotate
from .. import exc as sa_exc
from .. import inspect
from .. import util
from ..sql import coercions
from ..sql import roles
from ..sql.base import _generative
from ..sql.base import Generative

class Load(Generative, MapperOption):
    """Represents loader options which modify the state of a
    :class:`.Query` in order to affect how various mapped attributes are
    loaded.

    The :class:`.Load` object is in most cases used implicitly behind the
    scenes when one makes use of a query option like :func:`.joinedload`,
    :func:`.defer`, or similar.   However, the :class:`.Load` object
    can also be used directly, and in some cases can be useful.

    To use :class:`.Load` directly, instantiate it with the target mapped
    class as the argument.   This style of usage is
    useful when dealing with a :class:`.Query` that has multiple entities::

        myopt = Load(MyClass).joinedload("widgets")

    The above ``myopt`` can now be used with :meth:`.Query.options`, where it
    will only take effect for the ``MyClass`` entity::

        session.query(MyClass, MyOtherClass).options(myopt)

    One case where :class:`.Load` is useful as public API is when specifying
    "wildcard" options that only take effect for a certain class::

        session.query(Order).options(Load(Order).lazyload('*'))

    Above, all relationships on ``Order`` will be lazy-loaded, but other
    attributes on those descendant objects will load using their normal
    loader strategy.

    .. seealso::

        :ref:`deferred_options`

        :ref:`deferred_loading_w_multiple`

        :ref:`relationship_loader_options`

    """

    def __init__(self, entity):
        insp = inspect(entity)
        self.path = insp._path_registry
        # note that this .context is shared among all descendant
        # Load objects
        self.context = util.OrderedDict()
        self.local_opts = {}
        self._of_type = None
        self.is_class_strategy = False

    @classmethod
    def for_existing_path(cls, path):
        load = cls.__new__(cls)
        load.path = path
        load.context = {}
        load.local_opts = {}
        load._of_type = None
        return load

    def _generate_cache_key(self, path):
        if path.path[0].is_aliased_class:
            return False

        serialized = []
        for (key, loader_path), obj in self.context.items():
            if key != "loader":
                continue

            for local_elem, obj_elem in zip(self.path.path, loader_path):
                if local_elem is not obj_elem:
                    break
            else:
                endpoint = obj._of_type or obj.path.path[-1]
                chopped = self._chop_path(loader_path, path)

                if (
                    # means loader_path and path are unrelated,
                    # this does not need to be part of a cache key
                    chopped
                    is None
                ) or (
                    # means no additional path with loader_path + path
                    # and the endpoint isn't using of_type so isn't modified
                    # into an alias or other unsafe entity
                    not chopped
                    and not obj._of_type
                ):
                    continue

                serialized_path = []

                for token in chopped:
                    if isinstance(token, util.string_types):
                        serialized_path.append(token)
                    elif token.is_aliased_class:
                        return False
                    elif token.is_property:
                        serialized_path.append(token.key)
                    else:
                        assert token.is_mapper
                        serialized_path.append(token.class_)

                if not serialized_path or endpoint != serialized_path[-1]:
                    if endpoint.is_mapper:
                        serialized_path.append(endpoint.class_)
                    elif endpoint.is_aliased_class:
                        return False

                serialized.append(
                    (
                        tuple(serialized_path)
                        + (obj.strategy or ())
                        + (
                            tuple(
                                [
                                    (key, obj.local_opts[key])
                                    for key in sorted(obj.local_opts)
                                ]
                            )
                            if obj.local_opts
                            else ()
                        )
                    )
                )
        if not serialized:
            return None
        else:
            return tuple(serialized)

    def _generate(self):
        cloned = super(Load, self)._generate()
        cloned.local_opts = {}
        return cloned

    is_opts_only = False
    is_class_strategy = False
    strategy = None
    propagate_to_loaders = False

    def process_query(self, query):
        self._process(query, True)

    def process_query_conditionally(self, query):
        self._process(query, False)

    def _process(self, query, raiseerr):
        current_path = query._current_path
        if current_path:
            for (token, start_path), loader in self.context.items():
                chopped_start_path = self._chop_path(start_path, current_path)
                if chopped_start_path is not None:
                    query._attributes[(token, chopped_start_path)] = loader
        else:
            query._attributes.update(self.context)

    def _generate_path(
        self, path, attr, for_strategy, wildcard_key, raiseerr=True
    ):
        existing_of_type = self._of_type
        self._of_type = None
        if raiseerr and not path.has_entity:
            if isinstance(path, TokenRegistry):
                raise sa_exc.ArgumentError(
                    "Wildcard token cannot be followed by another entity"
                )
            else:
                raise sa_exc.ArgumentError(
                    "Mapped attribute '%s' does not "
                    "refer to a mapped entity" % (path.prop,)
                )

        if isinstance(attr, util.string_types):
            default_token = attr.endswith(_DEFAULT_TOKEN)
            if attr.endswith(_WILDCARD_TOKEN) or default_token:
                if default_token:
                    self.propagate_to_loaders = False
                if wildcard_key:
                    attr = "%s:%s" % (wildcard_key, attr)

                # TODO: AliasedInsp inside the path for of_type is not
                # working for a with_polymorphic entity because the
                # relationship loaders don't render the with_poly into the
                # path.  See #4469 which will try to improve this
                if existing_of_type and not existing_of_type.is_aliased_class:
                    path = path.parent[existing_of_type]
                path = path.token(attr)
                self.path = path
                return path

            if existing_of_type:
                ent = inspect(existing_of_type)
            else:
                ent = path.entity

            try:
                # use getattr on the class to work around
                # synonyms, hybrids, etc.
                attr = getattr(ent.class_, attr)
            except AttributeError:
                if raiseerr:
                    raise sa_exc.ArgumentError(
                        'Can\'t find property named "%s" on '
                        "%s in this Query." % (attr, ent)
                    )
                else:
                    return None
            else:
                attr = found_property = attr.property

            path = path[attr]
        elif _is_mapped_class(attr):
            # TODO: this does not appear to be a valid codepath.  "attr"
            # would never be a mapper.  This block is present in 1.2
            # as well however does not seem to be accessed in any tests.
            if not orm_util._entity_corresponds_to_use_path_impl(
                attr.parent, path[-1]
            ):
                if raiseerr:
                    raise sa_exc.ArgumentError(
                        "Attribute '%s' does not "
                        "link from element '%s'" % (attr, path.entity)
                    )
                else:
                    return None
        else:
            prop = found_property = attr.property

            if not orm_util._entity_corresponds_to_use_path_impl(
                attr.parent, path[-1]
            ):
                if raiseerr:
                    raise sa_exc.ArgumentError(
                        'Attribute "%s" does not '
                        'link from element "%s".%s'
                        % (
                            attr,
                            path.entity,
                            (
                                "  Did you mean to use "
                                "%s.of_type(%s)?"
                                % (path[-2], attr.class_.__name__)
                                if len(path) > 1
                                and path.entity.is_mapper
                                and attr.parent.is_aliased_class
                                else ""
                            ),
                        )
                    )
                else:
                    return None

            if getattr(attr, "_of_type", None):
                ac = attr._of_type
                ext_info = of_type_info = inspect(ac)

                existing = path.entity_path[prop].get(
                    self.context, "path_with_polymorphic"
                )
                if not ext_info.is_aliased_class:
                    ac = orm_util.with_polymorphic(
                        ext_info.mapper.base_mapper,
                        ext_info.mapper,
                        aliased=True,
                        _use_mapper_path=True,
                        _existing_alias=existing,
                    )
                    ext_info = inspect(ac)

                path.entity_path[prop].set(
                    self.context, "path_with_polymorphic", ext_info
                )

                path = path[prop][ext_info]

                self._of_type = of_type_info

            else:
                path = path[prop]

        if for_strategy is not None:
            found_property._get_strategy(for_strategy)
        if path.has_entity:
            path = path.entity_path
        self.path = path
        return path

    def __str__(self):
        return "Load(strategy=%r)" % (self.strategy,)

    def _coerce_strat(self, strategy):
        if strategy is not None:
            strategy = tuple(sorted(strategy.items()))
        return strategy

    def _apply_to_parent(self, parent, applied, bound):
        raise NotImplementedError(
            "Only 'unbound' loader options may be used with the "
            "Load.options() method"
        )

    @_generative
    def options(self, *opts):
        r"""Apply a series of options as sub-options to this :class:`.Load`
        object.

        E.g.::

            query = session.query(Author)
            query = query.options(
                        joinedload(Author.book).options(
                            load_only("summary", "excerpt"),
                            joinedload(Book.citations).options(
                                joinedload(Citation.author)
                            )
                        )
                    )

        :param \*opts: A series of loader option objects (ultimately
         :class:`.Load` objects) which should be applied to the path
         specified by this :class:`.Load` object.

        .. versionadded:: 1.3.6

        .. seealso::

            :func:`.defaultload`

            :ref:`relationship_loader_options`

            :ref:`deferred_loading_w_multiple`

        """
        apply_cache = {}
        bound = not isinstance(self, _UnboundLoad)
        if bound:
            raise NotImplementedError(
                "The options() method is currently only supported "
                "for 'unbound' loader options"
            )
        for opt in opts:
            opt._apply_to_parent(self, apply_cache, bound)

    @_generative
    def set_relationship_strategy(
        self, attr, strategy, propagate_to_loaders=True
    ):
        strategy = self._coerce_strat(strategy)
        self.is_class_strategy = False
        self.propagate_to_loaders = propagate_to_loaders
        # if the path is a wildcard, this will set propagate_to_loaders=False
        self._generate_path(self.path, attr, strategy, "relationship")
        self.strategy = strategy
        if strategy is not None:
            self._set_path_strategy()

    @_generative
    def set_column_strategy(self, attrs, strategy, opts=None, opts_only=False):
        strategy = self._coerce_strat(strategy)

        self.is_class_strategy = False
        for attr in attrs:
            cloned = self._generate()
            cloned.strategy = strategy
            cloned._generate_path(self.path, attr, strategy, "column")
            cloned.propagate_to_loaders = True
            if opts:
                cloned.local_opts.update(opts)
            if opts_only:
                cloned.is_opts_only = True
            cloned._set_path_strategy()
        self.is_class_strategy = False

    @_generative
    def set_generic_strategy(self, attrs, strategy):
        strategy = self._coerce_strat(strategy)

        for attr in attrs:
            path = self._generate_path(self.path, attr, strategy, None)
            cloned = self._generate()
            cloned.strategy = strategy
            cloned.path = path
            cloned.propagate_to_loaders = True
            cloned._set_path_strategy()

    @_generative
    def set_class_strategy(self, strategy, opts):
        strategy = self._coerce_strat(strategy)
        cloned = self._generate()
        cloned.is_class_strategy = True
        path = cloned._generate_path(self.path, None, strategy, None)
        cloned.strategy = strategy
        cloned.path = path
        cloned.propagate_to_loaders = True
        cloned._set_path_strategy()
        cloned.local_opts.update(opts)

    def _set_for_path(self, context, path, replace=True, merge_opts=False):
        if merge_opts or not replace:
            existing = path.get(self.context, "loader")

            if existing:
                if merge_opts:
                    existing.local_opts.update(self.local_opts)
            else:
                path.set(context, "loader", self)
        else:
            existing = path.get(self.context, "loader")
            path.set(context, "loader", self)
            if existing and existing.is_opts_only:
                self.local_opts.update(existing.local_opts)

    def _set_path_strategy(self):
        if not self.is_class_strategy and self.path.has_entity:
            effective_path = self.path.parent
        else:
            effective_path = self.path

        if effective_path.is_token:
            for path in effective_path.generate_for_superclasses():
                self._set_for_path(
                    self.context,
                    path,
                    replace=True,
                    merge_opts=self.is_opts_only,
                )
        else:
            self._set_for_path(
                self.context,
                effective_path,
                replace=True,
                merge_opts=self.is_opts_only,
            )

    def __getstate__(self):
        d = self.__dict__.copy()
        d["path"] = self.path.serialize()
        return d

    def __setstate__(self, state):
        self.__dict__.update(state)
        self.path = PathRegistry.deserialize(self.path)

    def _chop_path(self, to_chop, path):
        i = -1

        for i, (c_token, p_token) in enumerate(zip(to_chop, path.path)):
            if isinstance(c_token, util.string_types):
                # TODO: this is approximated from the _UnboundLoad
                # version and probably has issues, not fully covered.

                if i == 0 and c_token.endswith(":" + _DEFAULT_TOKEN):
                    return to_chop
                elif (
                    c_token != "relationship:%s" % (_WILDCARD_TOKEN,)
                    and c_token != p_token.key
                ):
                    return None

            if c_token is p_token:
                continue
            elif (
                isinstance(c_token, InspectionAttr)
                and c_token.is_mapper
                and p_token.is_mapper
                and c_token.isa(p_token)
            ):
                continue
            else:
                return None
        return to_chop[i + 1 :]

class _UnboundLoad(Load):
    """Represent a loader option that isn't tied to a root entity.

    The loader option will produce an entity-linked :class:`.Load`
    object when it is passed :meth:`.Query.options`.

    This provides compatibility with the traditional system
    of freestanding options, e.g. ``joinedload('x.y.z')``.

    """

    def __init__(self):
        self.path = ()
        self._to_bind = []
        self.local_opts = {}

    _is_chain_link = False

    def _generate_cache_key(self, path):
        serialized = ()
        for val in self._to_bind:
            for local_elem, val_elem in zip(self.path, val.path):
                if local_elem is not val_elem:
                    break
            else:
                opt = val._bind_loader([path.path[0]], None, None, False)
                if opt:
                    c_key = opt._generate_cache_key(path)
                    if c_key is False:
                        return False
                    elif c_key:
                        serialized += c_key
        if not serialized:
            return None
        else:
            return serialized

    def _set_path_strategy(self):
        self._to_bind.append(self)

    def _apply_to_parent(self, parent, applied, bound):
        if self in applied:
            return applied[self]

        cloned = self._generate()

        applied[self] = cloned

        cloned.strategy = self.strategy
        if self.path:
            attr = self.path[-1]
            if isinstance(attr, util.string_types) and attr.endswith(
                _DEFAULT_TOKEN
            ):
                attr = attr.split(":")[0] + ":" + _WILDCARD_TOKEN
            cloned._generate_path(
                parent.path + self.path[0:-1], attr, self.strategy, None
            )

        # these assertions can go away once the "sub options" API is
        # mature
        assert cloned.propagate_to_loaders == self.propagate_to_loaders
        assert cloned.is_class_strategy == self.is_class_strategy
        assert cloned.is_opts_only == self.is_opts_only

        new_to_bind = {
            elem._apply_to_parent(parent, applied, bound)
            for elem in self._to_bind
        }
        cloned._to_bind = parent._to_bind
        cloned._to_bind.extend(new_to_bind)
        cloned.local_opts.update(self.local_opts)

        return cloned

    def _generate_path(self, path, attr, for_strategy, wildcard_key):
        if (
            wildcard_key
            and isinstance(attr, util.string_types)
            and attr in (_WILDCARD_TOKEN, _DEFAULT_TOKEN)
        ):
            if attr == _DEFAULT_TOKEN:
                self.propagate_to_loaders = False
            attr = "%s:%s" % (wildcard_key, attr)
        if path and _is_mapped_class(path[-1]) and not self.is_class_strategy:
            path = path[0:-1]
        if attr:
            path = path + (attr,)
        self.path = path
        return path

    def __getstate__(self):
        d = self.__dict__.copy()
        d["path"] = self._serialize_path(self.path, filter_aliased_class=True)
        return d

    def __setstate__(self, state):
        ret = []
        for key in state["path"]:
            if isinstance(key, tuple):
                if len(key) == 2:
                    # support legacy
                    cls, propkey = key
                    of_type = None
                else:
                    cls, propkey, of_type = key
                prop = getattr(cls, propkey)
                if of_type:
                    prop = prop.of_type(of_type)
                ret.append(prop)
            else:
                ret.append(key)
        state["path"] = tuple(ret)
        self.__dict__ = state

    def _process(self, query, raiseerr):
        dedupes = query._attributes["_unbound_load_dedupes"]
        for val in self._to_bind:
            if val not in dedupes:
                dedupes.add(val)
                val._bind_loader(
                    [ent.entity_zero for ent in query._mapper_entities],
                    query._current_path,
                    query._attributes,
                    raiseerr,
                )

    @classmethod
    def _from_keys(cls, meth, keys, chained, kw):
        opt = _UnboundLoad()

        def _split_key(key):
            if isinstance(key, util.string_types):
                # coerce fooload('*') into "default loader strategy"
                if key == _WILDCARD_TOKEN:
                    return (_DEFAULT_TOKEN,)
                # coerce fooload(".*") into "wildcard on default entity"
                elif key.startswith("." + _WILDCARD_TOKEN):
                    key = key[1:]
                return key.split(".")
            else:
                return (key,)

        all_tokens = [token for key in keys for token in _split_key(key)]

        for token in all_tokens[0:-1]:
            if chained:
                opt = meth(opt, token, **kw)
            else:
                opt = opt.defaultload(token)
            opt._is_chain_link = True

        opt = meth(opt, all_tokens[-1], **kw)
        opt._is_chain_link = False

        return opt

    def _chop_path(self, to_chop, path):
        i = -1
        for i, (c_token, (p_entity, p_prop)) in enumerate(
            zip(to_chop, path.pairs())
        ):
            if isinstance(c_token, util.string_types):
                if i == 0 and c_token.endswith(":" + _DEFAULT_TOKEN):
                    return to_chop
                elif (
                    c_token != "relationship:%s" % (_WILDCARD_TOKEN,)
                    and c_token != p_prop.key
                ):
                    return None
            elif isinstance(c_token, PropComparator):
                if c_token.property is not p_prop or (
                    c_token._parententity is not p_entity
                    and (
                        not c_token._parententity.is_mapper
                        or not c_token._parententity.isa(p_entity)
                    )
                ):
                    return None
        else:
            i += 1

        return to_chop[i:]

    def _serialize_path(self, path, filter_aliased_class=False):
        ret = []
        for token in path:
            if isinstance(token, QueryableAttribute):
                if (
                    filter_aliased_class
                    and token._of_type
                    and inspect(token._of_type).is_aliased_class
                ):
                    ret.append((token._parentmapper.class_, token.key, None))
                else:
                    ret.append(
                        (token._parentmapper.class_, token.key, token._of_type)
                    )
            elif isinstance(token, PropComparator):
                ret.append((token._parentmapper.class_, token.key, None))
            else:
                ret.append(token)
        return ret

    def _bind_loader(self, entities, current_path, context, raiseerr):
        """Convert from an _UnboundLoad() object into a Load() object.

        The _UnboundLoad() uses an informal "path" and does not necessarily
        refer to a lead entity as it may use string tokens.   The Load()
        OTOH refers to a complete path.   This method reconciles from a
        given Query into a Load.

        Example::

            query = session.query(User).options(
                joinedload("orders").joinedload("items"))

        The above options will be an _UnboundLoad object along the lines
        of (note this is not the exact API of _UnboundLoad)::

            _UnboundLoad(
                _to_bind=[
                    _UnboundLoad(["orders"], {"lazy": "joined"}),
                    _UnboundLoad(["orders", "items"], {"lazy": "joined"}),
                ]
            )

        After this method, we get something more like this (again this is
        not exact API)::

            Load(
                User,
                (User, User.orders.property))
            Load(
                User,
                (User, User.orders.property, Order, Order.items.property))

        """

        start_path = self.path

        if self.is_class_strategy and current_path:
            start_path += (entities[0],)

        # _current_path implies we're in a
        # secondary load with an existing path

        if current_path:
            start_path = self._chop_path(start_path, current_path)

        if not start_path:
            return None

        # look at the first token and try to locate within the Query
        # what entity we are referring towards.
        token = start_path[0]

        if isinstance(token, util.string_types):
            entity = self._find_entity_basestring(entities, token, raiseerr)
        elif isinstance(token, PropComparator):
            prop = token.property
            entity = self._find_entity_prop_comparator(
                entities, prop, token._parententity, raiseerr
            )
        elif self.is_class_strategy and _is_mapped_class(token):
            entity = inspect(token)
            if entity not in entities:
                entity = None
        else:
            raise sa_exc.ArgumentError(
                "mapper option expects " "string key or list of attributes"
            )

        if not entity:
            return

        path_element = entity

        # transfer our entity-less state into a Load() object
        # with a real entity path.  Start with the lead entity
        # we just located, then go through the rest of our path
        # tokens and populate into the Load().
        loader = Load(path_element)
        if context is not None:
            loader.context = context
        else:
            context = loader.context

        loader.strategy = self.strategy
        loader.is_opts_only = self.is_opts_only
        loader.is_class_strategy = self.is_class_strategy

        path = loader.path

        if not loader.is_class_strategy:
            for idx, token in enumerate(start_path):
                if not loader._generate_path(
                    loader.path,
                    token,
                    self.strategy if idx == len(start_path) - 1 else None,
                    None,
                    raiseerr,
                ):
                    return

        loader.local_opts.update(self.local_opts)

        if not loader.is_class_strategy and loader.path.has_entity:
            effective_path = loader.path.parent
        else:
            effective_path = loader.path

        # prioritize "first class" options over those
        # that were "links in the chain", e.g. "x" and "y" in
        # someload("x.y.z") versus someload("x") / someload("x.y")

        if effective_path.is_token:
            for path in effective_path.generate_for_superclasses():
                loader._set_for_path(
                    context,
                    path,
                    replace=not self._is_chain_link,
                    merge_opts=self.is_opts_only,
                )
        else:
            loader._set_for_path(
                context,
                effective_path,
                replace=not self._is_chain_link,
                merge_opts=self.is_opts_only,
            )

        return loader

    def _find_entity_prop_comparator(self, entities, prop, mapper, raiseerr):
        if _is_aliased_class(mapper):
            searchfor = mapper
        else:
            searchfor = _class_to_mapper(mapper)
        for ent in entities:
            if orm_util._entity_corresponds_to(ent, searchfor):
                return ent
        else:
            if raiseerr:
                if not list(entities):
                    raise sa_exc.ArgumentError(
                        "Query has only expression-based entities, "
                        'which do not apply to %s "%s"'
                        % (util.clsname_as_plain_name(type(prop)), prop)
                    )
                else:
                    raise sa_exc.ArgumentError(
                        'Mapped attribute "%s" does not apply to any of the '
                        "root entities in this query, e.g. %s. Please "
                        "specify the full path "
                        "from one of the root entities to the target "
                        "attribute. "
                        % (prop, ", ".join(str(x) for x in entities))
                    )
            else:
                return None

    def _find_entity_basestring(self, entities, token, raiseerr):
        if token.endswith(":" + _WILDCARD_TOKEN):
            if len(list(entities)) != 1:
                if raiseerr:
                    raise sa_exc.ArgumentError(
                        "Can't apply wildcard ('*') or load_only() "
                        "loader option to multiple entities %s. Specify "
                        "loader options for each entity individually, such "
                        "as %s."
                        % (
                            ", ".join(str(ent) for ent in entities),
                            ", ".join(
                                "Load(%s).some_option('*')" % ent
                                for ent in entities
                            ),
                        )
                    )
        elif token.endswith(_DEFAULT_TOKEN):
            raiseerr = False

        for ent in entities:
            # return only the first _MapperEntity when searching
            # based on string prop name.   Ideally object
            # attributes are used to specify more exactly.
            return ent
        else:
            if raiseerr:
                raise sa_exc.ArgumentError(
                    "Query has only expression-based entities - "
                    'can\'t find property named "%s".' % (token,)
                )
            else:
                return None

class loader_option(object):
    def __init__(self):
        pass

    def __call__(self, fn):
        self.name = name = fn.__name__
        self.fn = fn
        if hasattr(Load, name):
            raise TypeError("Load class already has a %s method." % (name))
        setattr(Load, name, fn)

        return self

    def _add_unbound_fn(self, fn):
        self._unbound_fn = fn
        fn_doc = self.fn.__doc__
        self.fn.__doc__ = """Produce a new :class:`.Load` object with the
:func:`.orm.%(name)s` option applied.

See :func:`.orm.%(name)s` for usage examples.

""" % {
            "name": self.name
        }

        fn.__doc__ = fn_doc
        return self

    def _add_unbound_all_fn(self, fn):
        fn.__doc__ = """Produce a standalone "all" option for :func:`.orm.%(name)s`.

.. deprecated:: 0.9

    The :func:`.%(name)s_all` function is deprecated, and will be removed
    in a future release.  Please use method chaining with :func:`.%(name)s`
    instead, as in::

        session.query(MyClass).options(
            %(name)s("someattribute").%(name)s("anotherattribute")
        )

""" % {
            "name": self.name
        }
        fn = util.deprecated(
            "0.9",
            "The :func:`.%(name)s_all` function is deprecated, and will be "
            "removed in a future release.  Please use method chaining with "
            ":func:`.%(name)s` instead" % {"name": self.name},
            add_deprecation_to_docstring=False,
        )(fn)

        self._unbound_all_fn = fn
        return self

@loader_option()
def contains_eager(loadopt, attr, alias=None):
    r"""Indicate that the given attribute should be eagerly loaded from
    columns stated manually in the query.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    The option is used in conjunction with an explicit join that loads
    the desired rows, i.e.::

        sess.query(Order).\
                join(Order.user).\
                options(contains_eager(Order.user))

    The above query would join from the ``Order`` entity to its related
    ``User`` entity, and the returned ``Order`` objects would have the
    ``Order.user`` attribute pre-populated.

    :func:`.contains_eager` also accepts an `alias` argument, which is the
    string name of an alias, an :func:`~sqlalchemy.sql.expression.alias`
    construct, or an :func:`~sqlalchemy.orm.aliased` construct. Use this when
    the eagerly-loaded rows are to come from an aliased table::

        user_alias = aliased(User)
        sess.query(Order).\
                join((user_alias, Order.user)).\
                options(contains_eager(Order.user, alias=user_alias))

    When using :func:`.contains_eager` in conjunction with inherited
    subclasses, the :meth:`.RelationshipProperty.of_type` modifier should
    also be used in order to set up the pathing properly::

        sess.query(Company).\
            outerjoin(Company.employees.of_type(Manager)).\
            options(
                contains_eager(
                    Company.employees.of_type(Manager),
                    alias=Manager)
            )

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`contains_eager`

    """
    if alias is not None:
        if not isinstance(alias, str):
            info = inspect(alias)
            alias = info.selectable

    elif getattr(attr, "_of_type", None):
        ot = inspect(attr._of_type)
        alias = ot.selectable

    cloned = loadopt.set_relationship_strategy(
        attr, {"lazy": "joined"}, propagate_to_loaders=False
    )
    cloned.local_opts["eager_from_alias"] = alias
    return cloned

@contains_eager._add_unbound_fn
def contains_eager(*keys, **kw):
    return _UnboundLoad()._from_keys(
        _UnboundLoad.contains_eager, keys, True, kw
    )

@loader_option()
def load_only(loadopt, *attrs):
    """Indicate that for a particular entity, only the given list
    of column-based attribute names should be loaded; all others will be
    deferred.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    Example - given a class ``User``, load only the ``name`` and ``fullname``
    attributes::

        session.query(User).options(load_only("name", "fullname"))

    Example - given a relationship ``User.addresses -> Address``, specify
    subquery loading for the ``User.addresses`` collection, but on each
    ``Address`` object load only the ``email_address`` attribute::

        session.query(User).options(
                subqueryload("addresses").load_only("email_address")
        )

    For a :class:`.Query` that has multiple entities, the lead entity can be
    specifically referred to using the :class:`.Load` constructor::

        session.query(User, Address).join(User.addresses).options(
                    Load(User).load_only("name", "fullname"),
                    Load(Address).load_only("email_addres")
                )

    .. versionadded:: 0.9.0

    """
    cloned = loadopt.set_column_strategy(
        attrs, {"deferred": False, "instrument": True}
    )
    cloned.set_column_strategy(
        "*", {"deferred": True, "instrument": True}, {"undefer_pks": True}
    )
    return cloned

@load_only._add_unbound_fn
def load_only(*attrs):
    return _UnboundLoad().load_only(*attrs)

@loader_option()
def joinedload(loadopt, attr, innerjoin=None):
    """Indicate that the given attribute should be loaded using joined
    eager loading.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    examples::

        # joined-load the "orders" collection on "User"
        query(User).options(joinedload(User.orders))

        # joined-load Order.items and then Item.keywords
        query(Order).options(
            joinedload(Order.items).joinedload(Item.keywords))

        # lazily load Order.items, but when Items are loaded,
        # joined-load the keywords collection
        query(Order).options(
            lazyload(Order.items).joinedload(Item.keywords))

    :param innerjoin: if ``True``, indicates that the joined eager load should
     use an inner join instead of the default of left outer join::

        query(Order).options(joinedload(Order.user, innerjoin=True))

     In order to chain multiple eager joins together where some may be
     OUTER and others INNER, right-nested joins are used to link them::

        query(A).options(
            joinedload(A.bs, innerjoin=False).
                joinedload(B.cs, innerjoin=True)
        )

     The above query, linking A.bs via "outer" join and B.cs via "inner" join
     would render the joins as "a LEFT OUTER JOIN (b JOIN c)".   When using
     older versions of SQLite (< 3.7.16), this form of JOIN is translated to
     use full subqueries as this syntax is otherwise not directly supported.

     The ``innerjoin`` flag can also be stated with the term ``"unnested"``.
     This indicates that an INNER JOIN should be used, *unless* the join
     is linked to a LEFT OUTER JOIN to the left, in which case it
     will render as LEFT OUTER JOIN.  For example, supposing ``A.bs``
     is an outerjoin::

        query(A).options(
            joinedload(A.bs).
                joinedload(B.cs, innerjoin="unnested")
        )

     The above join will render as "a LEFT OUTER JOIN b LEFT OUTER JOIN c",
     rather than as "a LEFT OUTER JOIN (b JOIN c)".

     .. note:: The "unnested" flag does **not** affect the JOIN rendered
        from a many-to-many association table, e.g. a table configured
        as :paramref:`.relationship.secondary`, to the target table; for
        correctness of results, these joins are always INNER and are
        therefore right-nested if linked to an OUTER join.

     .. versionchanged:: 1.0.0 ``innerjoin=True`` now implies
        ``innerjoin="nested"``, whereas in 0.9 it implied
        ``innerjoin="unnested"``.  In order to achieve the pre-1.0 "unnested"
        inner join behavior, use the value ``innerjoin="unnested"``.
        See :ref:`migration_3008`.

    .. note::

        The joins produced by :func:`.orm.joinedload` are **anonymously
        aliased**.  The criteria by which the join proceeds cannot be
        modified, nor can the :class:`.Query` refer to these joins in any way,
        including ordering.  See :ref:`zen_of_eager_loading` for further
        detail.

        To produce a specific SQL JOIN which is explicitly available, use
        :meth:`.Query.join`.   To combine explicit JOINs with eager loading
        of collections, use :func:`.orm.contains_eager`; see
        :ref:`contains_eager`.

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`joined_eager_loading`

    """
    loader = loadopt.set_relationship_strategy(attr, {"lazy": "joined"})
    if innerjoin is not None:
        loader.local_opts["innerjoin"] = innerjoin
    return loader

@joinedload._add_unbound_fn
def joinedload(*keys, **kw):
    return _UnboundLoad._from_keys(_UnboundLoad.joinedload, keys, False, kw)

@joinedload._add_unbound_all_fn
def joinedload_all(*keys, **kw):
    return _UnboundLoad._from_keys(_UnboundLoad.joinedload, keys, True, kw)

@loader_option()
def subqueryload(loadopt, attr):
    """Indicate that the given attribute should be loaded using
    subquery eager loading.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    examples::

        # subquery-load the "orders" collection on "User"
        query(User).options(subqueryload(User.orders))

        # subquery-load Order.items and then Item.keywords
        query(Order).options(
            subqueryload(Order.items).subqueryload(Item.keywords))

        # lazily load Order.items, but when Items are loaded,
        # subquery-load the keywords collection
        query(Order).options(
            lazyload(Order.items).subqueryload(Item.keywords))

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`subquery_eager_loading`

    """
    return loadopt.set_relationship_strategy(attr, {"lazy": "subquery"})

@subqueryload._add_unbound_fn
def subqueryload(*keys):
    return _UnboundLoad._from_keys(_UnboundLoad.subqueryload, keys, False, {})

@subqueryload._add_unbound_all_fn
def subqueryload_all(*keys):
    return _UnboundLoad._from_keys(_UnboundLoad.subqueryload, keys, True, {})

@loader_option()
def selectinload(loadopt, attr):
    """Indicate that the given attribute should be loaded using
    SELECT IN eager loading.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    examples::

        # selectin-load the "orders" collection on "User"
        query(User).options(selectinload(User.orders))

        # selectin-load Order.items and then Item.keywords
        query(Order).options(
            selectinload(Order.items).selectinload(Item.keywords))

        # lazily load Order.items, but when Items are loaded,
        # selectin-load the keywords collection
        query(Order).options(
            lazyload(Order.items).selectinload(Item.keywords))

    .. versionadded:: 1.2

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`selectin_eager_loading`

    """
    return loadopt.set_relationship_strategy(attr, {"lazy": "selectin"})

@selectinload._add_unbound_fn
def selectinload(*keys):
    return _UnboundLoad._from_keys(_UnboundLoad.selectinload, keys, False, {})

@selectinload._add_unbound_all_fn
def selectinload_all(*keys):
    return _UnboundLoad._from_keys(_UnboundLoad.selectinload, keys, True, {})

@loader_option()
def lazyload(loadopt, attr):
    """Indicate that the given attribute should be loaded using "lazy"
    loading.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`lazy_loading`

    """
    return loadopt.set_relationship_strategy(attr, {"lazy": "select"})

@lazyload._add_unbound_fn
def lazyload(*keys):
    return _UnboundLoad._from_keys(_UnboundLoad.lazyload, keys, False, {})

@lazyload._add_unbound_all_fn
def lazyload_all(*keys):
    return _UnboundLoad._from_keys(_UnboundLoad.lazyload, keys, True, {})

@loader_option()
def immediateload(loadopt, attr):
    """Indicate that the given attribute should be loaded using
    an immediate load with a per-attribute SELECT statement.

    The :func:`.immediateload` option is superseded in general
    by the :func:`.selectinload` option, which performs the same task
    more efficiently by emitting a SELECT for all loaded objects.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`selectin_eager_loading`

    """
    loader = loadopt.set_relationship_strategy(attr, {"lazy": "immediate"})
    return loader

@immediateload._add_unbound_fn
def immediateload(*keys):
    return _UnboundLoad._from_keys(_UnboundLoad.immediateload, keys, False, {})

@loader_option()
def noload(loadopt, attr):
    """Indicate that the given relationship attribute should remain unloaded.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    :func:`.orm.noload` applies to :func:`.relationship` attributes; for
    column-based attributes, see :func:`.orm.defer`.

    .. seealso::

        :ref:`loading_toplevel`

    """

    return loadopt.set_relationship_strategy(attr, {"lazy": "noload"})

@noload._add_unbound_fn
def noload(*keys):
    return _UnboundLoad._from_keys(_UnboundLoad.noload, keys, False, {})

@loader_option()
def raiseload(loadopt, attr, sql_only=False):
    """Indicate that the given relationship attribute should disallow lazy loads.

    A relationship attribute configured with :func:`.orm.raiseload` will
    raise an :exc:`~sqlalchemy.exc.InvalidRequestError` upon access.   The
    typical way this is useful is when an application is attempting to ensure
    that all relationship attributes that are accessed in a particular context
    would have been already loaded via eager loading.  Instead of having
    to read through SQL logs to ensure lazy loads aren't occurring, this
    strategy will cause them to raise immediately.

    :param sql_only: if True, raise only if the lazy load would emit SQL,
     but not if it is only checking the identity map, or determining that
     the related value should just be None due to missing keys.  When False,
     the strategy will raise for all varieties of lazyload.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    :func:`.orm.raiseload` applies to :func:`.relationship` attributes only.

    .. versionadded:: 1.1

    .. seealso::

        :ref:`loading_toplevel`

        :ref:`prevent_lazy_with_raiseload`

    """

    return loadopt.set_relationship_strategy(
        attr, {"lazy": "raise_on_sql" if sql_only else "raise"}
    )

@raiseload._add_unbound_fn
def raiseload(*keys, **kw):
    return _UnboundLoad._from_keys(_UnboundLoad.raiseload, keys, False, kw)

@loader_option()
def defaultload(loadopt, attr):
    """Indicate an attribute should load using its default loader style.

    This method is used to link to other loader options further into
    a chain of attributes without altering the loader style of the links
    along the chain.  For example, to set joined eager loading for an
    element of an element::

        session.query(MyClass).options(
            defaultload(MyClass.someattribute).
            joinedload(MyOtherClass.someotherattribute)
        )

    :func:`.defaultload` is also useful for setting column-level options
    on a related class, namely that of :func:`.defer` and :func:`.undefer`::

        session.query(MyClass).options(
            defaultload(MyClass.someattribute).
            defer("some_column").
            undefer("some_other_column")
        )

    .. seealso::

        :meth:`.Load.options` - allows for complex hierarchical
        loader option structures with less verbosity than with individual
        :func:`.defaultload` directives.

        :ref:`relationship_loader_options`

        :ref:`deferred_loading_w_multiple`

    """
    return loadopt.set_relationship_strategy(attr, None)

@defaultload._add_unbound_fn
def defaultload(*keys):
    return _UnboundLoad._from_keys(_UnboundLoad.defaultload, keys, False, {})

@loader_option()
def defer(loadopt, key):
    r"""Indicate that the given column-oriented attribute should be deferred,
    e.g. not loaded until accessed.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    e.g.::

        from sqlalchemy.orm import defer

        session.query(MyClass).options(
                            defer("attribute_one"),
                            defer("attribute_two"))

        session.query(MyClass).options(
                            defer(MyClass.attribute_one),
                            defer(MyClass.attribute_two))

    To specify a deferred load of an attribute on a related class,
    the path can be specified one token at a time, specifying the loading
    style for each link along the chain.  To leave the loading style
    for a link unchanged, use :func:`.orm.defaultload`::

        session.query(MyClass).options(defaultload("someattr").defer("some_column"))

    A :class:`.Load` object that is present on a certain path can have
    :meth:`.Load.defer` called multiple times, each will operate on the same
    parent entity::

        session.query(MyClass).options(
                        defaultload("someattr").
                            defer("some_column").
                            defer("some_other_column").
                            defer("another_column")
            )

    :param key: Attribute to be deferred.

    :param \*addl_attrs: This option supports the old 0.8 style
     of specifying a path as a series of attributes, which is now superseded
     by the method-chained style.

        .. deprecated:: 0.9  The \*addl_attrs on :func:`.orm.defer` is
           deprecated and will be removed in a future release.   Please
           use method chaining in conjunction with defaultload() to
           indicate a path.

    .. seealso::

        :ref:`deferred`

        :func:`.orm.undefer`

    """
    return loadopt.set_column_strategy(
        (key,), {"deferred": True, "instrument": True}
    )

@defer._add_unbound_fn
def defer(key, *addl_attrs):
    if addl_attrs:
        util.warn_deprecated(
            "The *addl_attrs on orm.defer is deprecated.  Please use "
            "method chaining in conjunction with defaultload() to "
            "indicate a path."
        )
    return _UnboundLoad._from_keys(
        _UnboundLoad.defer, (key,) + addl_attrs, False, {}
    )

@loader_option()
def undefer(loadopt, key):
    r"""Indicate that the given column-oriented attribute should be undeferred,
    e.g. specified within the SELECT statement of the entity as a whole.

    The column being undeferred is typically set up on the mapping as a
    :func:`.deferred` attribute.

    This function is part of the :class:`.Load` interface and supports
    both method-chained and standalone operation.

    Examples::

        # undefer two columns
        session.query(MyClass).options(undefer("col1"), undefer("col2"))

        # undefer all columns specific to a single class using Load + *
        session.query(MyClass, MyOtherClass).options(
            Load(MyClass).undefer("*"))

        # undefer a column on a related object
        session.query(MyClass).options(
            defaultload(MyClass.items).undefer('text'))

    :param key: Attribute to be undeferred.

    :param \*addl_attrs: This option supports the old 0.8 style
     of specifying a path as a series of attributes, which is now superseded
     by the method-chained style.

        .. deprecated:: 0.9  The \*addl_attrs on :func:`.orm.undefer` is
           deprecated and will be removed in a future release.   Please
           use method chaining in conjunction with defaultload() to
           indicate a path.

    .. seealso::

        :ref:`deferred`

        :func:`.orm.defer`

        :func:`.orm.undefer_group`

    """
    return loadopt.set_column_strategy(
        (key,), {"deferred": False, "instrument": True}
    )

@undefer._add_unbound_fn
def undefer(key, *addl_attrs):
    if addl_attrs:
        util.warn_deprecated(
            "The *addl_attrs on orm.undefer is deprecated.  Please use "
            "method chaining in conjunction with defaultload() to "
            "indicate a path."
        )
    return _UnboundLoad._from_keys(
        _UnboundLoad.undefer, (key,) + addl_attrs, False, {}
    )

@loader_option()
def undefer_group(loadopt, name):
    """Indicate that columns within the given deferred group name should be
    undeferred.

    The columns being undeferred are set up on the mapping as
    :func:`.deferred` attributes and include a "group" name.

    E.g::

        session.query(MyClass).options(undefer_group("large_attrs"))

    To undefer a group of attributes on a related entity, the path can be
    spelled out using relationship loader options, such as
    :func:`.orm.defaultload`::

        session.query(MyClass).options(
            defaultload("someattr").undefer_group("large_attrs"))

    .. versionchanged:: 0.9.0 :func:`.orm.undefer_group` is now specific to a
       particular entity load path.

    .. seealso::

        :ref:`deferred`

        :func:`.orm.defer`

        :func:`.orm.undefer`

    """
    return loadopt.set_column_strategy(
        "*", None, {"undefer_group_%s" % name: True}, opts_only=True
    )

@undefer_group._add_unbound_fn
def undefer_group(name):
    return _UnboundLoad().undefer_group(name)

@loader_option()
def with_expression(loadopt, key, expression):
    r"""Apply an ad-hoc SQL expression to a "deferred expression" attribute.

    This option is used in conjunction with the :func:`.orm.query_expression`
    mapper-level construct that indicates an attribute which should be the
    target of an ad-hoc SQL expression.

    E.g.::

        sess.query(SomeClass).options(
            with_expression(SomeClass.x_y_expr, SomeClass.x + SomeClass.y)
        )

    .. versionadded:: 1.2

    :param key: Attribute to be undeferred.

    :param expr: SQL expression to be applied to the attribute.

    .. seealso::

        :ref:`mapper_query_expression`

    """

    expression = coercions.expect(
        roles.LabeledColumnExprRole, _orm_full_deannotate(expression)
    )

    return loadopt.set_column_strategy(
        (key,), {"query_expression": True}, opts={"expression": expression}
    )

@with_expression._add_unbound_fn
def with_expression(key, expression):
    return _UnboundLoad._from_keys(
        _UnboundLoad.with_expression, (key,), False, {"expression": expression}
    )

@loader_option()
def selectin_polymorphic(loadopt, classes):
    """Indicate an eager load should take place for all attributes
    specific to a subclass.

    This uses an additional SELECT with IN against all matched primary
    key values, and is the per-query analogue to the ``"selectin"``
    setting on the :paramref:`.mapper.polymorphic_load` parameter.

    .. versionadded:: 1.2

    .. seealso::

        :ref:`inheritance_polymorphic_load`

    """
    loadopt.set_class_strategy(
        {"selectinload_polymorphic": True},
        opts={
            "entities": tuple(
                sorted((inspect(cls) for cls in classes), key=id)
            )
        },
    )
    return loadopt

@selectin_polymorphic._add_unbound_fn
def selectin_polymorphic(base_cls, classes):
    ul = _UnboundLoad()
    ul.is_class_strategy = True
    ul.path = (inspect(base_cls),)
    ul.selectin_polymorphic(classes)
    return ul


text:
require 'heapinfo/nil'

describe HeapInfo::Nil do
  before(:all) do
    @nil = HeapInfo::Nil.instance
  end
  it 'nil?' do
    expect(@nil.nil?).to be true
  end
  it 'nil chain' do
    expect(@nil.xdd.oao.no_method).to be @nil
  end
  it 'puts' do
    expect(puts(@nil)).to be nil
  end
  it 'respond_to?' do
    expect(@nil.respond_to?(:puts)).to be false
    expect(@nil.respond_to?(:inspect)).to be true
    expect(@nil.respond_to?(:nil?)).to be true
  end
end


text:
[![Build Status](https://travis-ci.org/myJekyll/jasper2.svg?branch=master)](https://travis-ci.org/myJekyll/jasper2)
[![Ruby](https://img.shields.io/badge/ruby-2.4.2-blue.svg?style=flat)](http://travis-ci.org/myJekyll/jasper2)
[![Jekyll](https://img.shields.io/badge/jekyll-3.6.2-blue.svg?style=flat)](http://travis-ci.org/myJekyll/jasper2)

This is a full-featured port of Ghost's default theme [Casper](https://github.com/tryghost/casper)
*v2.1.7* for [Jekyll](https://jekyllrb.com/) / [GitHub Pages](https://pages.github.com/).

## Live Demo

[Ghost's Casper](https://demo.ghost.io) // [Jasper2](https://myJekyll.github.io/jasper2)

![home page](https://raw.githubusercontent.com/myJekyll/jasper2/master/assets/screenshot-desktop.jpg)

## Features

* Out of the box support for multiple authors (via `_data/authors.yml`)
* Full author information including: picture, bio, website, twitter, facebook, etc.
* Tag description(s) and personalised covers (via `_data/tags.yml`)
* Related posts view at the bottom of each post
* All Ghost default pages: Author page(s), Tag page(s), About page(s), 404, etc.
* Pagination (infinite scrolling or standard pagination, i.e. posts across multiple pages)
* Atom Feeds by [Jekyll-feed](https://github.com/jekyll/jekyll-feed)
* Toggleable subscribe button (requires an external service)
* Code Syntax Highlight with [highlight.js](https://highlightjs.org/)
* Support for Google Analytics tracking
* Support for Disqus comments (not Ghost standard)

## Getting Started

### Deployment

**Important:**  For security reasons, Github does not allow plugins (under `_plugins/`) when
deploying with Github Pages. This means:

**1)** that we need to generate your site locally (more details below) and push the resulting
HTML (the contents of `_site/` or `../jasper2-pages/`) to a Github repository, that GitHub Pages
then host;

**2)** built the site with [travis-ci](https://travis-ci.org/) (with goodies from
[jekyll-travis](https://github.com/mfenner/jekyll-travis)) automatically pushing the
generated HTML files to a *gh-pages* branch.
This later approach is the one I am currently using to generate the live demo.

**3)** deploy the static website with Jekyll-compatible hosters, such as https://www.netlify.com/, that allow for deployment from the Github repo and publish the website using CDNs. Netlify has a free starter offer.

For option **1)** simply clone this repository (*master branch*), and then run
`bundle exec jekyll serve` inside the directory. Upload the resulting `_site/` (or `../jasper2-pages/`)
contents to your repository (*master branch* if uploading as your personal page
(e.g. username.github.io) or *gh-pages branch* if uploading as a project page
(as for the [demo](https://github.com/myJekyll/jasper2/tree/gh-pages)).

For option **2)** you will need to set up travis-ci for your personal fork. Briefly all you
need then is to change your details in *[\_config.yml](_config.yml)* so that you can push
to your github repo. You will also need to generate a secure key to add to your
*[.travis.yml](.travis.yml)* (you can find more info on how to do it in that file).
Also make sure you read the documentation from
[jekyll-travis](https://github.com/mfenner/jekyll-travis). This approach has clear
advantages in that you simply push your file changes to GitHub and all the HTML files
are generated for you and pushed to *gh-pages*. Also you get to know if everything is
still fine with your site builds. Don't hesitate to contact me if you still have any
issues (see below about issue tracking).

### Author Pages

In order to properly generate author pages you need to rename the field *author* in the
front matter of every post to match that of your each author's *username* as defined
in the *[\_data/authors.yml](_data/authors.yml)* file.
With the latest update, multiple author blogs are now supported out of the box.

### Compiling Styles

Following on the way Casper styles are compiled as [described here](https://github.com/tryghost/casper#development):

Jasper2 styles are compiled using Gulp/PostCSS to polyfill future CSS spec. You'll need Node and Gulp installed globally. After that, from the theme's root directory:

```bash
$ npm install
$ gulp
```

Now you can edit `/assets/css/` files, which will be compiled to `/assets/built/` automatically.

## Issues and Contributing

This install builds well with Ruby v2.4.2 and Jekyll v3.6.2. If you run into any problems
please log them on the [issue tracker](https://github.com/myJekyll/jasper2/issues).

Feel free pull-request your patches and fixes.

## Thanks

Many thanks to the Ghost team for all the design work. Also many thanks to all contributors,
that help keeping the project alive and updated :smile:

## Copyright & License

Same licence as the one provided by Ghost's team. See Casper's theme [license](GHOST.txt).

Copyright (C) 2015-2017 - Released under the MIT License.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


text:
package cn.teaey.apns4j.protocol;

import java.util.AbstractMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author teaey
 * @since 1.0.0
 */
public class ListMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
    Entry[] table;
    int size;

    /**
     *
Constructor for ListMap.

     */
    public ListMap() {
        table = new Entry[16];
    }

    /**
     *
Constructor for ListMap.

     *
     * @param initialCapacity a int.
     */
    public ListMap(int initialCapacity) {
        table = new Entry[initialCapacity];
    }

    private Entry remove(int index) {
        rangeCheck(index);
        Entry oldValue = table[index];
        int numMoved = size - index - 1;
        if (numMoved > 0)
            System.arraycopy(table, index + 1, table, index, numMoved);
        table[--size] = null;
        return oldValue;
    }

    private void rangeCheck(int index) {
        if (index >= size) {
            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
        }
    }

    private String outOfBoundsMsg(int index) {
        return "Index: " + index + ", Size: " + size;
    }

    private Entry index(int index) {
        rangeCheck(index);
        return table[index];
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Set<Map.Entry<K, V>> entrySet() {
        return null;
    }

    static class Entry<K, V> implements Map.Entry<K, V> {
        final K key;
        V value;

        Entry(K key, V value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public K getKey() {
            return key;
        }

        @Override
        public V getValue() {
            return value;
        }

        @Override
        public V setValue(V value) {
            V oldValue = value;
            this.value = value;
            return oldValue;
        }

        public String toString() {
            return "[" + getKey() + ":" + getValue() + "]";
        }
    }

    private abstract class ListIterator<K, V> implements Iterator<Map.Entry<K, V>> {
        int index;

        ListIterator() {
        }

        @Override
        public boolean hasNext() {
            return index != (size() - 1);
        }

        @Override
        public Map.Entry<K, V> next() {
            return index(++index);
        }

        @Override
        public void remove() {
            ListMap.this.remove(index);
        }
    }
}