All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.solovyev.android.menu.MenuImpl Maven / Gradle / Ivy

There is a newer version: 1.1.18
Show newest version
/*
 * Copyright (c) 2009-2011. Created by serso aka se.solovyev.
 * For more information, please, contact [email protected]
 * or visit http://se.solovyev.org
 */

package org.solovyev.android.menu;

import android.content.Context;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.collections.CollectionsUtils;

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

/**
* User: serso
* Date: 12/18/11
* Time: 1:31 PM
*/
public class MenuImpl, D> implements AMenu {

	private final List menuItems;

	@NotNull
	public static , D> AMenu newInstance(T... menuItems) {
		return new MenuImpl(menuItems);
	}

	@NotNull
	public static , D> AMenu newInstance(@NotNull List menuItems) {
		return new MenuImpl(menuItems);
	}

	private MenuImpl(T... menuItems) {
		this(CollectionsUtils.asList(menuItems));
	}

	private MenuImpl(@NotNull List menuItems) {
		this.menuItems = new ArrayList(menuItems);
	}

	@Override
	@Nullable
	public T itemAt(int i) {
		if (i >= 0 && i < menuItems.size()) {
			return menuItems.get(i);
		} else {
			return null;
		}
	}

	@Override
	@NotNull
	public CharSequence[] getMenuCaptions(@NotNull final Context context) {
		final CharSequence[] result = new CharSequence[this.menuItems.size()];
		for (int i = 0; i < this.menuItems.size(); i++) {
			result[i] = this.menuItems.get(i).getCaption(context);
		}
		return result;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy