Example usage for java.text NumberFormat setMaximumFractionDigits

List of usage examples for java.text NumberFormat setMaximumFractionDigits

Introduction

In this page you can find the example usage for java.text NumberFormat setMaximumFractionDigits.

Prototype

public void setMaximumFractionDigits(int newValue) 

Source Link

Document

Sets the maximum number of digits allowed in the fraction portion of a number.

Usage

From source file:org.red5.io.m4a.impl.M4AReader.java

/**
 * This handles the moov atom being at the beginning or end of the file, so the mdat may also be before or after the moov atom.
 *///from  www .jav  a 2  s .  c om
public void decodeHeader() {
    try {
        // we want a moov and an mdat, anything else will throw the invalid file type error
        MovieBox moov = isoFile.getBoxes(MovieBox.class).get(0);
        if (log.isDebugEnabled()) {
            log.debug("moov children: {}", moov.getBoxes().size());
            MP4Reader.dumpBox(moov);
        }
        // get the movie header
        MovieHeaderBox mvhd = moov.getMovieHeaderBox();
        // get the timescale and duration
        timeScale = mvhd.getTimescale();
        duration = mvhd.getDuration();
        log.debug("Time scale {} Duration {}", timeScale, duration);
        double lengthInSeconds = (double) duration / timeScale;
        log.debug("Seconds {}", lengthInSeconds);
        // look at the tracks
        log.debug("Tracks: {}", moov.getTrackCount());
        List<TrackBox> tracks = moov.getBoxes(TrackBox.class); // trak
        for (TrackBox trak : tracks) {
            if (log.isDebugEnabled()) {
                log.debug("trak children: {}", trak.getBoxes().size());
                MP4Reader.dumpBox(trak);
            }
            TrackHeaderBox tkhd = trak.getTrackHeaderBox(); // tkhd
            log.debug("Track id: {}", tkhd.getTrackId());
            MediaBox mdia = trak.getMediaBox(); // mdia
            long scale = 0;
            if (mdia != null) {
                if (log.isDebugEnabled()) {
                    log.debug("mdia children: {}", mdia.getBoxes().size());
                    MP4Reader.dumpBox(mdia);
                }
                MediaHeaderBox mdhd = mdia.getMediaHeaderBox(); // mdhd
                if (mdhd != null) {
                    log.debug("Media data header atom found");
                    // this will be for either video or audio depending media info
                    scale = mdhd.getTimescale();
                    log.debug("Time scale {}", scale);
                }
                HandlerBox hdlr = mdia.getHandlerBox(); // hdlr
                if (hdlr != null) {
                    String hdlrType = hdlr.getHandlerType();
                    if ("soun".equals(hdlrType)) {
                        if (scale > 0) {
                            audioTimeScale = scale * 1.0;
                            log.debug("Audio time scale: {}", audioTimeScale);
                        }
                    } else {
                        log.debug("Unhandled handler type: {}", hdlrType);
                    }
                }
                MediaInformationBox minf = mdia.getMediaInformationBox();
                if (minf != null) {
                    if (log.isDebugEnabled()) {
                        log.debug("minf children: {}", minf.getBoxes().size());
                        MP4Reader.dumpBox(minf);
                    }
                    AbstractMediaHeaderBox abs = minf.getMediaHeaderBox();
                    if (abs instanceof SoundMediaHeaderBox) { // smhd
                        //SoundMediaHeaderBox smhd = (SoundMediaHeaderBox) abs;
                        log.debug("Sound header atom found");
                    } else {
                        log.debug("Unhandled media header box: {}", abs.getType());
                    }
                }
            }
            SampleTableBox stbl = trak.getSampleTableBox(); // mdia/minf/stbl
            if (stbl != null) {
                if (log.isDebugEnabled()) {
                    log.debug("stbl children: {}", stbl.getBoxes().size());
                    MP4Reader.dumpBox(stbl);
                }
                SampleDescriptionBox stsd = stbl.getSampleDescriptionBox(); // stsd
                if (stsd != null) {
                    //stsd: mp4a, avc1, mp4v
                    //String type = stsd.getType();
                    if (log.isDebugEnabled()) {
                        log.debug("stsd children: {}", stsd.getBoxes().size());
                        MP4Reader.dumpBox(stsd);
                    }
                    SampleEntry entry = stsd.getSampleEntry();
                    log.debug("Sample entry type: {}", entry.getType());
                    // determine if audio or video and process from there
                    if (entry instanceof AudioSampleEntry) {
                        processAudioBox(stbl, (AudioSampleEntry) entry, scale);
                    }
                }
            }
        }
        //real duration
        StringBuilder sb = new StringBuilder();
        double videoTime = ((double) duration / (double) timeScale);
        log.debug("Video time: {}", videoTime);
        int minutes = (int) (videoTime / 60);
        if (minutes > 0) {
            sb.append(minutes);
            sb.append('.');
        }
        //formatter for seconds / millis
        NumberFormat df = DecimalFormat.getInstance();
        df.setMaximumFractionDigits(2);
        sb.append(df.format((videoTime % 60)));
        formattedDuration = sb.toString();
        log.debug("Time: {}", formattedDuration);

        List<MediaDataBox> mdats = isoFile.getBoxes(MediaDataBox.class);
        if (mdats != null && !mdats.isEmpty()) {
            log.debug("mdat count: {}", mdats.size());
            MediaDataBox mdat = mdats.get(0);
            if (mdat != null) {
                mdatOffset = mdat.getOffset();
            }
        }
        log.debug("Offset - mdat: {}", mdatOffset);
    } catch (Exception e) {
        log.error("Exception decoding header / atoms", e);
    }
}

