/* candidate-list.c generated by valac 0.56.19, the Vala compiler
 * generated from candidate-list.vala, do not modify */

/*
 * Copyright (C) 2011-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2011-2014 Red Hat, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "libkkc/libkkc.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	KKC_CANDIDATE_LIST_0_PROPERTY,
	KKC_CANDIDATE_LIST_CURSOR_POS_PROPERTY,
	KKC_CANDIDATE_LIST_SIZE_PROPERTY,
	KKC_CANDIDATE_LIST_PAGE_START_PROPERTY,
	KKC_CANDIDATE_LIST_PAGE_SIZE_PROPERTY,
	KKC_CANDIDATE_LIST_ROUND_PROPERTY,
	KKC_CANDIDATE_LIST_PAGE_VISIBLE_PROPERTY,
	KKC_CANDIDATE_LIST_NUM_PROPERTIES
};
static GParamSpec* kkc_candidate_list_properties[KKC_CANDIDATE_LIST_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	KKC_CANDIDATE_LIST_POPULATED_SIGNAL,
	KKC_CANDIDATE_LIST_SELECTED_SIGNAL,
	KKC_CANDIDATE_LIST_NUM_SIGNALS
};
static guint kkc_candidate_list_signals[KKC_CANDIDATE_LIST_NUM_SIGNALS] = {0};
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _KkcCandidateListPrivate {
	GeeArrayList* _candidates;
	gint _cursor_pos;
	GeeMap* seen;
	guint _page_start;
	guint _page_size;
	gboolean _round;
};

static gint KkcCandidateList_private_offset;
static gpointer kkc_candidate_list_parent_class = NULL;

VALA_EXTERN void kkc_candidate_list_clear (KkcCandidateList* self);
VALA_EXTERN gboolean kkc_candidate_list_contains (KkcCandidateList* self,
                                      KkcCandidate* candidate);
VALA_EXTERN gboolean kkc_candidate_list_add (KkcCandidateList* self,
                                 KkcCandidate* candidate);
VALA_EXTERN gboolean kkc_candidate_list_add_all (KkcCandidateList* self,
                                     KkcCandidateList* other);
VALA_EXTERN KkcCandidate** kkc_candidate_list_to_array (KkcCandidateList* self,
                                            gint* result_length1);
static guint kkc_candidate_list_get_page_start_cursor_pos (KkcCandidateList* self,
                                                    guint pos);
static gboolean kkc_candidate_list_real_next (KkcCandidateList* self);
static gboolean kkc_candidate_list_real_previous (KkcCandidateList* self);
static gboolean kkc_candidate_list_cursor_move (KkcCandidateList* self,
                                         gint step);
static gboolean kkc_candidate_list_page_move (KkcCandidateList* self,
                                       gint step);
static void kkc_candidate_list_finalize (GObject * obj);
static GType kkc_candidate_list_get_type_once (void);
static void _vala_kkc_candidate_list_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);
static void _vala_kkc_candidate_list_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec);

static inline gpointer
kkc_candidate_list_get_instance_private (KkcCandidateList* self)
{
	return G_STRUCT_MEMBER_P (self, KkcCandidateList_private_offset);
}

/**
         * Get the current candidate at the given index.
         *
         * @param index candidate position (-1 for the current cursor position)
         *
         * @return a Candidate
         */
