Example usage for java.util Optional get

List of usage examples for java.util Optional get

Introduction

In this page you can find the example usage for java.util Optional get.

Prototype

public T get() 

Source Link

Document

If a value is present, returns the value, otherwise throws NoSuchElementException .

Usage

From source file:dpfmanager.shell.modules.messages.MessagesModule.java

private void askForClosePeriodical() {
    ResourceBundle bundle = DPFManagerProperties.getBundle();
    Platform.runLater(new Runnable() {
        @Override// w ww .  j  a  v  a  2 s  .c  o m
        public void run() {
            Alert alert = AlertsManager.createAskAlert(bundle.getString("askAlertPeriodical"),
                    bundle.getString("askAlertPeriodicalContent"));
            Optional<ButtonType> result = alert.showAndWait();
            if (result.get().getButtonData().equals(ButtonBar.ButtonData.YES)) {
                closeNow();
            }
        }
    });
}

From source file:dpfmanager.shell.modules.messages.MessagesModule.java

private void askForCloseConformances() {
    ResourceBundle bundle = DPFManagerProperties.getBundle();
    Platform.runLater(new Runnable() {
        @Override//from w  ww.j a v  a2 s . c o  m
        public void run() {
            Alert alert = AlertsManager.createAskAlert(bundle.getString("askAlertConformances"),
                    bundle.getString("askAlertConformancesContent"));
            Optional<ButtonType> result = alert.showAndWait();
            if (result.get().getButtonData().equals(ButtonBar.ButtonData.YES)) {
                closeNow();
            }
        }
    });
}

From source file:dpfmanager.shell.modules.messages.MessagesModule.java

private void askForCloseThreading() {
    ResourceBundle bundle = DPFManagerProperties.getBundle();
    Platform.runLater(new Runnable() {
        @Override//  www  .  j av  a 2s. c o m
        public void run() {
            Alert alert = AlertsManager.createAskAlert(bundle.getString("askAlertRunning"),
                    bundle.getString("askAlertQuestion"));
            Optional<ButtonType> result = alert.showAndWait();
            if (result.get().getButtonData().equals(ButtonBar.ButtonData.YES)) {
                context.send(GuiConfig.PERSPECTIVE_PERIODICAL + "." + GuiConfig.COMPONENT_PERIODICAL,
                        new CloseMessage(CloseMessage.Type.PERIODICAL));
            }
        }
    });
}

From source file:org.openmhealth.dsu.service.EndUserUserDetailsServiceImpl.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

    Optional<EndUser> user = endUserService.findUser(username);

    if (!user.isPresent()) {
        throw new UsernameNotFoundException("A user with username '" + username + "' doesn't exist.");
    }//from   w  w  w . j  a  v a 2 s.c  o  m

    return new EndUserUserDetails(user.get().getUsername(), user.get().getPasswordHash());
}

From source file:org.anhonesteffort.p25.ACAP25.java

private Optional<Double> findActiveControlChannel(Integer systemId, Integer systemWacn, Site site) {
    for (Double channelFreq : site.getControlChannels()) {
        P25ChannelSpec channelSpec = new P25ChannelSpec(channelFreq);
        P25Channel channel = new P25Channel(channelSpec);
        ControlChannelQualifier channelQualifier = new ControlChannelQualifier(controlChannelPool,
                samplesController, channel, systemId, systemWacn);

        try {//ww w .j a  v a  2 s.  c  o m

            Future<Optional<Double>> channelQualified = controlChannelPool.submit(channelQualifier);
            Optional<Double> controlFreq = channelQualified.get();

            if (controlFreq.isPresent()) {
                log.info(
                        "found active control channel at " + controlFreq.get() + " for site " + site.getName());
                return Optional.of(controlFreq.get());
            }

        } catch (InterruptedException | ExecutionException e) {
            log.error("error while identifying active control channels, exiting", e);
            java.lang.System.exit(1);
        }
    }

    return Optional.empty();
}

From source file:com.macrossx.wechat.impl.WechatMenuHelper.java