From source file:mx.edu.um.mateo.inventario.dao.impl.SalidaDaoHibernate.java

private String getFolio(Almacen almacen) {
    Query query = currentSession()
            .createQuery("select f from Folio f where f.nombre = :nombre and f.almacen.id = :almacenId");
    query.setString("nombre", "SALIDA");
    query.setLong("almacenId", almacen.getId());
    query.setLockOptions(LockOptions.UPGRADE);
    Folio folio = (Folio) query.uniqueResult();
    if (folio == null) {
        folio = new Folio("SALIDA");
        folio.setAlmacen(almacen);// w ww  .  j  a v a2s .  co m
        currentSession().save(folio);
        return getFolio(almacen);
    }
    folio.setValor(folio.getValor() + 1);
    java.text.NumberFormat nf = java.text.DecimalFormat.getInstance();
    nf.setGroupingUsed(false);
    nf.setMinimumIntegerDigits(9);
    nf.setMaximumIntegerDigits(9);
    nf.setMaximumFractionDigits(0);
    StringBuilder sb = new StringBuilder();
    sb.append("S-");
    sb.append(almacen.getEmpresa().getOrganizacion().getCodigo());
    sb.append(almacen.getEmpresa().getCodigo());
    sb.append(almacen.getCodigo());
    sb.append(nf.format(folio.getValor()));
    return sb.toString();
}

From source file:org.red5.io.m4a.impl.AACReader.java

/**
 * This handles the moov atom being at the beginning or end of the file, so the mdat may also
 * be before or after the moov atom./*from www .  ja v  a2  s  .  c o m*/
 */