KkcCandidate*
kkc_candidate_list_get (KkcCandidateList* self,
                        gint index)
{
	gboolean _tmp0_ = FALSE;
	GeeArrayList* _tmp3_;
	gpointer _tmp4_;
	KkcCandidate* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (index < 0) {
		index = self->priv->_cursor_pos;
	}
	if (0 <= index) {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = kkc_candidate_list_get_size (self);
		_tmp2_ = _tmp1_;
		_tmp0_ = index < _tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	_vala_assert (_tmp0_, "0 <= index && index < size");
	_tmp3_ = self->priv->_candidates;
	_tmp4_ = gee_abstract_list_get ((GeeAbstractList*) _tmp3_, index);
	result = (KkcCandidate*) _tmp4_;
	return result;
}

void
kkc_candidate_list_clear (KkcCandidateList* self)
{
	gboolean is_populated = FALSE;
	gboolean is_cursor_changed = FALSE;
	GeeMap* _tmp0_;
	GeeArrayList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	g_return_if_fail (self != NULL);
	is_populated = FALSE;
	is_cursor_changed = FALSE;
	_tmp0_ = self->priv->seen;
	gee_map_clear (_tmp0_);
	_tmp1_ = self->priv->_candidates;
	_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ > 0) {
		GeeArrayList* _tmp4_;
		_tmp4_ = self->priv->_candidates;
		gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp4_);
		is_populated = TRUE;
	}
	if (self->priv->_cursor_pos >= 0) {
		self->priv->_cursor_pos = -1;
		is_cursor_changed = TRUE;
	}
	if (is_populated) {
		g_signal_emit (self, kkc_candidate_list_signals[KKC_CANDIDATE_LIST_POPULATED_SIGNAL], 0);
	}
	if (is_cursor_changed) {
		g_object_notify ((GObject*) self, "cursor-pos");
	}
}

gboolean
kkc_candidate_list_contains (KkcCandidateList* self,
                             KkcCandidate* candidate)
{
	GeeMap* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (candidate != NULL, FALSE);
	_tmp0_ = self->priv->seen;
	_tmp1_ = kkc_candidate_get_output (candidate);
	_tmp2_ = _tmp1_;
	result = gee_map_contains (_tmp0_, _tmp2_);
	return result;
}

gboolean
kkc_candidate_list_add (KkcCandidateList* self,
                        KkcCandidate* candidate)
{
	GeeMap* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (candidate != NULL, FALSE);
	_tmp0_ = self->priv->seen;
	_tmp1_ = kkc_candidate_get_output (candidate);
	_tmp2_ = _tmp1_;
	if (gee_map_contains (_tmp0_, _tmp2_)) {
		KkcCandidate* c = NULL;
		GeeMap* _tmp3_;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		gpointer _tmp6_;
		gboolean _tmp7_ = FALSE;
		KkcCandidate* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		_tmp3_ = self->priv->seen;
		_tmp4_ = kkc_candidate_get_output (candidate);
		_tmp5_ = _tmp4_;
		_tmp6_ = gee_map_get (_tmp3_, _tmp5_);
		c = (KkcCandidate*) _tmp6_;
		_tmp8_ = c;
		_tmp9_ = kkc_candidate_get_annotation (_tmp8_);
		_tmp10_ = _tmp9_;
		if (_tmp10_ == NULL) {
			const gchar* _tmp11_;
			const gchar* _tmp12_;
			_tmp11_ = kkc_candidate_get_annotation (candidate);
			_tmp12_ = _tmp11_;
			_tmp7_ = _tmp12_ != NULL;
		} else {
			_tmp7_ = FALSE;
		}
		if (_tmp7_) {
			KkcCandidate* _tmp13_;
			const gchar* _tmp14_;
			const gchar* _tmp15_;
			_tmp13_ = c;
			_tmp14_ = kkc_candidate_get_annotation (candidate);
			_tmp15_ = _tmp14_;
			kkc_candidate_set_annotation (_tmp13_, _tmp15_);
		}
		result = FALSE;
		_g_object_unref0 (c);
		return result;
	} else {
		GeeArrayList* _tmp16_;
		GeeMap* _tmp17_;
		const gchar* _tmp18_;
		const gchar* _tmp19_;
		_tmp16_ = self->priv->_candidates;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp16_, candidate);
		_tmp17_ = self->priv->seen;
		_tmp18_ = kkc_candidate_get_output (candidate);
		_tmp19_ = _tmp18_;
		gee_map_set (_tmp17_, _tmp19_, candidate);
		result = TRUE;
		return result;
	}
}

