Example usage for java.lang Number intValue

List of usage examples for java.lang Number intValue

Introduction

In this page you can find the example usage for java.lang Number intValue.

Prototype

public abstract int intValue();

Source Link

Document

Returns the value of the specified number as an int .

Usage

From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java

/**
 * Return compatible class for typedValue based on untypedValueClass 
 * // www  .j a  v a 2 s. c  o  m
 * @param untypedValueClass
 * @param typedValue
 * @return
 */
public static Object fromDataType(Class<?> untypedValueClass, Object typedValue) {
    Log LOG = LogFactory.getLog(DataTypeHelper.class);

    if (typedValue == null) {
        return null;
    }

    if (untypedValueClass == null) {
        return typedValue;
    }

    if (ClassUtils.isAssignable(typedValue.getClass(), untypedValueClass)) {
        return typedValue;
    }

    String strTypedValue = null;
    boolean isStringTypedValue = typedValue instanceof String;

    Number numTypedValue = null;
    boolean isNumberTypedValue = typedValue instanceof Number;

    Boolean boolTypedValue = null;
    boolean isBooleanTypedValue = typedValue instanceof Boolean;

    Date dateTypedValue = null;
    boolean isDateTypedValue = typedValue instanceof Date;

    if (isStringTypedValue) {
        strTypedValue = (String) typedValue;
    }
    if (isNumberTypedValue) {
        numTypedValue = (Number) typedValue;
    }
    if (isBooleanTypedValue) {
        boolTypedValue = (Boolean) typedValue;
    }
    if (isDateTypedValue) {
        dateTypedValue = (Date) typedValue;
    }

    Object v = null;
    if (String.class.equals(untypedValueClass)) {
        v = ObjectUtils.toString(typedValue);
    } else if (BigDecimal.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createBigDecimal(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new BigDecimal(numTypedValue.doubleValue());
        } else if (isBooleanTypedValue) {
            v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new BigDecimal(dateTypedValue.getTime());
        }
    } else if (Boolean.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = BooleanUtils.toBooleanObject(strTypedValue);
        } else if (isNumberTypedValue) {
            v = BooleanUtils.toBooleanObject(numTypedValue.intValue());
        } else if (isDateTypedValue) {
            v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime());
        }
    } else if (Byte.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = Byte.valueOf(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Byte(numTypedValue.byteValue());
        } else if (isBooleanTypedValue) {
            v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Byte((byte) dateTypedValue.getTime());
        }
    } else if (byte[].class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = strTypedValue.getBytes();
        }
    } else if (Double.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createDouble(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Double(numTypedValue.doubleValue());
        } else if (isBooleanTypedValue) {
            v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Double(dateTypedValue.getTime());
        }
    } else if (Float.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createFloat(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Float(numTypedValue.floatValue());
        } else if (isBooleanTypedValue) {
            v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Float(dateTypedValue.getTime());
        }
    } else if (Short.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createInteger(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Integer(numTypedValue.intValue());
        } else if (isBooleanTypedValue) {
            v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue());
        } else if (isDateTypedValue) {
            v = new Integer((int) dateTypedValue.getTime());
        }
    } else if (Integer.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createInteger(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Integer(numTypedValue.intValue());
        } else if (isBooleanTypedValue) {
            v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue());
        } else if (isDateTypedValue) {
            v = new Integer((int) dateTypedValue.getTime());
        }
    } else if (Long.class.equals(untypedValueClass)) {
        if (isStringTypedValue) {
            v = NumberUtils.createLong(strTypedValue);
        } else if (isNumberTypedValue) {
            v = new Long(numTypedValue.longValue());
        } else if (isBooleanTypedValue) {
            v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        } else if (isDateTypedValue) {
            v = new Long(dateTypedValue.getTime());
        }
    } else if (java.sql.Date.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new java.sql.Date(numTypedValue.longValue());
        } else if (isDateTypedValue) {
            v = new java.sql.Date(dateTypedValue.getTime());
        }
    } else if (java.sql.Time.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new java.sql.Time(numTypedValue.longValue());
        } else if (isDateTypedValue) {
            v = new java.sql.Time(dateTypedValue.getTime());
        }
    } else if (java.sql.Timestamp.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new java.sql.Timestamp(numTypedValue.longValue());
        } else if (isDateTypedValue) {
            v = new java.sql.Timestamp(dateTypedValue.getTime());
        }
    } else if (Date.class.equals(untypedValueClass)) {
        if (isNumberTypedValue) {
            v = new Date(numTypedValue.longValue());
        } else if (isStringTypedValue) {
            try {
                v = DateFormat.getDateInstance().parse(strTypedValue);
            } catch (ParseException e) {
                LOG.error("Unable to parse the date : " + strTypedValue);
                LOG.debug(e.getMessage());
            }
        }
    }
    return v;
}

