/** * If the outbound level is BINARY, convert the string field to binary, then pad to the left with * the appropriate number of zero bits to reach a number of bits specified by the bitLength * attribute of the TDT definition file. */ private void binaryPadding(Map<String, String> extraparams, Field tdtfield) { String fieldname = tdtfield.getName(); int reqbitlength = tdtfield.getBitLength(); String value; String binaryValue = fieldToBinary(tdtfield, extraparams); if (binaryValue.length() < reqbitlength) { int extraBitLength = reqbitlength - binaryValue.length(); StringBuilder zeroPaddedBinaryValue = new StringBuilder(""); for (int i = 0; i < extraBitLength; i++) { zeroPaddedBinaryValue.append("0"); } zeroPaddedBinaryValue.append(binaryValue); value = zeroPaddedBinaryValue.toString(); } else { if (binaryValue.length() > reqbitlength) throw new TDTException( "Binary value [" + binaryValue + "] for field " + fieldname + " exceeds maximum allowed " + reqbitlength + " bits. Decimal value was " + extraparams.get(fieldname)); value = binaryValue; } extraparams.put(fieldname, value); }
private Node[] processIndexNode( final Node theNode, final Document theTargetDocument, final IndexEntryFoundListener theIndexEntryFoundListener) { theNode.normalize(); boolean ditastyle = false; String textNode = null; final NodeList childNodes = theNode.getChildNodes(); final StringBuilder textBuf = new StringBuilder(); final List<Node> contents = new ArrayList<Node>(); for (int i = 0; i < childNodes.getLength(); i++) { final Node child = childNodes.item(i); if (checkElementName(child)) { ditastyle = true; break; } else if (child.getNodeType() == Node.ELEMENT_NODE) { textBuf.append(XMLUtils.getStringValue((Element) child)); contents.add(child); } else if (child.getNodeType() == Node.TEXT_NODE) { textBuf.append(child.getNodeValue()); contents.add(child); } } textNode = IndexStringProcessor.normalizeTextValue(textBuf.toString()); if (textNode.length() == 0) { textNode = null; } if (theNode.getAttributes().getNamedItem(elIndexRangeStartName) != null || theNode.getAttributes().getNamedItem(elIndexRangeEndName) != null) { ditastyle = true; } final ArrayList<Node> res = new ArrayList<Node>(); if ((ditastyle)) { final IndexEntry[] indexEntries = indexDitaProcessor.processIndexDitaNode(theNode, ""); for (final IndexEntry indexEntrie : indexEntries) { theIndexEntryFoundListener.foundEntry(indexEntrie); } final Node[] nodes = transformToNodes(indexEntries, theTargetDocument, null); for (final Node node : nodes) { res.add(node); } } else if (textNode != null) { final Node[] nodes = processIndexString(textNode, contents, theTargetDocument, theIndexEntryFoundListener); for (final Node node : nodes) { res.add(node); } } else { return new Node[0]; } return (Node[]) res.toArray(new Node[res.size()]); }
private String unirMapeos(LinkedHashMap<String, String> mapa, Object[] descripciones) { // mapa(llave,punto) // descripciones en el mismo orden que el mapeo String comillas = "\""; StringBuilder builder = new StringBuilder(); Iterator<String> iterador = mapa.keySet().iterator(); int indice = 0; while (iterador.hasNext()) { String llave = iterador.next(); String puntaje = mapa.get(llave); String descripcion = descripciones[indice].toString().equals("null") ? "" : descripciones[indice].toString(); builder.append(comillas + descripcion + comillas + "," + comillas + puntaje + comillas + ","); indice++; } return builder.toString(); }
// ## operation writeChemkinReactions(ReactionModel) // 10/26/07 gmagoon: changed to take temperature as parameter (it doesn't seem like this method is // currently used anywhere) public static String writeChemkinReactions( ReactionModel p_reactionModel, Temperature p_temperature) { // #[ operation writeChemkinReactions(ReactionModel) StringBuilder result = new StringBuilder(); result.append("REACTIONS KCAL/MOLE\n"); CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel; LinkedHashSet all = cerm.getReactedReactionSet(); HashSet hs = new HashSet(); int numfor = 0; int numrev = 0; int numdup = 0; int numnorev = 0; for (Iterator iter = all.iterator(); iter.hasNext(); ) { Reaction rxn = (Reaction) iter.next(); if (rxn.isForward()) { result.append( " " + rxn.toChemkinString(p_temperature) + "\n"); // 10/26/07 gmagoon: changed to avoid use of Global.temperature // result.append(" " + rxn.toChemkinString(Global.temperature) + "\n"); } } result.append("END\n"); return result.toString(); // #] }
private void initExecute(Element executeRoot) throws XmlaException { Element[] childElems = XmlaUtil.filterChildElements(executeRoot, NS_XMLA, "Command"); if (childElems.length != 1) { StringBuilder buf = new StringBuilder(100); buf.append(MSG_INVALID_XMLA); buf.append(": Wrong number of Command elements: "); buf.append(childElems.length); throw new XmlaException( CLIENT_FAULT_FC, HSB_BAD_COMMAND_CODE, HSB_BAD_COMMAND_FAULT_FS, Util.newError(buf.toString())); } initCommand(childElems[0]); // <Command><Statement> childElems = XmlaUtil.filterChildElements(executeRoot, NS_XMLA, "Properties"); if (childElems.length != 1) { StringBuilder buf = new StringBuilder(100); buf.append(MSG_INVALID_XMLA); buf.append(": Wrong number of Properties elements: "); buf.append(childElems.length); throw new XmlaException( CLIENT_FAULT_FC, HSB_BAD_PROPERTIES_CODE, HSB_BAD_PROPERTIES_FAULT_FS, Util.newError(buf.toString())); } initProperties(childElems[0]); // <Properties><PropertyList> }
private static String normalisedVersion(String version, String sep, int maxWidth) { String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version); StringBuilder sb = new StringBuilder(); for (String s : split) { sb.append(String.format("%" + maxWidth + 's', s)); } return sb.toString(); }
private static String encodeChar(char c) { StringBuilder buf = new StringBuilder(); buf.append("_x"); String str = Integer.toHexString(c); for (int i = 4 - str.length(); i > 0; i--) { buf.append("0"); } return buf.append(str).append("_").toString(); }
/** * Returns a string representation of all found arguments. * * @param args array with arguments * @return string representation */ static String foundArgs(final Value[] args) { // compose found arguments final StringBuilder sb = new StringBuilder(); for (final Value v : args) { if (sb.length() != 0) sb.append(", "); sb.append(v instanceof Jav ? Util.className(((Jav) v).toJava()) : v.seqType()); } return sb.toString(); }
private static String dump(Collection<ProtocolConfiguration> configs) { StringBuilder sb = new StringBuilder(); String indent = " "; sb.append("<config>\n"); for (ProtocolConfiguration cfg : configs) { sb.append(indent).append("<").append(cfg.getProtocolName()); Map<String, String> props = cfg.getProperties(); if (props.isEmpty()) { sb.append(" />\n"); } else { sb.append("\n").append(indent).append(indent); for (Map.Entry<String, String> entry : props.entrySet()) { String key = entry.getKey(); String val = entry.getValue(); key = trim(key); val = trim(val); sb.append(key).append("=\"").append(val).append("\" "); } sb.append(" />\n"); } } sb.append("</config>\n"); return sb.toString(); }
public static String writeChemkinPdepReactions(ReactionSystem rs) { // #[ operation writeChemkinReactions(ReactionModel) StringBuilder result = new StringBuilder(); result.append("REACTIONS KCAL/MOLE\n"); LinkedList rList = new LinkedList(); LinkedList troeList = new LinkedList(); LinkedList tbrList = new LinkedList(); LinkedList duplicates = new LinkedList(); LinkedList lindeList = new LinkedList(); if (rs.dynamicSimulator instanceof JDASPK) { rList = ((JDASPK) rs.dynamicSimulator).rList; troeList = ((JDASPK) rs.dynamicSimulator).troeList; tbrList = ((JDASPK) rs.dynamicSimulator).thirdBodyList; duplicates = ((JDASPK) rs.dynamicSimulator).duplicates; lindeList = ((JDASPK) rs.dynamicSimulator).lindemannList; } else if (rs.dynamicSimulator instanceof JDASSL) { rList = ((JDASSL) rs.dynamicSimulator).rList; troeList = ((JDASSL) rs.dynamicSimulator).troeList; tbrList = ((JDASSL) rs.dynamicSimulator).thirdBodyList; duplicates = ((JDASSL) rs.dynamicSimulator).duplicates; lindeList = ((JDASSL) rs.dynamicSimulator).lindemannList; } for (Iterator iter = rList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); // 10/26/07 gmagoon: changed to avoid use of Global.temperature; I am using // getPresentTemperature for the time being; it is possible that // getInitialStatus.getTemperature or something similar may be more appropriate result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n"); // result.append(r.toChemkinString(Global.temperature)+"\n"); } for (Iterator iter = troeList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n"); // result.append(r.toChemkinString(Global.temperature)+"\n"); } for (Iterator iter = tbrList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n"); // result.append(r.toChemkinString(Global.temperature)+"\n"); } for (Iterator iter = duplicates.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n\tDUP\n"); // result.append(r.toChemkinString(Global.temperature)+"\n\tDUP\n"); } for (Iterator iter = lindeList.iterator(); iter.hasNext(); ) { Reaction r = (Reaction) iter.next(); result.append(r.toChemkinString(rs.getPresentTemperature()) + "\n"); } result.append("END\n"); return result.toString(); // #] }
/** Converts a binary string input into a byte string, using 8-bits per character byte */ private String bytestring2bin(String bytestring) { String binary; StringBuilder buffer = new StringBuilder(""); int len = bytestring.length(); byte[] bytes = bytestring.getBytes(); for (int i = 0; i < len; i++) { buffer.append(padBinary(dec2bin(Integer.toString(bytes[i])), 8)); } binary = buffer.toString(); return binary; }
/** Converts a byte string input into a binary string, using 8-bits per character byte */ private String bin2bytestring(String binary) { String bytestring; StringBuilder buffer = new StringBuilder(""); int len = binary.length(); for (int i = 0; i < len; i += 8) { int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 8), 8))); buffer.append((char) j); } bytestring = buffer.toString(); return bytestring; }
/** * Converts an upper case character string input into a binary string, using 5-bit compaction of * each ASCII byte */ private String uppercasefive2bin(String uppercasefive) { String binary; StringBuilder buffer = new StringBuilder(""); int len = uppercasefive.length(); byte[] bytes = uppercasefive.getBytes(); for (int i = 0; i < len; i++) { buffer.append(padBinary(dec2bin(Integer.toString(bytes[i] % 32)), 8).substring(3, 8)); } binary = buffer.toString(); return binary; }
private static <T> String toString(List<T> list) { StringBuilder buf = new StringBuilder(); int k = -1; for (T t : list) { if (++k > 0) { buf.append(", "); } buf.append(t); } return buf.toString(); }
/** * Converts an ASCII string input into a binary string, using 7-bit compaction of each ASCII byte */ private String asciiseven2bin(String asciiseven) { String binary; StringBuilder buffer = new StringBuilder(""); int len = asciiseven.length(); byte[] bytes = asciiseven.getBytes(); for (int i = 0; i < len; i++) { buffer.append(padBinary(dec2bin(Integer.toString(bytes[i] % 128)), 8).substring(1, 8)); } binary = buffer.toString(); return binary; }
/** * Converts a binary string input into a character string output, assuming that 5-bit compaction * was used */ private String bin2uppercasefive(String binary) { String uppercasefive; StringBuilder buffer = new StringBuilder(""); int len = binary.length(); for (int i = 0; i < len; i += 5) { int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 5), 8))); buffer.append((char) (j + 64)); } uppercasefive = buffer.toString(); return uppercasefive; }
/** * Converts an alphanumeric string input into a binary string, using 6-bit compaction of each * ASCII byte */ private String alphanumsix2bin(String alphanumsix) { String binary; StringBuilder buffer = new StringBuilder(""); int len = alphanumsix.length(); byte[] bytes = alphanumsix.getBytes(); for (int i = 0; i < len; i++) { buffer.append(padBinary(dec2bin(Integer.toString(bytes[i] % 64)), 8).substring(2, 8)); } binary = buffer.toString(); return binary; }
/** * Converts a binary string input into an ASCII string output, assuming that 7-bit compaction was * used */ private String bin2asciiseven(String binary) { String asciiseven; StringBuilder buffer = new StringBuilder(""); int len = binary.length(); for (int i = 0; i < len; i += 7) { int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 7), 8))); buffer.append((char) j); } asciiseven = buffer.toString(); return asciiseven; }
public String getPath() { StringBuilder builder = new StringBuilder(); Node current = node; while (current != null && current instanceof Element) { if (current != node) { builder.insert(0, "/"); } builder.insert(0, current.getNodeName()); current = current.getParentNode(); } return builder.toString(); }
/** * Pads a binary value supplied as a string first parameter to the left with leading zeros in * order to reach a required number of bits, as expressed by the second parameter, reqlen. Returns * a string value corresponding to the binary value left padded to the required number of bits. */ private String padBinary(String binary, int reqlen) { String rv; int l = binary.length(); int pad = (reqlen - (l % reqlen)) % reqlen; StringBuilder buffer = new StringBuilder(""); for (int i = 0; i < pad; i++) { buffer.append("0"); } buffer.append(binary); rv = buffer.toString(); return rv; }
// ## operation writeChemkinInputFile(ReactionModel,SystemSnapshot) public static void writeChemkinInputFile( final ReactionModel p_reactionModel, SystemSnapshot p_beginStatus) { // #[ operation writeChemkinInputFile(ReactionModel,SystemSnapshot) StringBuilder result = new StringBuilder(); result.append(writeChemkinHeader()); result.append(writeChemkinElement()); double start = System.currentTimeMillis(); result.append(writeChemkinSpecies(p_reactionModel, p_beginStatus)); result.append(writeChemkinThermo(p_reactionModel)); Global.chemkinThermo = Global.chemkinThermo + (System.currentTimeMillis() - start) / 1000 / 60; start = System.currentTimeMillis(); result.append( writeChemkinPdepReactions( p_reactionModel, p_beginStatus)); // 10/26/07 gmagoon: changed to pass p_beginStatus // result.append(writeChemkinPdepReactions(p_reactionModel)); Global.chemkinReaction = Global.chemkinReaction + (System.currentTimeMillis() - start) / 1000 / 60; String dir = System.getProperty("RMG.workingDirectory"); if (!dir.endsWith("/")) dir += "/"; dir += "software/reactorModel/"; String file = "chemkin/chem.inp"; try { FileWriter fw = new FileWriter(file); fw.write(result.toString()); fw.close(); } catch (Exception e) { System.out.println("Error in writing chemkin input file chem.inp!"); System.out.println(e.getMessage()); System.exit(0); } if (PDepRateConstant.getMode() == Mode.CHEBYSHEV || PDepRateConstant.getMode() == Mode.PDEPARRHENIUS || PDepRateConstant.getMode() == Mode.RATE) { StringBuilder gridOfRateCoeffs = new StringBuilder(); gridOfRateCoeffs.append(writeGridOfRateCoeffs(p_reactionModel)); String newFile = "chemkin/tableOfRateCoeffs.txt"; try { FileWriter fw = new FileWriter(newFile); fw.write(gridOfRateCoeffs.toString()); fw.close(); } catch (Exception e) { System.out.println("Error in writing tableOfRateCoeffs.txt"); System.out.println(e.getMessage()); System.exit(0); } } // #] }
/** * Encodes an XML element name. * * <p>This function is mainly for encode element names in result of Drill Through execute, because * its element names come from database, we cannot make sure they are valid XML contents. * * <p>Quoth the <a href="http://xmla.org">XML/A specification</a>, version 1.1: * * <blockquote> * * XML does not allow certain characters as element and attribute names. XML for Analysis supports * encoding as defined by SQL Server 2000 to address this XML constraint. For column names that * contain invalid XML name characters (according to the XML 1.0 specification), the nonvalid * Unicode characters are encoded using the corresponding hexadecimal values. These are escaped as * _x<i>HHHH_</i> where <i>HHHH</i> stands for the four-digit hexadecimal UCS-2 code for the * character in most-significant bit first order. For example, the name "Order Details" is encoded * as Order_<i>x0020</i>_Details, where the space character is replaced by the corresponding * hexadecimal code. * * </blockquote> * * @param name Name of XML element * @return encoded name */ private static String encodeElementName(String name) { StringBuilder buf = new StringBuilder(); char[] nameChars = name.toCharArray(); for (char ch : nameChars) { String encodedStr = (ch >= CHAR_TABLE.length ? null : CHAR_TABLE[ch]); if (encodedStr == null) { buf.append(ch); } else { buf.append(encodedStr); } } return buf.toString(); }
public static String textInElement(Element elem) { StringBuilder buf = new StringBuilder(100); elem.normalize(); NodeList nlst = elem.getChildNodes(); for (int i = 0, nlen = nlst.getLength(); i < nlen; i++) { Node n = nlst.item(i); if (n instanceof Text) { final String data = ((Text) n).getData(); buf.append(data); } } return buf.toString(); }
/** * Returns a string built using a particular grammar. Single-quotes strings are counted as literal * strings, whereas all other strings appearing in the grammar require substitution with the * corresponding value from the extraparams hashmap. */ private String buildGrammar(String grammar, Map<String, String> extraparams) { StringBuilder outboundstring = new StringBuilder(); String[] fields = Pattern.compile("\\s+").split(grammar); for (int i = 0; i < fields.length; i++) { if (fields[i].substring(0, 1).equals("'")) { outboundstring.append(fields[i].substring(1, fields[i].length() - 1)); } else { outboundstring.append(extraparams.get(fields[i])); } } return outboundstring.toString(); }
/** * Converts a binary string input into a character string output, assuming that 6-bit compaction * was used */ private String bin2alphanumsix(String binary) { String alphanumsix; StringBuilder buffer = new StringBuilder(""); int len = binary.length(); for (int i = 0; i < len; i += 6) { int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 6), 8))); if (j < 32) { j += 64; } buffer.append((char) j); } alphanumsix = buffer.toString(); return alphanumsix; }
private String obtenerNombre(Element raiz) { String comillas = "\""; StringBuilder nombre = new StringBuilder(comillas); String[] vars = {"CliApePat", "CliApeMat", "CliNom"}; for (String s : vars) { nombre.append(raiz.getElementsByTagName(s).item(0).getTextContent() + " "); } nombre.append(comillas); return nombre.toString(); }
public static String writeGridOfRateCoeffs(ReactionModel p_reactionModel) { StringBuilder result = new StringBuilder(); LinkedList pDepList = new LinkedList(); CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel; for (Iterator iter = PDepNetwork.getNetworks().iterator(); iter.hasNext(); ) { PDepNetwork pdn = (PDepNetwork) iter.next(); for (ListIterator pdniter = pdn.getNetReactions().listIterator(); pdniter.hasNext(); ) { PDepReaction rxn = (PDepReaction) pdniter.next(); if (cerm.categorizeReaction(rxn) != 1) continue; // check if this reaction is not already in the list and also check if this reaction has a // reverse reaction // which is already present in the list. if (rxn.getReverseReaction() == null) rxn.generateReverseReaction(); if (!rxn.reactantEqualsProduct() && !pDepList.contains(rxn) && !pDepList.contains(rxn.getReverseReaction())) { pDepList.add(rxn); } } } Temperature[] tempsUsedInFame = PDepRateConstant.getTemperatures(); int numTemps = tempsUsedInFame.length; Pressure[] pressUsedInFame = PDepRateConstant.getPressures(); int numPress = pressUsedInFame.length; for (int i = 0; i < numTemps; i++) { for (int j = 0; j < numPress; j++) { result.append( "T=" + tempsUsedInFame[i].getK() + "K,P=" + pressUsedInFame[j].getBar() + "bar\t"); } result.append("\n"); } result.append("\n"); for (Iterator iter = pDepList.iterator(); iter.hasNext(); ) { PDepReaction r = (PDepReaction) iter.next(); result.append(r.toString() + "\n"); double[][] rates = new double[numTemps][numPress]; rates = r.getPDepRate().getRateConstants(); for (int i = 0; i < numTemps; i++) { for (int j = 0; j < numPress; j++) { result.append(rates[i][j] + "\t"); } result.append("\n"); } result.append("\n"); } return result.toString(); }
private void initCommand(Element commandRoot) throws XmlaException { Element[] childElems = XmlaUtil.filterChildElements(commandRoot, NS_XMLA, "Statement"); if (childElems.length != 1) { StringBuilder buf = new StringBuilder(100); buf.append(MSG_INVALID_XMLA); buf.append(": Wrong number of Statement elements: "); buf.append(childElems.length); throw new XmlaException( CLIENT_FAULT_FC, HSB_BAD_STATEMENT_CODE, HSB_BAD_STATEMENT_FAULT_FS, Util.newError(buf.toString())); } statement = XmlaUtil.textInElement(childElems[0]).replaceAll("\\r", ""); drillthrough = statement.toUpperCase().indexOf("DRILLTHROUGH") != -1; }
public static String replace(String input, final String expr, String replacement) { StringBuilder sb = new StringBuilder(); int new_index = 0, index = 0, len = expr.length(), input_len = input.length(); while (true) { new_index = input.indexOf(expr, index); if (new_index == -1) { sb.append(input.substring(index, input_len)); break; } sb.append(input.substring(index, new_index)); sb.append(replacement); index = new_index + len; } return sb.toString(); }
public static void writeChemkinInputFile(ReactionSystem rs) { // #[ operation writeChemkinInputFile(ReactionModel,SystemSnapshot) StringBuilder result = new StringBuilder(); result.append(writeChemkinHeader()); result.append(writeChemkinElement()); double start = System.currentTimeMillis(); result.append(writeChemkinSpecies(rs.reactionModel, rs.initialStatus)); result.append(writeChemkinThermo(rs.reactionModel)); Global.chemkinThermo = Global.chemkinThermo + (System.currentTimeMillis() - start) / 1000 / 60; start = System.currentTimeMillis(); result.append(writeChemkinPdepReactions(rs)); Global.chemkinReaction = Global.chemkinReaction + (System.currentTimeMillis() - start) / 1000 / 60; String dir = System.getProperty("RMG.workingDirectory"); if (!dir.endsWith("/")) dir += "/"; dir += "software/reactorModel/"; String file = "chemkin/chem.inp"; try { FileWriter fw = new FileWriter(file); fw.write(result.toString()); fw.close(); } catch (Exception e) { System.out.println("Error in writing chemkin input file chem.inp!"); System.out.println(e.getMessage()); System.exit(0); } // #] }