gboolean
kkc_candidate_list_add_all (KkcCandidateList* self,
                            KkcCandidateList* other)
{
	gboolean retval = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (other != NULL, FALSE);
	retval = FALSE;
	{
		GeeArrayList* _c_list = NULL;
		GeeArrayList* _tmp0_;
		gint _c_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _c_index = 0;
		_tmp0_ = other->priv->_candidates;
		_c_list = _tmp0_;
		_tmp1_ = _c_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_c_size = _tmp3_;
		_c_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			KkcCandidate* c = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			KkcCandidate* _tmp8_;
			_c_index = _c_index + 1;
			_tmp4_ = _c_index;
			_tmp5_ = _c_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _c_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _c_index);
			c = (KkcCandidate*) _tmp7_;
			_tmp8_ = c;
			if (kkc_candidate_list_add (self, _tmp8_)) {
				retval = TRUE;
			}
			_g_object_unref0 (c);
		}
	}
	result = retval;
	return result;
}

KkcCandidate**
kkc_candidate_list_to_array (KkcCandidateList* self,
                             gint* result_length1)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_ = 0;
	gpointer* _tmp2_;
	KkcCandidate** _tmp3_;
	gint _tmp3__length1;
	KkcCandidate** result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_candidates;
	_tmp2_ = gee_collection_to_array ((GeeCollection*) _tmp0_, &_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp3__length1 = _tmp1_;
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}

static guint
kkc_candidate_list_get_page_start_cursor_pos (KkcCandidateList* self,
                                              guint pos)
{
	guint _tmp0_;
	guint _tmp1_;
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp0_ = self->priv->_page_size;
	_tmp1_ = self->priv->_page_size;
	result = (pos / _tmp0_) * _tmp1_;
	return result;
}

/**
         * Select a candidate in the current page.
         *
         * @param index_in_page cursor position in the page to select
         *
         * @return `true` if a candidate is selected, `false` otherwise
         */