From source file:org.trade.ui.chart.renderer.CandleRenderer.java

private void configureToolTips() {
    setBaseToolTipGenerator(new XYToolTipGenerator() {
        public String generateToolTip(XYDataset dataset, int series, int item) {
            StringBuilder result = new StringBuilder("<html>");
            if (dataset instanceof CandleDataset) {
                CandleDataset d = (CandleDataset) dataset;
                Number time = d.getX(series, item);
                Number high = d.getHigh(series, item);
                Number low = d.getLow(series, item);
                Number open = d.getOpen(series, item);
                Number close = d.getClose(series, item);
                Number vwap = d.getVwap(series, item);
                Number volume = d.getVolume(series, item);
                result.append("<b>Open:</b> ").append(new Money(open.doubleValue())).append("<br/>");
                result.append("<b>High:</b> ").append(new Money(high.doubleValue())).append("<br/>");
                result.append("<b>Low:</b> ").append(new Money(low.doubleValue())).append("<br/>");
                result.append("<b>Close:</b> ").append(new Money(close.doubleValue())).append("<br/>");
                result.append("<b>Vwap:</b> ").append(new Money(vwap.doubleValue())).append("<br/>");
                result.append("<b>Volume:</b> ").append(new Quantity(volume.intValue())).append("<br/>");
                result.append("<b>Date:</b> ").append(TOOLTIP_DATE_FORMAT.format(time)).append("<br/>");
            }/* w  w  w .  ja  v a  2s  .c  om*/
            return result.toString();
        }
    });
}

From source file:org.osgp.adapter.protocol.dlms.domain.commands.DlmsHelperService.java

public MessageType readMessageType(final DataObject resultData, final String description)
        throws ProtocolAdapterException {
    final Number number = this.readNumber(resultData, description, "Enum");
    if (number == null) {
        return null;
    }//www . j av a 2 s . co m
    final MessageType message;
    final int enumValue = number.intValue();
    switch (enumValue) {
    case 0:
        message = MessageType.A_XDR_ENCODED_X_DLMS_APDU;
        break;
    case 1:
        message = MessageType.XML_ENCODED_X_DLMS_APDU;
        break;
    default:
        if (enumValue < 128 || enumValue > 255) {
            LOGGER.error("Unexpected Enum value for MessageType: {}", enumValue);
            throw new ProtocolAdapterException("Unknown Enum value for MessageType: " + enumValue);
        }
        message = MessageType.MANUFACTURER_SPECIFIC;
    }
    return message;
}

From source file:com.vuze.plugin.azVPN_PIA.Checker.java

