org.solovyev.android.menu.MenuImpl Maven / Gradle / Ivy
/*
* 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 extends T> menuItems;
@NotNull
public static , D> AMenu newInstance(T... menuItems) {
return new MenuImpl(menuItems);
}
@NotNull
public static , D> AMenu newInstance(@NotNull List extends T> menuItems) {
return new MenuImpl(menuItems);
}
private MenuImpl(T... menuItems) {
this(CollectionsUtils.asList(menuItems));
}
private MenuImpl(@NotNull List extends T> 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