gboolean
kkc_candidate_list_select_at (KkcCandidateList* self,
                              guint index_in_page)
{
	guint _tmp0_;
	guint page_offset = 0U;
	gint _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_page_size;
	_vala_assert (index_in_page < _tmp0_, "index_in_page < page_size");
	_tmp1_ = kkc_candidate_list_get_cursor_pos (self);
	_tmp2_ = _tmp1_;
	page_offset = kkc_candidate_list_get_page_start_cursor_pos (self, (guint) _tmp2_);
	_tmp3_ = kkc_candidate_list_get_size (self);
	_tmp4_ = _tmp3_;
	if ((page_offset + index_in_page) < ((guint) _tmp4_)) {
		self->priv->_cursor_pos = (gint) (page_offset + index_in_page);
		g_object_notify ((GObject*) self, "cursor-pos");
		kkc_candidate_list_select (self);
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

/**
         * Select the current candidate.
         */
void
kkc_candidate_list_select (KkcCandidateList* self)
{
	KkcCandidate* candidate = NULL;
	KkcCandidate* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = kkc_candidate_list_get (self, -1);
	candidate = _tmp0_;
	g_signal_emit (self, kkc_candidate_list_signals[KKC_CANDIDATE_LIST_SELECTED_SIGNAL], 0, candidate);
	_g_object_unref0 (candidate);
}

/**
         * Create a new CandidateList.
         *
         * @param page_start starting index of pagination
         * @param page_size page size
         * @param round whether to loop over the candidate list
         *
         * @return a new CandidateList
         */
KkcCandidateList*
kkc_candidate_list_construct (GType object_type,
                              guint page_start,
                              guint page_size,
                              gboolean round)
{
	KkcCandidateList * self = NULL;
	self = (KkcCandidateList*) g_object_new (object_type, NULL);
	kkc_candidate_list_set_page_start (self, page_start);
	kkc_candidate_list_set_page_size (self, page_size);
	kkc_candidate_list_set_round (self, round);
	return self;
}

KkcCandidateList*
kkc_candidate_list_new (guint page_start,
                        guint page_size,
                        gboolean round)
{
	return kkc_candidate_list_construct (KKC_TYPE_CANDIDATE_LIST, page_start, page_size, round);
}

/**
         * Select the first candidate.
         *
         * @return `true` if cursor position has changed, `false` otherwise
         */
gboolean
kkc_candidate_list_first (KkcCandidateList* self)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_candidates;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ > 0) {
		self->priv->_cursor_pos = 0;
		g_object_notify ((GObject*) self, "cursor-pos");
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

/**
         * Move cursor forward.
         *
         * @return `true` if cursor position has changed, `false` otherwise
         */
static gboolean
kkc_candidate_list_real_next (KkcCandidateList* self)
{
	gint _tmp0_;
	gint _tmp1_;
	guint _tmp2_;
	gboolean result;
	_tmp0_ = kkc_candidate_list_get_cursor_pos (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->priv->_page_start;
	if (((guint) _tmp1_) < _tmp2_) {
		result = kkc_candidate_list_cursor_down (self);
		return result;
	} else {
		result = kkc_candidate_list_page_down (self);
		return result;
	}
}

gboolean
kkc_candidate_list_next (KkcCandidateList* self)
{
	KkcCandidateListClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = KKC_CANDIDATE_LIST_GET_CLASS (self);
	if (_klass_->next) {
		return _klass_->next (self);
	}
	return FALSE;
}

/**
         * Move cursor backward.
         *
         * @return `true` if cursor position has changed, `false` otherwise
         */
static gboolean
kkc_candidate_list_real_previous (KkcCandidateList* self)
{
	gint _tmp0_;
	gint _tmp1_;
	guint _tmp2_;
	gboolean result;
	_tmp0_ = kkc_candidate_list_get_cursor_pos (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->priv->_page_start;
	if (((guint) _tmp1_) <= _tmp2_) {
		result = kkc_candidate_list_cursor_up (self);
		return result;
	} else {
		result = kkc_candidate_list_page_up (self);
		return result;
	}
}

gboolean
kkc_candidate_list_previous (KkcCandidateList* self)
{
	KkcCandidateListClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = KKC_CANDIDATE_LIST_GET_CLASS (self);
	if (_klass_->previous) {
		return _klass_->previous (self);
	}
	return FALSE;
}

static gboolean
kkc_candidate_list_cursor_move (KkcCandidateList* self,
                                gint step)
{
	gboolean _tmp0_ = FALSE;
	GeeArrayList* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->priv->_candidates;
	_tmp2_ = gee_collection_get_is_empty ((GeeCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = step == 0;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp4_ = self->priv->_round;
	if (_tmp4_) {
		gint pos = 0;
		GeeArrayList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		_tmp5_ = self->priv->_candidates;
		_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		pos = (self->priv->_cursor_pos + step) % _tmp7_;
		if (pos < 0) {
			GeeArrayList* _tmp8_;
			gint _tmp9_;
			gint _tmp10_;
			_tmp8_ = self->priv->_candidates;
			_tmp9_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp8_);
			_tmp10_ = _tmp9_;
			pos += _tmp10_;
		}
		self->priv->_cursor_pos = pos;
		g_object_notify ((GObject*) self, "cursor-pos");
		result = TRUE;
		return result;
	} else {
		gint pos = 0;
		gboolean _tmp11_ = FALSE;
		pos = self->priv->_cursor_pos + step;
		if (0 <= pos) {
			GeeArrayList* _tmp12_;
			gint _tmp13_;
			gint _tmp14_;
			_tmp12_ = self->priv->_candidates;
			_tmp13_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp12_);
			_tmp14_ = _tmp13_;
			_tmp11_ = pos < _tmp14_;
		} else {
			_tmp11_ = FALSE;
		}
		if (_tmp11_) {
			self->priv->_cursor_pos = pos;
			g_object_notify ((GObject*) self, "cursor-pos");
			result = TRUE;
			return result;
		}
	}
	result = FALSE;
	return result;
}

/**
         * Move cursor to the previous candidate.
         *
         * @return `true` if cursor position has changed, `false` otherwise.
         */
gboolean
kkc_candidate_list_cursor_up (KkcCandidateList* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = kkc_candidate_list_cursor_move (self, -1);
	return result;
}

/**
         * Move cursor to the next candidate.
         *
         * @return `true` if cursor position has changed, `false` otherwise
         */
gboolean
kkc_candidate_list_cursor_down (KkcCandidateList* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = kkc_candidate_list_cursor_move (self, 1);
	return result;
}

static gboolean
kkc_candidate_list_page_move (KkcCandidateList* self,
                              gint step)
{
	gboolean _tmp0_ = FALSE;
	GeeArrayList* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->priv->_candidates;
	_tmp2_ = gee_collection_get_is_empty ((GeeCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = step == 0;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp4_ = self->priv->_round;
	if (_tmp4_) {
		guint pos = 0U;
		guint _tmp5_;
		GeeArrayList* _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		_tmp5_ = self->priv->_page_size;
		_tmp6_ = self->priv->_candidates;
		_tmp7_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp6_);
		_tmp8_ = _tmp7_;
		pos = (self->priv->_cursor_pos + (_tmp5_ * step)) % _tmp8_;
		if (pos < ((guint) 0)) {
			GeeArrayList* _tmp9_;
			gint _tmp10_;
			gint _tmp11_;
			_tmp9_ = self->priv->_candidates;
			_tmp10_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp9_);
			_tmp11_ = _tmp10_;
			pos += (guint) _tmp11_;
		}
		pos = kkc_candidate_list_get_page_start_cursor_pos (self, pos);
		if (pos != ((guint) self->priv->_cursor_pos)) {
			self->priv->_cursor_pos = (gint) pos;
			g_object_notify ((GObject*) self, "cursor-pos");
			result = TRUE;
			return result;
		}
	} else {
		guint pos = 0U;
		guint _tmp12_;
		gboolean _tmp13_ = FALSE;
		_tmp12_ = self->priv->_page_size;
		pos = self->priv->_cursor_pos + (_tmp12_ * step);
		if (((guint) 0) <= pos) {
			GeeArrayList* _tmp14_;
			gint _tmp15_;
			gint _tmp16_;
			_tmp14_ = self->priv->_candidates;
			_tmp15_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp14_);
			_tmp16_ = _tmp15_;
			_tmp13_ = pos < ((guint) _tmp16_);
		} else {
			_tmp13_ = FALSE;
		}
		if (_tmp13_) {
			pos = kkc_candidate_list_get_page_start_cursor_pos (self, pos);
			if (pos != ((guint) self->priv->_cursor_pos)) {
				self->priv->_cursor_pos = (gint) pos;
				g_object_notify ((GObject*) self, "cursor-pos");
				result = TRUE;
				return result;
			}
		}
	}
	result = FALSE;
	return result;
}

/**
         * Move cursor to the previous page.
         *
         * @return `true` if cursor position has changed, `false` otherwise
         */
gboolean
kkc_candidate_list_page_up (KkcCandidateList* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = kkc_candidate_list_page_move (self, -1);
	return result;
}

/**
         * Move cursor to the next page.
         *
         * @return `true` if cursor position has changed, `false` otherwise
         */
gboolean
kkc_candidate_list_page_down (KkcCandidateList* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = kkc_candidate_list_page_move (self, 1);
	return result;
}

gint
kkc_candidate_list_get_cursor_pos (KkcCandidateList* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_cursor_pos;
	return result;
}

void
kkc_candidate_list_set_cursor_pos (KkcCandidateList* self,
                                   gint value)
{
	g_return_if_fail (self != NULL);
	self->priv->_cursor_pos = value;
	g_object_notify_by_pspec ((GObject *) self, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_CURSOR_POS_PROPERTY]);
}

gint
kkc_candidate_list_get_size (KkcCandidateList* self)
{
	gint result;
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = self->priv->_candidates;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

guint
kkc_candidate_list_get_page_start (KkcCandidateList* self)
{
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	result = self->priv->_page_start;
	return result;
}

void
kkc_candidate_list_set_page_start (KkcCandidateList* self,
                                   guint value)
{
	guint old_value;
	g_return_if_fail (self != NULL);
	old_value = kkc_candidate_list_get_page_start (self);
	if (old_value != value) {
		self->priv->_page_start = value;
		g_object_notify_by_pspec ((GObject *) self, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_PAGE_START_PROPERTY]);
	}
}

guint
kkc_candidate_list_get_page_size (KkcCandidateList* self)
{
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	result = self->priv->_page_size;
	return result;
}

void
kkc_candidate_list_set_page_size (KkcCandidateList* self,
                                  guint value)
{
	guint old_value;
	g_return_if_fail (self != NULL);
	old_value = kkc_candidate_list_get_page_size (self);
	if (old_value != value) {
		self->priv->_page_size = value;
		g_object_notify_by_pspec ((GObject *) self, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_PAGE_SIZE_PROPERTY]);
	}
}

gboolean
kkc_candidate_list_get_round (KkcCandidateList* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_round;
	return result;
}

void
kkc_candidate_list_set_round (KkcCandidateList* self,
                              gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = kkc_candidate_list_get_round (self);
	if (old_value != value) {
		self->priv->_round = value;
		g_object_notify_by_pspec ((GObject *) self, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_ROUND_PROPERTY]);
	}
}