private boolean callRPCforPort(File pathPIAManagerData, InetAddress bindIP, StringBuilder sReply) {
    InetAddress[] resolve = null;
    try {/*  ww w.  ja va2  s.  co m*/
        // Let's assume the client_id.txt file is the one for port forwarding.
        File fileClientID = new File(pathPIAManagerData, "client_id.txt");
        String clientID;
        if (fileClientID.isFile() && fileClientID.canRead()) {
            clientID = FileUtil.readFileAsString(fileClientID, -1);
        } else {
            clientID = config.getPluginStringParameter("client.id", null);
            if (clientID == null) {
                clientID = RandomUtils.generateRandomAlphanumerics(20);
                config.setPluginParameter("client.id", clientID);
            }
        }

        HttpPost post = new HttpPost(PIA_RPC_URL);

        String user = config.getPluginStringParameter(PluginPIA.CONFIG_USER);
        String pass = new String(config.getPluginByteParameter(PluginPIA.CONFIG_P, new byte[0]), "utf-8");

        if (user == null || user.length() == 0 || pass == null || pass.length() == 0) {
            return false;
        }

        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("user", user));
        urlParameters.add(new BasicNameValuePair("pass", pass));
        urlParameters.add(new BasicNameValuePair("client_id", clientID));
        urlParameters.add(new BasicNameValuePair("local_ip", bindIP.getHostAddress()));

        // Call needs to be from the VPN interface (the bindIP)
        RequestConfig requestConfig = RequestConfig.custom().setLocalAddress(bindIP).setConnectTimeout(10000)
                .build();

        post.setConfig(requestConfig);

        post.setEntity(new UrlEncodedFormEntity(urlParameters));

        CloseableHttpClient httpClient = HttpClients.createDefault();

        // If Vuze has a proxy set up (Tools->Options->Connection->Proxy), then
        // we'll need to disable it for the URL
        AEProxySelector selector = AEProxySelectorFactory.getSelector();
        if (selector != null) {
            resolve = SystemDefaultDnsResolver.INSTANCE.resolve(PIA_DOMAIN);

            for (InetAddress address : resolve) {
                selector.setProxy(new InetSocketAddress(address, 443), Proxy.NO_PROXY);
            }
        }

        CloseableHttpResponse response = httpClient.execute(post);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }

        boolean gotPort = false;
        // should be {"port":xyz}

        Map<?, ?> mapResult = JSONUtils.decodeJSON(result.toString());
        if (mapResult.containsKey("port")) {
            Object oPort = mapResult.get("port");
            if (oPort instanceof Number) {
                gotPort = true;
                Number nPort = (Number) oPort;
                int port = nPort.intValue();

                addReply(sReply, CHAR_GOOD, "pia.port.from.rpc", new String[] { Integer.toString(port) });

                changePort(port, sReply);
            }
        }

        if (!gotPort) {
            addReply(sReply, CHAR_WARN, "pia.rpc.bad", new String[] { result.toString() });

            // mapResult.containsKey("error")
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        addReply(sReply, CHAR_BAD, "pia.rpc.no.connect", new String[] { bindIP + ": " + e.getMessage() });

        return false;
    } finally {
        AEProxySelector selector = AEProxySelectorFactory.getSelector();
        if (selector != null && resolve != null) {
            for (InetAddress address : resolve) {
                AEProxySelectorFactory.getSelector().removeProxy(new InetSocketAddress(address, 443));
            }
        }
    }
    return true;
}

From source file:HexFormat.java

/**
 * Parse a hex number into a Number object. Hexadecimal numbers may be
 * indicated with a leading character designation of '0x'. If up to 1 byte
 * is parsed, returns a Byte. If more than 1 and up to 2 bytes are parsed,
 * return a Short. If more than 2 and up to 4 bytes are parsed, return an
 * Integer. If more than 4 and up to 8 bytes are parsed, return a Long.
 * //w ww .  j  ava  2 s  .  co  m
 * @param text
 *            a hexadecimal number
 * @param parsePosition
 *            position to start parsing from
 * @return return an integer form of Number object if parse is successful;
 *         <CODE>null</CODE> otherwise
 * 
 * @since 1.0
 */
public Number parse(String text, ParsePosition parsePosition) {
    boolean skipWhitespace = true;
    int startIndex, nibbles;

    // remove whitespace
    StringCharacterIterator iter = new StringCharacterIterator(text, parsePosition.getIndex());
    for (char c = iter.current(); c != CharacterIterator.DONE; c = iter.next()) {
        if (skipWhitespace && Character.isWhitespace(c)) {
            // skip whitespace
            continue;
        }
        break;
    }

    // skip a leading hex designation of the characters '0x'
    if (text.regionMatches(iter.getIndex(), "0x", 0, 2)) {
        parsePosition.setIndex(iter.getIndex() + 2);
    } else {
        parsePosition.setIndex(iter.getIndex());
    }

    startIndex = parsePosition.getIndex();
    Number result = (Number) parseObject(text, parsePosition);

    if (result == null) {
        return (result);
    }

    nibbles = parsePosition.getIndex() - startIndex;
    if (nibbles <= 2) {
        result = new Byte(result.byteValue());
    } else if (nibbles <= 4) {
        result = new Short(result.shortValue());
    } else if (nibbles <= 8) {
        result = new Integer(result.intValue());
    } else if (nibbles <= 16) {
        result = new Long(result.longValue());
    }
    return (result);
}

From source file:edu.kit.dama.staging.services.impl.download.DownloadInformationPersistenceImpl.java

@Override
public Number getEntitiesCountByDigitalObjectId(DigitalObjectId pDigitalObjectId,
        IAuthorizationContext pSecurityContext) {
    IMetaDataManager mdm = SecureMetaDataManager.factorySecureMetaDataManager(getPersistenceUnit(),
            pSecurityContext);// ww  w .ja v  a2 s  .com
    LOGGER.debug("Executing query for entity count by digital object id");
    Number result = 0;
    try {
        result = mdm.findSingleResult(
                "SELECT x FROM DownloadInformation x WHERE x.digitalObjectUuid = ?1 AND x.ownerUuid LIKE ?2",
                new Object[] { pDigitalObjectId, getOwnerFromContext(pSecurityContext) }, Number.class);
        if (result.intValue() > 1 && !isPrivilegedContext(pSecurityContext)) {
            LOGGER.warn("Query for DownloadInformation count with id '" + pDigitalObjectId + "' returned "
                    + result
                    + ". This should not happen for non-privileged queries for DownloadInformation entities.");
        }
    } catch (UnauthorizedAccessAttemptException ex) {
        LOGGER.error("Not authorized to get download count for object id " + pDigitalObjectId
                + " using context " + pSecurityContext, ex);
    } finally {
        mdm.close();
    }
    return result;
}