public void decodeHeader() {
    try {
        // we want a moov and an mdat, anything else will throw the invalid file type error
        MovieBox moov = isoFile.getBoxes(MovieBox.class).get(0);
        if (log.isDebugEnabled()) {
            log.debug("moov children: {}", moov.getBoxes().size());
            MP4Reader.dumpBox(moov);
        }
        // get the movie header
        MovieHeaderBox mvhd = moov.getMovieHeaderBox();
        // get the timescale and duration
        timeScale = mvhd.getTimescale();
        duration = mvhd.getDuration();
        log.debug("Time scale {} Duration {}", timeScale, duration);
        double lengthInSeconds = (double) duration / timeScale;
        log.debug("Seconds {}", lengthInSeconds);
        // look at the tracks
        log.debug("Tracks: {}", moov.getTrackCount());
        List<TrackBox> tracks = moov.getBoxes(TrackBox.class); // trak
        for (TrackBox trak : tracks) {
            if (log.isDebugEnabled()) {
                log.debug("trak children: {}", trak.getBoxes().size());
                MP4Reader.dumpBox(trak);
            }
            TrackHeaderBox tkhd = trak.getTrackHeaderBox(); // tkhd
            log.debug("Track id: {}", tkhd.getTrackId());
            MediaBox mdia = trak.getMediaBox(); // mdia
            long scale = 0;
            if (mdia != null) {
                if (log.isDebugEnabled()) {
                    log.debug("mdia children: {}", mdia.getBoxes().size());
                    MP4Reader.dumpBox(mdia);
                }
                MediaHeaderBox mdhd = mdia.getMediaHeaderBox(); // mdhd
                if (mdhd != null) {
                    log.debug("Media data header atom found");
                    // this will be for either video or audio depending media info
                    scale = mdhd.getTimescale();
                    log.debug("Time scale {}", scale);
                }
                HandlerBox hdlr = mdia.getHandlerBox(); // hdlr
                if (hdlr != null) {
                    String hdlrType = hdlr.getHandlerType();
                    if ("soun".equals(hdlrType)) {
                        if (scale > 0) {
                            audioTimeScale = scale * 1.0;
                            log.debug("Audio time scale: {}", audioTimeScale);
                        }
                    } else {
                        log.debug("Unhandled handler type: {}", hdlrType);
                    }
                }
                MediaInformationBox minf = mdia.getMediaInformationBox();
                if (minf != null) {
                    if (log.isDebugEnabled()) {
                        log.debug("minf children: {}", minf.getBoxes().size());
                        MP4Reader.dumpBox(minf);
                    }
                    AbstractMediaHeaderBox abs = minf.getMediaHeaderBox();
                    if (abs instanceof SoundMediaHeaderBox) { // smhd
                        //SoundMediaHeaderBox smhd = (SoundMediaHeaderBox) abs;
                        log.debug("Sound header atom found");
                    } else {
                        log.debug("Unhandled media header box: {}", abs.getType());
                    }
                }
            }
            SampleTableBox stbl = trak.getSampleTableBox(); // mdia/minf/stbl
            if (stbl != null) {
                if (log.isDebugEnabled()) {
                    log.debug("stbl children: {}", stbl.getBoxes().size());
                    MP4Reader.dumpBox(stbl);
                }
                SampleDescriptionBox stsd = stbl.getSampleDescriptionBox(); // stsd
                if (stsd != null) {
                    //stsd: mp4a, avc1, mp4v
                    //String type = stsd.getType();
                    if (log.isDebugEnabled()) {
                        log.debug("stsd children: {}", stsd.getBoxes().size());
                        MP4Reader.dumpBox(stsd);
                    }
                    SampleEntry entry = stsd.getSampleEntry();
                    log.debug("Sample entry type: {}", entry.getType());
                    // determine if audio or video and process from there
                    if (entry instanceof AudioSampleEntry) {
                        processAudioBox(stbl, (AudioSampleEntry) entry, scale);
                    }
                }
            }
        }
        //real duration
        StringBuilder sb = new StringBuilder();
        double videoTime = ((double) duration / (double) timeScale);
        log.debug("Video time: {}", videoTime);
        int minutes = (int) (videoTime / 60);
        if (minutes > 0) {
            sb.append(minutes);
            sb.append('.');
        }
        //formatter for seconds / millis
        NumberFormat df = DecimalFormat.getInstance();
        df.setMaximumFractionDigits(2);
        sb.append(df.format((videoTime % 60)));
        formattedDuration = sb.toString();
        log.debug("Time: {}", formattedDuration);

        List<MediaDataBox> mdats = isoFile.getBoxes(MediaDataBox.class);
        if (mdats != null && !mdats.isEmpty()) {
            log.debug("mdat count: {}", mdats.size());
            MediaDataBox mdat = mdats.get(0);
            if (mdat != null) {
                mdatOffset = mdat.getDataStartPosition();
            }
        }
        log.debug("Offset - mdat: {}", mdatOffset);
    } catch (Exception e) {
        log.error("Exception decoding header / atoms", e);
    }
}

From source file:mx.edu.um.mateo.inventario.dao.impl.SalidaDaoHibernate.java

private String getFolioTemporal(Almacen almacen) {
    Query query = currentSession()
            .createQuery("select f from Folio f where f.nombre = :nombre and f.almacen.id = :almacenId");
    query.setString("nombre", "SALIDA-TEMPORAL");
    query.setLong("almacenId", almacen.getId());
    query.setLockOptions(LockOptions.UPGRADE);
    Folio folio = (Folio) query.uniqueResult();
    if (folio == null) {
        folio = new Folio("SALIDA-TEMPORAL");
        folio.setAlmacen(almacen);/* w w  w. j  av  a  2  s  . co  m*/
        currentSession().save(folio);
        currentSession().flush();
        return getFolioTemporal(almacen);
    }
    folio.setValor(folio.getValor() + 1);
    java.text.NumberFormat nf = java.text.DecimalFormat.getInstance();
    nf.setGroupingUsed(false);
    nf.setMinimumIntegerDigits(9);
    nf.setMaximumIntegerDigits(9);
    nf.setMaximumFractionDigits(0);
    StringBuilder sb = new StringBuilder();
    sb.append("TS-");
    sb.append(almacen.getEmpresa().getOrganizacion().getCodigo());
    sb.append(almacen.getEmpresa().getCodigo());
    sb.append(almacen.getCodigo());
    sb.append(nf.format(folio.getValor()));
    return sb.toString();
}

