/* * The contents of this file are subject to the terms of the Common Development and * Distribution License (the License). You may not use this file except in compliance with the * License. * * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the * specific language governing permission and limitations under the License. * * When distributing Covered Software, include this CDDL Header Notice in each file and include * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions Copyright [year] [name of copyright owner]". * * Copyright 2008 Sun Microsystems, Inc. * Portions Copyright 2014-2015 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 values.iterator().next();
}
return null;
}
/**
* 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;
}
@Override
public String toString() {
return getClass().getSimpleName() + "(type=" + type + ", values=" + values + ")";
}
}