From source file:IntRange.java

/**
 * <p>Tests whether the specified <code>Number</code> occurs within
 * this range using <code>int</code> comparison..</p>
 * /*from ww  w . j  ava2 s  .co m*/
 * <p><code>null</code> is handled and returns <code>false</code>.</p>
 * 
 * <p>This implementation forwards to the {@link #containsInteger(int)} method.</p>
 *
 * @param value  the integer to test, may be <code>null</code>
 * @return <code>true</code> if the specified number occurs within this
 *  range by <code>int</code> comparison
 */
public boolean containsInteger(Number value) {
    if (value == null) {
        return false;
    }
    return containsInteger(value.intValue());
}

From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java

private void handleDecodeExternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    if (barcode != null) {
        viewfinderView.drawResultBitmap(barcode);
    }//from   ww w . ja  v  a2 s  . co m

    long resultDurationMS;
    if (getIntent() == null) {
        resultDurationMS = DEFAULT_INTENT_RESULT_DURATION_MS;
    } else {
        resultDurationMS = getIntent().getLongExtra(Intents.Scan.RESULT_DISPLAY_DURATION_MS,
                DEFAULT_INTENT_RESULT_DURATION_MS);
    }

    if (resultDurationMS > 0) {
        String rawResultString = String.valueOf(rawResult);
        if (rawResultString.length() > 32) {
            rawResultString = rawResultString.substring(0, 32) + " ...";
        }
        statusView.setText(getString(resultHandler.getDisplayTitle()) + " : " + rawResultString);
    }

    //        if (copyToClipboard && !resultHandler.areContentsSecure()) {
    //            CharSequence text = resultHandler.getDisplayContents();
    //            ClipboardInterface.setText(text, this);
    //        }

    if (source == IntentSource.NATIVE_APP_INTENT) {

        // Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when
        // the deprecated intent is retired.
        Intent intent = new Intent(getIntent().getAction());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.putExtra(Intents.Scan.RESULT, rawResult.toString());
        intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
        byte[] rawBytes = rawResult.getRawBytes();
        if (rawBytes != null && rawBytes.length > 0) {
            intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
        }
        Map<ResultMetadataType, ?> metadata = rawResult.getResultMetadata();
        if (metadata != null) {
            if (metadata.containsKey(ResultMetadataType.UPC_EAN_EXTENSION)) {
                intent.putExtra(Intents.Scan.RESULT_UPC_EAN_EXTENSION,
                        metadata.get(ResultMetadataType.UPC_EAN_EXTENSION).toString());
            }
            Number orientation = (Number) metadata.get(ResultMetadataType.ORIENTATION);
            if (orientation != null) {
                intent.putExtra(Intents.Scan.RESULT_ORIENTATION, orientation.intValue());
            }
            String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
            if (ecLevel != null) {
                intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, ecLevel);
            }
            @SuppressWarnings("unchecked")
            Iterable<byte[]> byteSegments = (Iterable<byte[]>) metadata.get(ResultMetadataType.BYTE_SEGMENTS);
            if (byteSegments != null) {
                int i = 0;
                for (byte[] byteSegment : byteSegments) {
                    intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, byteSegment);
                    i++;
                }
            }
        }
        sendReplyMessage(R.id.return_scan_result, intent, resultDurationMS);

    } else if (source == IntentSource.PRODUCT_SEARCH_LINK) {

        // Reformulate the URL which triggered us into a query, so that the request goes to the same
        // TLD as the scan URL.
        int end = sourceUrl.lastIndexOf("/scan");
        String replyURL = sourceUrl.substring(0, end) + "?q=" + resultHandler.getDisplayContents()
                + "&source=zxing";
        sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS);

    } else if (source == IntentSource.ZXING_LINK) {

        //            if (scanFromWebPageManager != null && scanFromWebPageManager.isScanFromWebPage()) {
        //                String replyURL = scanFromWebPageManager.buildReplyURL(rawResult, resultHandler);
        //                scanFromWebPageManager = null;
        //                sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS);
        //            }

    }
}