From source file:com.autentia.tnt.bean.admin.ProjectBean.java

public String getCostPerProject() {
    BigDecimal total = project.getCostPerProject();
    String totalCost = null;/*from www .  j a v a  2 s.co  m*/

    NumberFormat format = NumberFormat.getInstance();
    format.setMaximumFractionDigits(2);
    totalCost = format.format(total.doubleValue());

    return totalCost;
}

From source file:com.autentia.tnt.bean.admin.ProjectBean.java

public String getWorkedHours() {
    long total = project.getWorkedHours();
    String totalWorked = "0";

    if (total != 0) {
        NumberFormat format = NumberFormat.getInstance();
        format.setMaximumFractionDigits(2);
        totalWorked = format.format(total / 60); // Convertimos a horas
    }//  ww w .j  a v a  2s . com

    return totalWorked;
}

From source file:mx.edu.um.mateo.inventario.dao.impl.EntradaDaoHibernate.java

private String getFolio(Almacen almacen) {
    Query query = currentSession()
            .createQuery("select f from Folio f where f.nombre = :nombre and f.almacen.id = :almacenId");
    query.setString("nombre", "ENTRADA");
    query.setLong("almacenId", almacen.getId());
    query.setLockOptions(LockOptions.UPGRADE);
    Folio folio = (Folio) query.uniqueResult();
    if (folio == null) {
        folio = new Folio("ENTRADA");
        folio.setAlmacen(almacen);//  w  ww  .  ja v  a2  s .  com
        currentSession().save(folio);
        return getFolio(almacen);
    }
    folio.setValor(folio.getValor() + 1);
    java.text.NumberFormat nf = java.text.DecimalFormat.getInstance();
    nf.setGroupingUsed(false);
    nf.setMinimumIntegerDigits(9);
    nf.setMaximumIntegerDigits(9);
    nf.setMaximumFractionDigits(0);
    StringBuilder sb = new StringBuilder();
    sb.append("E-");
    sb.append(almacen.getEmpresa().getOrganizacion().getCodigo());
    sb.append(almacen.getEmpresa().getCodigo());
    sb.append(almacen.getCodigo());
    sb.append(nf.format(folio.getValor()));
    return sb.toString();
}

From source file:mx.edu.um.mateo.inventario.dao.impl.EntradaDaoHibernate.java

private String getFolioTemporal(Almacen almacen) {
    Query query = currentSession()
            .createQuery("select f from Folio f where f.nombre = :nombre and f.almacen.id = :almacenId");
    query.setString("nombre", "ENTRADA-TEMPORAL");
    query.setLong("almacenId", almacen.getId());
    query.setLockOptions(LockOptions.UPGRADE);
    Folio folio = (Folio) query.uniqueResult();
    if (folio == null) {
        folio = new Folio("ENTRADA-TEMPORAL");
        folio.setAlmacen(almacen);//from w  ww .j a  va  2  s.  c  om
        currentSession().save(folio);
        currentSession().flush();
        return getFolioTemporal(almacen);
    }
    folio.setValor(folio.getValor() + 1);
    java.text.NumberFormat nf = java.text.DecimalFormat.getInstance();
    nf.setGroupingUsed(false);
    nf.setMinimumIntegerDigits(9);
    nf.setMaximumIntegerDigits(9);
    nf.setMaximumFractionDigits(0);
    StringBuilder sb = new StringBuilder();
    sb.append("TE-");
    sb.append(almacen.getEmpresa().getOrganizacion().getCodigo());
    sb.append(almacen.getEmpresa().getCodigo());
    sb.append(almacen.getCodigo());
    sb.append(nf.format(folio.getValor()));
    return sb.toString();
}

From source file:l2r.gameserver.handler.voicecommands.impl.RandomCommands.java

