/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt * or http://forgerock.org/license/CDDLv1.0.html. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at legal-notices/CDDLv1_0.txt. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Copyright 2008 Sun Microsystems, Inc. * Portions Copyright 2014 ForgeRock AS */ package com.forgerock.opendj.cli; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; /** * The result of running a {@link Menu}. The result indicates to the * application how it should proceed: *
Void if success results should
* not contain values.
*/
public final class MenuResultVoid if success results
* should not contain values.
* @return Returns a new menu result indicating that the menu should be displayed again.
*/
public static Void if success results
* should not contain values.
* @return Returns a new menu result indicating that the user chose to cancel any task currently in progress and go
* back to the previous main menu if applicable.
*/
public static Void if success results
* should not contain values.
* @return Returns a new menu result indicating that the user chose to quit the application and cancel all
* outstanding tasks.
*/
public static Void if success results
* should not contain values.
* @return Returns a new menu result indicating that the user chose to apply any task currently in progress and go
* back to the previous menu if applicable.The menu result will not contain any result values.
*/
public static null if there was no result value or if this is not a
* success menu result.
* @see #isSuccess()
*/
public T getValue() {
if (values.isEmpty()) {
return null;
} else {
return values.iterator().next();
}
}
/**
* Gets the menu result values if this is a menu result indicating success.
*
* @return Returns the menu result values, which may be empty if there were no result values or if this is not a
* success menu result.
* @see #isSuccess()
*/
public Collectiontrue if this menu result indicates that the menu should be displayed again.
*/
public boolean isAgain() {
return type == Type.AGAIN;
}
/**
* Determines if this menu result indicates that the user chose to cancel any task currently in progress and go back
* to the previous main menu if applicable.
*
* @return Returns true if this menu result indicates that the user chose to cancel any task currently
* in progress and go back to the previous main menu if applicable.
*/
public boolean isCancel() {
return type == Type.CANCEL;
}
/**
* Determines if this menu result indicates that the user chose to quit the application and cancel all outstanding
* tasks.
*
* @return Returns true if this menu result indicates that the user chose to quit the application and
* cancel all outstanding tasks.
*/
public boolean isQuit() {
return type == Type.QUIT;
}
/**
* Determines if this menu result indicates that the user chose to apply any task currently in progress and go back
* to the previous menu if applicable. Any result values can be retrieved using the {@link #getValue()} or
* {@link #getValues()} methods.
*
* @return Returns true if this menu result indicates that the user chose to apply any task currently
* in progress and go back to the previous menu if applicable.
* @see #getValue()
* @see #getValues()
*/
public boolean isSuccess() {
return type == Type.SUCCESS;
}
}