List of usage examples for org.apache.commons.lang3 EnumUtils isValidEnum
public static <E extends Enum<E>> boolean isValidEnum(final Class<E> enumClass, final String enumName)
Checks if the specified name is a valid enum for the class.
This method differs from Enum#valueOf in that checks if the name is a valid enum without needing to catch the exception.
From source file:de.mpg.imeji.presentation.license.LicenseEditor.java
/** * Listener for when the license menu is changed *//*from w w w . ja va 2s .c om*/ public void licenseMenuListener() { if (EnumUtils.isValidEnum(ImejiLicenses.class, licenseName)) { final ImejiLicenses lic = ImejiLicenses.valueOf(licenseName); this.licenseUrl = lic.getUrl(); this.licenseLabel = lic.getLabel(); } else { this.licenseName = null; this.licenseUrl = null; this.licenseLabel = null; } }
From source file:com.linkedin.pinot.common.data.DateTimeFormatUnitSpec.java
public DateTimeFormatUnitSpec(String unit) { if (!isValidUnitSpec(unit)) { throw new IllegalArgumentException("Unit must belong to enum TimeUnit or DateTimeTransformUnit"); }/*w w w .j a v a 2 s. c o m*/ if (EnumUtils.isValidEnum(TimeUnit.class, unit)) { _timeUnit = TimeUnit.valueOf(unit); } if (EnumUtils.isValidEnum(DateTimeTransformUnit.class, unit)) { _dateTimeTransformUnit = DateTimeTransformUnit.valueOf(unit); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.MMXWakeupNSHandler.java
private boolean isValidCommand(String command) { return command != null && !command.isEmpty() && EnumUtils.isValidEnum(Constants.PingPongCommand.class, command.toLowerCase()); }
From source file:de.mpg.imeji.presentation.license.LicenseEditor.java
/** * Get the license of the entered via the component * * @param lic/*w ww.ja v a 2 s . c om*/ * @return */ public License getLicense() { License license = new License(); if (showInput) { license.setName(customLicenseName); license.setUrl(customLicenseUrl); license.setLabel(customLicenseName); } else if (EnumUtils.isValidEnum(ImejiLicenses.class, licenseName)) { license = new License(ImejiLicenses.valueOf(licenseName)); } return license; }
From source file:io.lavagna.service.NotificationService.java
private List<String> composeCardSection(List<Event> events, EventsContext context) { ////from w w w . java2 s . co m List<String> res = new ArrayList<>(); for (Event e : events) { if (EnumUtils.isValidEnum(SupportedEventType.class, e.getEvent().toString())) { ImmutablePair<String, String[]> message = SupportedEventType.valueOf(e.getEvent().toString()) .toKeyAndParam(e, context, cardDataRepository); res.add(messageSource.getMessage(message.getKey(), message.getValue(), Locale.ENGLISH)); } } return res; }
From source file:com.vmware.photon.controller.deployer.dcp.task.WaitForServiceTaskService.java
/** * This method performs document owner operations in response to a patch * operation.// w w w .j ava2 s . c om * * @param currentState */ private void processStartedStage(final State currentState) { final Service service = this; Operation.CompletionHandler handler = new Operation.CompletionHandler() { @Override public void handle(Operation operation, Throwable throwable) { if (null != throwable) { failTask(throwable); return; } try { VmService.State vmState = operation.getBody(VmService.State.class); if (EnumUtils.isValidEnum(ContainersConfig.ContainerType.class, currentState.containerType)) { ContainersConfig.ContainerType containerType = ContainersConfig.ContainerType .valueOf(currentState.containerType); final HealthChecker healthChecker = getHealthCheckHelperFactory() .create(service, containerType, vmState.ipAddress).getHealthChecker(); final AtomicInteger retryCounter = new AtomicInteger(currentState.maxRetries); scheduleHealthCheckQuery(currentState, healthChecker, retryCounter); } else { // Assume success sendStageProgressPatch(TaskState.TaskStage.FINISHED); } } catch (Throwable t) { failTask(t); } } }; Operation get = Operation.createGet(UriUtils.buildUri(getHost(), currentState.vmServiceLink)) .setCompletion(handler); sendRequest(get); }
From source file:com.vmware.photon.controller.deployer.dcp.workflow.CreateAndValidateContainerWorkflowService.java
/** * This method takes a container template and calls the corresponding * child task./*from ww w.ja v a2s. c o m*/ * * @param currentState Supplies the current state object. * @param containerState Supplies the container service state object. * @param containerTemplateState Supplies the container template service state object. */ private void waitForService(final State currentState, final ContainerService.State containerState, final ContainerTemplateService.State containerTemplateState) { if (EnumUtils.isValidEnum(ContainersConfig.ContainerType.class, containerTemplateState.name)) { ServiceUtils.logInfo(this, "Waiting for: %s start", containerTemplateState.name); final Service service = this; FutureCallback<WaitForServiceTaskService.State> callback = new FutureCallback<WaitForServiceTaskService.State>() { @Override public void onSuccess(@Nullable WaitForServiceTaskService.State result) { if (result.taskState.stage == TaskState.TaskStage.FAILED) { State state = buildPatch(TaskState.TaskStage.FAILED, null, null); state.taskState.failure = result.taskState.failure; TaskUtils.sendSelfPatch(service, state); return; } if (result.taskState.stage == TaskState.TaskStage.CANCELLED) { TaskUtils.sendSelfPatch(service, buildPatch(TaskState.TaskStage.CANCELLED, null, null)); return; } TaskUtils.sendSelfPatch(service, buildPatch(TaskState.TaskStage.FINISHED, null, null)); } @Override public void onFailure(Throwable t) { failTask(t); } }; WaitForServiceTaskService.State startState = new WaitForServiceTaskService.State(); startState.vmServiceLink = containerState.vmServiceLink; startState.containerType = containerTemplateState.name; startState.taskPollDelay = currentState.taskPollDelay; startState.maxRetries = currentState.maxRetries; TaskUtils.startTaskAsync(this, WaitForServiceTaskFactoryService.SELF_LINK, startState, (state) -> TaskUtils.finalTaskStages.contains(state.taskState.stage), WaitForServiceTaskService.State.class, currentState.taskPollDelay, callback); } else { ServiceUtils.logInfo(this, "Non-standard container template: %s, will skip wait!", containerTemplateState.name); TaskUtils.sendSelfPatch(this, buildPatch(TaskState.TaskStage.FINISHED, null, null)); } }
From source file:com.linkedin.pinot.controller.api.resources.PinotTableRestletResource.java
@POST @Produces(MediaType.APPLICATION_JSON)/*from w w w . j a v a 2 s .co m*/ @Path("/tables/{tableName}/rebalance") @ApiOperation(value = "Rebalances segments of a table across servers", notes = "Rebalances segments of a table across servers") public String rebalance( @ApiParam(value = "Name of the table to rebalance") @Nonnull @PathParam("tableName") String tableName, @ApiParam(value = "offline|realtime") @Nonnull @QueryParam("type") String tableType, @ApiParam(value = "true|false") @Nonnull @QueryParam("dryrun") Boolean dryRun, @ApiParam(value = "true|false") @DefaultValue("false") @QueryParam("includeConsuming") Boolean includeConsuming) { if (tableType != null && !EnumUtils.isValidEnum(CommonConstants.Helix.TableType.class, tableType.toUpperCase())) { throw new ControllerApplicationException(LOGGER, "Illegal table type " + tableType, Response.Status.BAD_REQUEST); } Configuration rebalanceUserConfig = new PropertiesConfiguration(); rebalanceUserConfig.addProperty(RebalanceUserConfigConstants.DRYRUN, dryRun); rebalanceUserConfig.addProperty(RebalanceUserConfigConstants.INCLUDE_CONSUMING, includeConsuming); JSONObject jsonObject = null; try { jsonObject = _pinotHelixResourceManager.rebalanceTable(tableName, CommonConstants.Helix.TableType.valueOf(tableType.toUpperCase()), rebalanceUserConfig); } catch (JSONException e) { throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } catch (InvalidConfigException e) { throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.BAD_REQUEST); } return jsonObject.toString(); }
From source file:net.sf.dynamicreports.jasper.transformation.ConstantTransform.java
public static HyperlinkTypeEnum hyperLinkType(String hyperLinkType) { if (hyperLinkType == null || !EnumUtils.isValidEnum(HyperLinkType.class, hyperLinkType)) { return null; }//from w w w . j a va 2 s .c om HyperLinkType type = HyperLinkType.valueOf(hyperLinkType); switch (type) { case NONE: return HyperlinkTypeEnum.NONE; case REFERENCE: return HyperlinkTypeEnum.REFERENCE; case LOCAL_ANCHOR: return HyperlinkTypeEnum.LOCAL_ANCHOR; case LOCAL_PAGE: return HyperlinkTypeEnum.LOCAL_PAGE; case REMOTE_ANCHOR: return HyperlinkTypeEnum.REMOTE_ANCHOR; case REMOTE_PAGE: return HyperlinkTypeEnum.REMOTE_PAGE; default: throw new JasperDesignException("HyperLinkType " + type.name() + " not supported"); } }
From source file:net.sf.dynamicreports.jasper.transformation.ConstantTransform.java
public static HyperlinkTargetEnum hyperLinkTarget(String hyperLinkTarget) { if (hyperLinkTarget == null || !EnumUtils.isValidEnum(HyperLinkTarget.class, hyperLinkTarget)) { return null; }/*ww w.j a v a 2s .c om*/ HyperLinkTarget target = HyperLinkTarget.valueOf(hyperLinkTarget); switch (target) { case NONE: return HyperlinkTargetEnum.NONE; case SELF: return HyperlinkTargetEnum.SELF; case BLANK: return HyperlinkTargetEnum.BLANK; case PARENT: return HyperlinkTargetEnum.PARENT; case TOP: return HyperlinkTargetEnum.TOP; default: throw new JasperDesignException("HyperLinkTarget " + target.name() + " not supported"); } }