public boolean useVoicedCommand(String command, Player activeChar, String args) {
    if (command.equalsIgnoreCase("smsreward")) {
        if (activeChar.getPremiumItemList().isEmpty()) {
            activeChar.sendPacket(Msg.THERE_ARE_NO_MORE_VITAMIN_ITEMS_TO_BE_FOUND);
            return true;
        }//from   w ww  .  j a  v a 2  s  . c  o m

        activeChar.sendPacket(new ExGetPremiumItemList(activeChar));
    } else if (command.equalsIgnoreCase("gearscore") && activeChar.isGM()) {
        int gearScore = Util.getGearPoints(activeChar);
        activeChar.sendMessage(new CustomMessage(
                "l2r.gameserver.handler.voicecommands.impl.randomcommands.message1", activeChar, gearScore));
    } else if (command.equalsIgnoreCase("sc")
            || command.equalsIgnoreCase("scinfo") && Config.ENABLE_SC_INFO_COMMAND) {
        int page = 1;
        if (args != null && !args.isEmpty() && NumberUtils.isNumber(args))
            page = Integer.parseInt(args);

        int blockforvisual = 0;
        int all = 0;
        boolean pagereached = false;

        StringBuilder html = new StringBuilder();
        html.append("<html><title>Soul Crystal Information</title><body><table height=350>");

        for (NpcTemplate tmpl : NpcHolder.getInstance().getAll()) {
            if (tmpl != null && !tmpl.getAbsorbInfo().isEmpty()) {
                boolean nameAppended = false;
                for (AbsorbInfo ai : tmpl.getAbsorbInfo()) {
                    if (ai == null || ai.getMaxLevel() <= 10)
                        continue;

                    all++;
                    if (page == 1 && blockforvisual > 10)
                        continue;
                    if (!pagereached && all > page * 10)
                        continue;
                    if (!pagereached && all <= (page - 1) * 10)
                        continue;

                    blockforvisual++;

                    if (!nameAppended) {
                        html.append("<tr><td><font color=\"07AE23\">").append(tmpl.getName())
                                .append("</font></td></tr>");
                        nameAppended = true;
                    }

                    int chance = ai.getChance();

                    if (Config.LEVEL_UP_CRY_EXTRA_CHANCE > 0)
                        chance += Config.LEVEL_UP_CRY_EXTRA_CHANCE;

                    if (chance > 100)
                        chance = 100;

                    html.append("<tr><td><table><tr><td width=80>[")
                            .append(ai.getMinLevel() == ai.getMaxLevel() ? ai.getMinLevel()
                                    : (ai.getMinLevel() + "-" + ai.getMaxLevel()))
                            .append("]</td><td width=200>").append(getAbsorbType(ai.getAbsorbType()))
                            .append("</td><td width=50>").append(chance)
                            .append("%</td></tr></table></td></tr>");
                }
            }
        }

        int totalPages = (int) Math.round(all / 10.0 + 1);

        if (page > totalPages)
            return false;

        if (page == 1) {

            html.append("<tr><td width=210>&nbsp;</td>");
            html.append("<td width=50><button value=\">>\" action=\"bypass -h user_sc " + (page + 1)
                    + "\" width=60 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>");
        } else if (page > 1)
            if (totalPages == page) {
                html.append("<tr><td width=210>&nbsp;</td>");
                html.append("<td width=50><button value=\"<<\" action=\"bypass -h user_sc " + (page - 1)
                        + "\" width=60 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>");
            } else {
                html.append("<tr><td width=210><button value=\"<<\" action=\"bypass -h user_sc " + (page - 1)
                        + "\" width=60 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td>");
                html.append("<td width=50><button value=\">>\" action=\"bypass -h user_sc " + (page + 1)
                        + "\" width=60 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>");
            }

        html.append("</table></body></html>");
        activeChar.sendPacket(new NpcHtmlMessage(0).setHtml(html.toString()));
    } else if (command.equalsIgnoreCase("findparty")
            || command.equalsIgnoreCase("fp") && Config.PARTY_SEARCH_COMMANDS) {
        if (activeChar.isInParty() && !activeChar.getParty().isLeader(activeChar)) {
            activeChar.sendMessage(new CustomMessage(
                    "l2r.gameserver.handler.voicecommands.impl.randomcommands.message2", activeChar));
            return false;
        }

        if (!activeChar.canOverrideCond(PcCondOverride.CHAT_CONDITIONS)
                && !activeChar.antiFlood.canFindParty()) {
            activeChar.sendChatMessage(0, ChatType.PARTY.ordinal(), "FINDPARTY",
                    "Anti flood protection. Please try again later.");
            return false;
        }

        if (activeChar.isInJail()) {
            activeChar.sendMessage(new CustomMessage(
                    "l2r.gameserver.handler.voicecommands.impl.randomcommands.message3", activeChar));
            return false;
        }

        int currmembers = activeChar.getParty() != null ? activeChar.getParty().size() : 0;
        if (args == null || args.isEmpty()) {
            if (NexusEvents.isInEvent(activeChar)) {
                for (Player player : GameObjectsStorage.getAllPlayersForIterate())
                    if (!player.isInBlockList(activeChar.getName()) && !player.isInParty()
                            && !player.isInOfflineMode() && !player.isInOlympiadMode()
                            && activeChar.getEventInfo().getTeamId() == player.getEventInfo().getTeamId())
                        player.sendPacket(
                                new Say2(activeChar.getObjectId(), ChatType.BATTLEFIELD, activeChar.getName(),
                                        "   Type=1    ID=" + activeChar.getObjectId()
                                                + " Color=0    Underline=0    Title=VENT]Free slots ("
                                                + currmembers + "/9) "));
            } else {
                for (Player player : GameObjectsStorage.getAllPlayersForIterate())
                    if (!player.isInBlockList(activeChar.getName()) && !player.isInParty()
                            && !player.isInOfflineMode() && !player.isInOlympiadMode()
                            && !player.getVarB("findparty"))
                        player.sendPacket(
                                new Say2(activeChar.getObjectId(), ChatType.PARTY, activeChar.getName(),
                                        "   Type=1    ID=" + activeChar.getObjectId()
                                                + " Color=0    Underline=0    Title=ARTY]Free slots ("
                                                + currmembers + "/9) "));
            }
        } else {
            for (String s : Config.TRADE_WORDS)
                if (args.contains(s)) {
                    activeChar.sendChatMessage(0, ChatType.PARTY.ordinal(), "FINDPARTY",
                            "Dont use party find command for trade!");
                    return false;
                }

            if (args.length() > 22)
                args = args.substring(0, 22);

            if (NexusEvents.isInEvent(activeChar)) {
                for (Player player : GameObjectsStorage.getAllPlayersForIterate())
                    if (!player.isInBlockList(activeChar.getName()) && !player.isInParty()
                            && !player.isInOfflineMode() && !player.isInOlympiadMode()
                            && activeChar.getEventInfo().getTeamId() == player.getEventInfo().getTeamId())
                        player.sendPacket(
                                new Say2(activeChar.getObjectId(), ChatType.BATTLEFIELD, activeChar.getName(),
                                        "   Type=1    ID=" + activeChar.getObjectId()
                                                + " Color=0    Underline=0    Title=VENT]Free slots ("
                                                + currmembers + "/9)  for " + args + ""));
            } else {
                for (Player player : GameObjectsStorage.getAllPlayersForIterate())
                    if (!player.isInBlockList(activeChar.getName()) && !player.isInParty()
                            && !player.isInOfflineMode() && !player.isInOlympiadMode()
                            && !player.getVarB("findparty"))
                        player.sendPacket(
                                new Say2(activeChar.getObjectId(), ChatType.PARTY, activeChar.getName(),
                                        "   Type=1    ID=" + activeChar.getObjectId()
                                                + " Color=0    Underline=0    Title=ARTY]Free slots ("
                                                + currmembers + "/9)  for " + args + ""));
            }
        }

        activeChar.setPartyFindValid(true);
    } else if (command.equalsIgnoreCase("report")) //TODO: Config ...
    {
        String htmlreport = HtmCache.getInstance().getNotNull("command/report.htm", activeChar);

        if (args == null || args == "" || args.isEmpty()) {
            NpcHtmlMessage html = new NpcHtmlMessage(0);
            html.setHtml(htmlreport);
            html.replace("%reported%",
                    activeChar.getTarget() == null ? "Please select target to report or type his name."
                            : activeChar.getTarget().isPlayer() ? activeChar.getTarget().getName()
                                    : "You can report only players.");
            activeChar.sendPacket(html);
            return false;
        }

        String[] paramSplit = args.split(" ");
        if (paramSplit[0].equalsIgnoreCase("Bot") && paramSplit.length != 1) {
            activeChar.sendMessage(new CustomMessage(
                    "l2r.gameserver.handler.voicecommands.impl.randomcommands.message4", activeChar));
            return false;
        }

        StringBuilder sb = new StringBuilder();
        for (String other : paramSplit) {
            other = other.replace("Bot", "");
            other = other.replace("Abuse", "");
            other = other.replace("FakeShop", "");
            other = other.replace("\n", " ");

            sb.append(other + " ");
        }

        String fullMsg = sb.toString();

        if (fullMsg.length() > 150) {
            activeChar.sendMessage(
                    "You have exceeded maximum allowed characters for report. Maximum lenght: 150 characters.");
            return false;
        }

        botReportcommand(activeChar, paramSplit[0], sb.toString());
    } else if (command.equalsIgnoreCase("referral") && Config.ENABLE_REFERRAL_SYSTEM) {
        CharacterEmails.showReferralHtml(activeChar);
    } else if (command.equalsIgnoreCase("help") && Config.ENABLE_HELP_COMMAND) {
        String html = HtmCache.getInstance().getNotNull(Config.BBS_HOME_DIR + "pages/help.htm", activeChar);
        ShowBoard.separateAndSend(html, activeChar);
    } else if (command.equalsIgnoreCase("npcspawn") && Config.ENABLE_NPCSPAWN_COMMAND) {
        if (args == null || args == "" || args.isEmpty()) {
            String msg = showClanhallNpcSpawnWindow(activeChar);
            if (msg != null)
                activeChar.sendMessage(msg);

            return true;
        }

        String[] paramSplit = args.split(" ");
        if (paramSplit.length != 2)
            activeChar.sendMessage(new CustomMessage(
                    "l2r.gameserver.handler.voicecommands.impl.randomcommands.message5", activeChar));
        else {
            if (paramSplit[0].equalsIgnoreCase("spawn")) {
                String npcId = paramSplit[1];
                if (Util.isDigit(npcId)) {
                    String msg = spawnClanhallNpc(activeChar, Integer.parseInt(npcId));
                    if (msg != null)
                        activeChar.sendMessage(msg);
                }
            } else if (paramSplit[0].equalsIgnoreCase("unspawn")) {
                String npcObjId = paramSplit[1];
                if (Util.isDigit(npcObjId)) {
                    String msg = unspawnClanhallNpc(activeChar, Integer.parseInt(npcObjId));
                    if (msg != null)
                        activeChar.sendMessage(msg);
                }
            }
        }
    } else if (command.equalsIgnoreCase("whereis") && Config.ENABLE_WHEREIS_COMMAND)
        return whereis(command, activeChar, args);
    else if (command.equalsIgnoreCase("combinetalismans") || command.equalsIgnoreCase("talisman")
            || command.equalsIgnoreCase("ct") && Config.ENABLE_COMBINE_TALISMAN_COMMAND) {
        try {
            // TalismanId, List<TalismansWithThisId>
            Map<Integer, List<ItemInstance>> talismans = new FastMap<>();

            for (ItemInstance item : activeChar.getInventory().getItems()) {
                if (item == null || !item.isShadowItem()) // Talismans are shadow items.
                    continue;

                int itemId = item.getItemId();
                // Get only the talismans.
                if (!Util.contains(TALISMAN_IDS, itemId))
                    continue;

                if (!talismans.containsKey(itemId))
                    talismans.put(itemId, new FastTable<ItemInstance>());

                talismans.get(itemId).add(item);
            }
            activeChar.sendMessage("----------------------------------------------------");
            activeChar.sendMessage(new CustomMessage(
                    "l2r.gameserver.handler.voicecommands.impl.randomcommands.message6", activeChar));

            // Now same talismans are under 1 list. Loop this list to combine them.
            for (Entry<Integer, List<ItemInstance>> n3 : talismans.entrySet()) {
                List<ItemInstance> sameTalismans = n3.getValue();
                if (sameTalismans.size() <= 1) // We need at least 2 talismans.
                    continue;

                List<ItemInstance> talismansToCharge = new FastTable<>(); // The talisman(s) that isnt(arent) going to be destroyed, but charged.

                // First, find the equipped talisman, it is with charge priority.
                for (ItemInstance talisman : sameTalismans) {
                    if (talisman.isEquipped()) {
                        talismansToCharge.add(talisman); // Add to the chargable talismans.
                        sameTalismans.remove(talisman); // and remove it from the list, because we will loop it again and we dont want that item there.
                    }
                }

                if (talismansToCharge.isEmpty())
                    talismansToCharge.add(sameTalismans.remove(0));

                // Second loop, charge the talismans.
                int index = 0;
                ItemInstance lastTalisman = null;
                for (ItemInstance talisman : sameTalismans) {
                    if (index >= talismansToCharge.size())
                        index = 0;

                    ItemInstance talismanToCharge = talismansToCharge.get(index++);
                    int chargeMana = talisman.getLifeTime() + talismanToCharge.getLifeTime();
                    if (activeChar.getInventory().destroyItem(talisman))
                        talismanToCharge.setLifeTime(chargeMana);

                    lastTalisman = talismanToCharge;
                }

                if (lastTalisman != null) {
                    if (lastTalisman.getJdbcState().isSavable()) {
                        lastTalisman.save();
                    } else {
                        lastTalisman.setJdbcState(JdbcEntityState.UPDATED);
                        lastTalisman.update();
                    }

                    activeChar.sendMessage(new CustomMessage(
                            "l2r.gameserver.handler.voicecommands.impl.randomcommands.message8", activeChar,
                            lastTalisman.getName()));
                    InventoryUpdate iu = new InventoryUpdate().addModifiedItem(lastTalisman);
                    activeChar.sendPacket(iu);
                }
            }

            activeChar.sendMessage("----------------------------------------------------");
        } catch (Exception e) {
            activeChar.sendMessage(
                    new CustomMessage("l2r.gameserver.handler.voicecommands.impl.randomcommands.message9",
                            activeChar, TimeUtils.getDateString(new Date(System.currentTimeMillis()))));
            _log.warn("Error while combining talismans: ", e);
        }
    } else if (command.equalsIgnoreCase("openatod")
            || command.equalsIgnoreCase("oatod") && Config.ENABLE_OPENATOD_COMMAND) {
        if (args == null)
            activeChar.sendMessage(new CustomMessage(
                    "l2r.gameserver.handler.voicecommands.impl.randomcommands.message10", activeChar));
        else {
            int num = 0;
            try {
                num = Integer.parseInt(args);
            } catch (NumberFormatException nfe) {
                activeChar.sendMessage(new CustomMessage(
                        "l2r.gameserver.handler.voicecommands.impl.randomcommands.message11", activeChar));
                return false;
            }

            if (num == 0)
                return false;
            else if (activeChar.getInventory().getCountOf(9599) >= num) {
                int a = 0, b = 0, c = 0, d = 0, rnd;
                for (int i = 0; i < num; i++) {
                    rnd = Rnd.get(100);
                    // 40% Chance for hidden first page
                    if (rnd <= 99 && rnd > 59)
                        a++;
                    // 50% chance for hidden second page
                    else if (rnd <= 59 && rnd > 9)
                        b++;
                    else if (rnd <= 9)
                        c++;
                    else
                        d++;
                }
                if (activeChar.getInventory().destroyItemByItemId(9599, a + b + c + d)) {
                    if (a > 0)
                        Functions.addItem(activeChar, 9600, a, true);
                    //activeChar.getInventory().addItem(9600, a);
                    if (b > 0)
                        Functions.addItem(activeChar, 9601, b, true);
                    //activeChar.getInventory().addItem(9601, b);
                    if (c > 0)
                        Functions.addItem(activeChar, 9602, c, true);
                    //activeChar.getInventory().addItem(9602, c);
                    activeChar.sendMessage(new CustomMessage(
                            "l2r.gameserver.handler.voicecommands.impl.randomcommands.message12", activeChar,
                            d));
                } else
                    activeChar.sendMessage(new CustomMessage(
                            "l2r.gameserver.handler.voicecommands.impl.randomcommands.message13", activeChar));
            } else
                activeChar.sendMessage(new CustomMessage(
                        "l2r.gameserver.handler.voicecommands.impl.randomcommands.message14", activeChar));
        }
    } else if (Config.ENABLE_TRADELIST_VOICE && command.equalsIgnoreCase("tradelist")) {
        TradesHandler.display(activeChar, args);
    } else if (command.equalsIgnoreCase("exp") && Config.ENABLE_EXP_COMMAND) {
        NumberFormat df = NumberFormat.getNumberInstance();
        df.setMaximumFractionDigits(2);

        if (activeChar.getLevel() >= (activeChar.isSubClassActive() ? Experience.getMaxSubLevel()
                : Experience.getMaxLevel()))
            show("Maximum level!", activeChar);
        else {
            long exp = Experience.LEVEL[activeChar.getLevel() + 1] - activeChar.getExp();
            double count = 0;
            String ret = "Exp left: " + exp;
            if (count > 0)
                ret += "<br>Monsters left: " + df.format(count);
            show(ret, activeChar);
        }
    }

    return true;
}

From source file:org.kuali.kfs.module.ld.batch.service.impl.LaborScrubberProcess.java

/**
 * Generate the flag for the end of specific descriptions. This will be used in the demerger step
 *///from   w  w w .j  a  v a  2  s .co m
protected void setOffsetString() {

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(0);
    nf.setMaximumIntegerDigits(2);
    nf.setMinimumFractionDigits(0);
    nf.setMinimumIntegerDigits(2);

    offsetString = "***" + nf.format(runCal.get(Calendar.MONTH) + 1)
            + nf.format(runCal.get(Calendar.DAY_OF_MONTH));
}