gboolean
kkc_candidate_list_get_page_visible (KkcCandidateList* self)
{
	gboolean result;
	guint _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_page_start;
	result = self->priv->_cursor_pos >= ((gint) _tmp0_);
	return result;
}

static void
kkc_candidate_list_class_init (KkcCandidateListClass * klass,
                               gpointer klass_data)
{
	kkc_candidate_list_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcCandidateList_private_offset);
	((KkcCandidateListClass *) klass)->next = (gboolean (*) (KkcCandidateList*)) kkc_candidate_list_real_next;
	((KkcCandidateListClass *) klass)->previous = (gboolean (*) (KkcCandidateList*)) kkc_candidate_list_real_previous;
	G_OBJECT_CLASS (klass)->get_property = _vala_kkc_candidate_list_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_kkc_candidate_list_set_property;
	G_OBJECT_CLASS (klass)->finalize = kkc_candidate_list_finalize;
	/**
	         * Current cursor position.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_CANDIDATE_LIST_CURSOR_POS_PROPERTY, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_CURSOR_POS_PROPERTY] = g_param_spec_int ("cursor-pos", "cursor-pos", "cursor-pos", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	         * The number of candidate in the candidate list.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_CANDIDATE_LIST_SIZE_PROPERTY, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_SIZE_PROPERTY] = g_param_spec_int ("size", "size", "size", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	         * Starting index of paging.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_CANDIDATE_LIST_PAGE_START_PROPERTY, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_PAGE_START_PROPERTY] = g_param_spec_uint ("page-start", "page-start", "page-start", 0, G_MAXUINT, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	         * Page size.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_CANDIDATE_LIST_PAGE_SIZE_PROPERTY, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_PAGE_SIZE_PROPERTY] = g_param_spec_uint ("page-size", "page-size", "page-size", 0, G_MAXUINT, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	         * Flag to indicate whether to loop over the candidates.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_CANDIDATE_LIST_ROUND_PROPERTY, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_ROUND_PROPERTY] = g_param_spec_boolean ("round", "round", "round", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	         * Flag to indicate whether page (lookup table) is visible.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_CANDIDATE_LIST_PAGE_VISIBLE_PROPERTY, kkc_candidate_list_properties[KKC_CANDIDATE_LIST_PAGE_VISIBLE_PROPERTY] = g_param_spec_boolean ("page-visible", "page-visible", "page-visible", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	         * Signal emitted when candidates are filled and ready for traversal.
	         */
	kkc_candidate_list_signals[KKC_CANDIDATE_LIST_POPULATED_SIGNAL] = g_signal_new ("populated", KKC_TYPE_CANDIDATE_LIST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	/**
	         * Signal emitted when a candidate is selected.
	         *
	         * @param candidate selected candidate
	         */
	kkc_candidate_list_signals[KKC_CANDIDATE_LIST_SELECTED_SIGNAL] = g_signal_new ("selected", KKC_TYPE_CANDIDATE_LIST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, KKC_TYPE_CANDIDATE);
}