/**
 * delete menu//from   www . j a  va  2  s  . com
 * 
 * @param menu
 *            menu to create
 *            {@link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141015&token=&lang=zh_CN}
 * @return true sucess
 */
public boolean deleteMenu() {
    try {
        Optional<WechatAccessToken> token = wechatHelper.getAccessToken();
        if (token.isPresent()) {
            WechatAccessToken accessToken = token.get();

            HttpGet httpGet = new HttpGet();
            httpGet.setURI(new URI(
                    MessageFormat.format(WechatConstants.MENU_DELETE_URL, accessToken.getAccess_token())));
            Optional<WechatResponseObj> response = new WechatHttpClient().send(httpGet,
                    WechatResponseObj.class);
            if (response.isPresent()) {
                WechatResponseObj e = response.get();
                log.info(e.toString());
                if (0 == e.getErrcode()) {
                    return true;
                }
            }
        }
    } catch (URISyntaxException e) {
        log.info(e.getMessage());
    }
    return false;
}

From source file:io.kloudwork.controller.LoginController.java

public String postLogin(Request request, Response response) throws IOException, FileUploadException {
    boolean matched = false;

    Optional<User> userOptional = userRepository.findByUserName(request.queryParams("username"));

    if (userOptional.isPresent()) {
        String userPassword = userOptional.get().getPassword();
        matched = BCrypt.checkpw(request.queryParams("password"), userPassword);
    }/* w  w w.j a v  a  2 s .  c o m*/

    if (!matched) {
        throw Spark.halt(401);
    }

    User user = userOptional.get();

    final Session session = request.session();
    session.attribute("username", user.getUsername());
    session.attribute("csrf-token", generateCSRFToken(64));

    response.status(200);
    return "Logged in";
}

From source file:org.openwms.tms.service.TransportationServiceImpl.java

/**
 * {@inheritDoc}/*from w w w  .  j av a2 s . c  om*/
 */
@Override
public int getNoTransportOrdersToTarget(String target, String... states) {
    int i = 0;
    for (TargetResolver<Target> tr : targetResolvers) {
        Optional<Target> t = tr.resolve(target);
        if (t.isPresent()) {
            i = +tr.getHandler().getNoTOToTarget(t.get());
        }
    }
    return i;
}

From source file:org.obiba.mica.micaConfig.rest.EntityConfigResource.java

@GET
@Path("/form-custom")
public U getComplete(@Context UriInfo uriInfo) {

    Optional<T> optionalConfig = getConfigService().findPartial();

    if (!optionalConfig.isPresent())
        throw NoSuchEntityException.withPath(EntityConfig.class, uriInfo.getPath());

    return asDto(optionalConfig.get());
}

From source file:com.macrossx.wechat.impl.WechatMenuHelper.java

/**
 * create menu//ww  w  . j ava 2 s  .  c o  m
 * 
 * @param menu
 *            menu to create
 *            {@link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013&token=&lang=zh_CN}
 * @return true sucess
 */
@Override
public boolean createMenu(List<WechatButton> menu) {
    try {
        Map<String, List<WechatButton>> menus = Maps.newConcurrentMap();
        menus.put("button", menu);
        Optional<WechatAccessToken> token = wechatHelper.getAccessToken();
        if (token.isPresent()) {
            WechatAccessToken accessToken = token.get();
            HttpPost httpPost = new HttpPost();
            httpPost.setEntity(new StringEntity(new Gson().toJson(menus), "utf-8"));
            httpPost.setURI(new URI(
                    MessageFormat.format(WechatConstants.MENU_CREATE_URL, accessToken.getAccess_token())));
            Optional<WechatResponseObj> response = new WechatHttpClient().send(httpPost,
                    WechatResponseObj.class);
            if (response.isPresent()) {
                WechatResponseObj e = response.get();
                log.info(e.toString());
                if (0 == e.getErrcode()) {
                    return true;
                }
            }
        }
    } catch (URISyntaxException e) {
        log.info(e.getMessage());
    }
    return false;
}