From source file:IntRange.java

/**
 * <p>Tests whether the specified <code>number</code> occurs within
 * this range using <code>int</code> comparison.</p>
 * /*from w w w  . j  a v a2s  . c  o  m*/
 * <p><code>null</code> is handled and returns <code>false</code>.</p>
 *
 * @param number  the number to test, may be <code>null</code>
 * @return <code>true</code> if the specified number occurs within this range
 */
public boolean containsNumber(Number number) {
    if (number == null) {
        return false;
    }
    return containsInteger(number.intValue());
}

From source file:mml.handler.get.MMLGetMMLHandler.java

/**
 * Create the MMLtext using the invert index and the cortex and corcode
 * @param cortex the plain text version//from w  ww . java  2  s.  co  m
 * @param ccDflt the default STIL markup for that plain text
 * @param ccPages the page-breaks or null
 * @param layer the number of the layer to build
 */
void createMML(ScratchVersion cortex, ScratchVersion ccDflt, ScratchVersion ccPages, int layer) {
    String text = cortex.getLayerString(layer);
    mml = new StringBuilder();
    String stilDflt = ccDflt.getLayerString(layer);
    String stilPages = (ccPages == null) ? null : ccPages.getLayerString(layer);
    JSONObject mDflt = (JSONObject) JSONValue.parse(stilDflt);
    if (stilPages != null) {
        JSONObject mPages = (JSONObject) JSONValue.parse(stilPages);
        mDflt = mergeCorcodes(mDflt, mPages);
    }
    JSONArray ranges = (JSONArray) mDflt.get("ranges");
    Stack<EndTag> stack = new Stack<EndTag>();
    int offset = 0;
    for (int i = 0; i < ranges.size(); i++) {
        JSONObject r = (JSONObject) ranges.get(i);
        Number len = (Number) r.get("len");
        Number relOff = (Number) r.get("reloff");
        String name = (String) r.get("name");
        if (invertIndex.containsKey(name)) {
            JSONObject def = invertIndex.get(name);
            String startTag = mmlStartTag(def, offset);
            String endTag = mmlEndTag(def, len.intValue());
            int start = offset + relOff.intValue();
            // 1. insert pending end-tags and text before current range
            int pos = offset;
            while (!stack.isEmpty() && stack.peek().offset <= start) {
                // check for NLs here if obj is of type lineformat
                int tagEnd = stack.peek().offset;
                boolean isLF = isLineFormat(stack);
                for (int j = pos; j < tagEnd; j++) {
                    char c = text.charAt(j);
                    if (c != '\n') {
                        if (globals.containsKey(c))
                            mml.append(globals.get(c));
                        else
                            mml.append(c);
                    } else if (isLF && j < tagEnd - 1)
                        startPreLine(stack);
                    else
                        mml.append(c);
                }
                pos = tagEnd;
                // newlines are not permitted before tag end
                while (mml.length() > 0 && mml.charAt(mml.length() - 1) == '\n')
                    mml.setLength(mml.length() - 1);
                mml.append(stack.pop().text);
            }
            // 2. insert intervening text
            boolean inPre = isLineFormat(stack);
            int nNLs = countTerminalNLs(mml);
            for (int j = pos; j < start; j++) {
                char c = text.charAt(j);
                if (c == '\n') {
                    if (mml.length() == 0 || nNLs == 0)
                        mml.append(c);
                    if (nNLs > 0)
                        nNLs--;
                    if (inPre)
                        startPreLine(stack);
                } else {
                    mml.append(c);
                    nNLs = 0;
                }
            }
            // 3. insert new start tag
            normaliseNewlines(startTag);
            mml.append(startTag);
            stack.push(new EndTag(start + len.intValue(), endTag, def));
        } else
            System.out.println("Ignoring tag " + name);
        offset += relOff.intValue();
    }
    //empty stack
    int pos = offset;
    while (!stack.isEmpty()) {
        int tagEnd = stack.peek().offset;
        boolean inPre = isLineFormat(stack);
        for (int j = pos; j < tagEnd; j++) {
            char c = text.charAt(j);
            mml.append(c);
            if (c == '\n' && inPre && j < tagEnd - 1)
                startPreLine(stack);
        }
        pos = tagEnd;
        // newlines are not permitted before tag end
        while (mml.length() > 0 && mml.charAt(mml.length() - 1) == '\n')
            mml.setLength(mml.length() - 1);
        mml.append(stack.pop().text);
    }
}