static void
kkc_candidate_list_instance_init (KkcCandidateList * self,
                                  gpointer klass)
{
	GeeArrayList* _tmp0_;
	GeeHashMap* _tmp1_;
	self->priv = kkc_candidate_list_get_instance_private (self);
	_tmp0_ = gee_array_list_new (KKC_TYPE_CANDIDATE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->_candidates = _tmp0_;
	_tmp1_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, KKC_TYPE_CANDIDATE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->seen = (GeeMap*) _tmp1_;
}

static void
kkc_candidate_list_finalize (GObject * obj)
{
	KkcCandidateList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_CANDIDATE_LIST, KkcCandidateList);
	_g_object_unref0 (self->priv->_candidates);
	_g_object_unref0 (self->priv->seen);
	G_OBJECT_CLASS (kkc_candidate_list_parent_class)->finalize (obj);
}

/**
     * Object representing a candidate list.
     */
static GType
kkc_candidate_list_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcCandidateListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_candidate_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcCandidateList), 0, (GInstanceInitFunc) kkc_candidate_list_instance_init, NULL };
	GType kkc_candidate_list_type_id;
	kkc_candidate_list_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcCandidateList", &g_define_type_info, 0);
	KkcCandidateList_private_offset = g_type_add_instance_private (kkc_candidate_list_type_id, sizeof (KkcCandidateListPrivate));
	return kkc_candidate_list_type_id;
}

GType
kkc_candidate_list_get_type (void)
{
	static volatile gsize kkc_candidate_list_type_id__once = 0;
	if (g_once_init_enter (&kkc_candidate_list_type_id__once)) {
		GType kkc_candidate_list_type_id;
		kkc_candidate_list_type_id = kkc_candidate_list_get_type_once ();
		g_once_init_leave (&kkc_candidate_list_type_id__once, kkc_candidate_list_type_id);
	}
	return kkc_candidate_list_type_id__once;
}

static void
_vala_kkc_candidate_list_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	KkcCandidateList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_CANDIDATE_LIST, KkcCandidateList);
	switch (property_id) {
		case KKC_CANDIDATE_LIST_CURSOR_POS_PROPERTY:
		g_value_set_int (value, kkc_candidate_list_get_cursor_pos (self));
		break;
		case KKC_CANDIDATE_LIST_SIZE_PROPERTY:
		g_value_set_int (value, kkc_candidate_list_get_size (self));
		break;
		case KKC_CANDIDATE_LIST_PAGE_START_PROPERTY:
		g_value_set_uint (value, kkc_candidate_list_get_page_start (self));
		break;
		case KKC_CANDIDATE_LIST_PAGE_SIZE_PROPERTY:
		g_value_set_uint (value, kkc_candidate_list_get_page_size (self));
		break;
		case KKC_CANDIDATE_LIST_ROUND_PROPERTY:
		g_value_set_boolean (value, kkc_candidate_list_get_round (self));
		break;
		case KKC_CANDIDATE_LIST_PAGE_VISIBLE_PROPERTY:
		g_value_set_boolean (value, kkc_candidate_list_get_page_visible (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_kkc_candidate_list_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	KkcCandidateList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_CANDIDATE_LIST, KkcCandidateList);
	switch (property_id) {
		case KKC_CANDIDATE_LIST_CURSOR_POS_PROPERTY:
		kkc_candidate_list_set_cursor_pos (self, g_value_get_int (value));
		break;
		case KKC_CANDIDATE_LIST_PAGE_START_PROPERTY:
		kkc_candidate_list_set_page_start (self, g_value_get_uint (value));
		break;
		case KKC_CANDIDATE_LIST_PAGE_SIZE_PROPERTY:
		kkc_candidate_list_set_page_size (self, g_value_get_uint (value));
		break;
		case KKC_CANDIDATE_LIST_ROUND_PROPERTY:
		kkc_candidate_list_set_round (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

