I work with j2me polish 2.0.7, in eclipse 3.4.2, with wtk2.5.2_01.
I create control which draws text: normal, bold, and italic.
The code below is parsing raw text, and search for * and _ symbols, if found than add to draw vector the text and the drawer, and it's just stops after getting second time to the line 58:
String test = new String(raw_text_buff.substring(iter));
it stops in raw_text_buff.substring(iter), ONLY in debug mode..
raw text is: bla bla bla *1000* bla bla
Full code:
private String raw_text = "bla bla bla *1000* bla bla";
Vector draw_items = null;
private void prepareText()
{
char open_char = 0;
int open_pos = 0;
Object []param = null;
StringBuffer sb = new StringBuffer();
String raw_text_buff = new String(raw_text);
int iter = 0;
boolean was_reset = false;
while(true)
{
char c = raw_text_buff.charAt(iter);
if(iter == raw_text_buff.length() || c == '*' || c == '_')
{
if(sb.length() > 0)
{
BmFont viewer = null;
String str = sb.toString();
if(open_char == '*' && null != bm_strong)
{
viewer = bm_strong.getViewer(str);
}else
if(open_char == '_' && null != bm_italic)
{
viewer = bm_italic.getViewer(str);
}else if(null != bm_normal)
{
viewer = bm_normal.getViewer(str);
}else
{
}
param = new Object[2];
param[0] = str;
param[1] = viewer;
if(null == draw_items)
draw_items = new Vector();
draw_items.addElement(param);
sb = new StringBuffer();
if(open_char == 0 && (c == '*' || c=='_'))
open_char = c;
else
open_char = 0;
String test = new String(raw_text_buff.substring(iter)); // stucks here.
raw_text_buff = test;
iter = 0;
was_reset = true;
}else
{
open_char = c;
}
if(iter == raw_text_buff.length())
break;
}else
{
sb.append(c);
}
++iter;
}
}
What I'm doing wrong?
Related
FileInputStream fileInputStream = new FileInputStream(filePath);
XWPFDocument document = new XWPFDocument(fileInputStream);
for (XWPFParagraph p : document.getParagraphs()) {
Boolean isPrg=true;
XmlCursor cursor = p.getCTP().newCursor();
cursor.selectPath(
"declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//*/w:txbxContent/w:p/w:r");
List<XmlObject> ctrsintxtbx = new ArrayList<XmlObject>();
while (cursor.hasNextSelection()) {
cursor.toNextSelection();
XmlObject obj = cursor.getObject();
ctrsintxtbx.add(obj);
}
for (XmlObject obj : ctrsintxtbx) {
CTR ctr = CTR.Factory.parse(obj.newInputStream());
XWPFRun bufferrun = new XWPFRun(ctr, (IRunBody) p);
String text = bufferrun.getText(0);
if (text != null && text != "") {
isPrg= false;
text = text.replace("[RECEPIENT_NAME]", name).replace("[ADDRESS1]", address1).replace("LETTER_GEN_DT", date)
.replace("[ID]",sbsbid).replace("MEMR_RX_ID", memrid)
.replace("MEMR_MCTR_RX_GROUP", memrgroup).replace("MEMR_MCTR_RXBIN", memrrxbin)
.replace("MEMR_MCTR_PCN", memrpcn);
System.out.println("header line is "+ text);
if((address2 == null || address2.equals("")) && (address3 == null || address3.equals(""))) {
text = text.replace("[ADDRESS2]",city+", "+state+" "+zip).replace("[ADDRESS3]","").replace("[ZIP]", "").replace("[CITY]", "").replace("[STATE]", "");
}
else if((address2 != null && !address2.equals("")) && (address3 == null || address3.equals(""))) {
text = text.replace("[ADDRESS2]",address2).replace("[ADDRESS3]",city+", "+state+" "+zip).replace("[ZIP]", "").replace("[CITY]", "").replace("[STATE]", "");
}
else if((address2 == null || address2.equals("")) && (address3 != null && !address3.equals(""))) {
text = text.replace("[ADDRESS2]",address3).replace("[ADDRESS3]",city+", "+state+" "+zip).replace("[ZIP]", "").replace("[CITY]", "").replace("[STATE]", "");
}
else if((address2 != null && !address2.equals("")) && (address3 != null && !address3.equals(""))) {
text = text.replace("[ADDRESS2]",address2).replace("[ADDRESS3]",address3).replace("[ZIP]",zip).replace("[CITY]", city).replace("[STATE]", state);
}
bufferrun.setText(text,0);
}
obj.set(bufferrun.getCTR());
}
if(isPrg) {
String runTxt="";
p.getCTP().documentProperties();
for(int i = 0; i < p.getRuns().size(); i++)
{
runTxt=runTxt+ p.getRuns().get(i);
}
System.out.println("main footer is :"+runTxt);
runTxt=runTxt.replace("[RECEPIENT_NAME]", name).replace("[PDP_NAME]", pdpname)
.replace("[ENRL_EFF_DT]", enrolldate).replace("[GLBL_PHONE_NUMBER]", phoneNumber);
int psize= p.getRuns().size();
if(psize>1) {
for(int i = 0; i < psize-1; i++)
{
try
{
p.removeRun(psize - i - 1);
}
catch(Exception e)
{
//e.printStackTrace();
}
}
}
for(XWPFRun ffr:p.getRuns()) {
ffr.setText(runTxt,0);
break;
}
}
}
outFilePath = filePath.replace(".docx", "_convert.docx");
FileOutputStream out = new FileOutputStream(
new File(outFilePath));
document.write(out);
out.close();
System.out.println("Output.docx written successully");
} catch (IOException | SQLException e) {
System.out.println("We had an error while reading the Word Doc");
}
return outFilePath;
}
Input Text :
will automatically terminate without notice when the base Contract terminates for any reason
Output i am getting like this:
will automatically terminate without notice when the base Contract terminates for any reason
For output also i need Bold text format after replacing the words in documents
Expected Output is :
will automatically terminate without notice when the base Contract terminates for any reason
I am attempting to read in info from files to implement Dijkstra's algorithm. I believe that the double for loop is causing this to drastically slow down, is there anyway around this?
Edge[] edge = new Edge[127807];
int indexEdge = 0;
String line2 = "";
BufferedReader fileReader2 = new BufferedReader(new FileReader("Road.txt"));
String valueString = null;
String vertex1IDName = null;
String vertex2IDName = null;
String extra = null;
float value = 0;
int vertex1ID = 0;
int vertex2ID = 0;
//Read the file line by line
while ((line2 = fileReader2.readLine()) != null)
{
//Get all tokens available in line
String[] tokens2 = line2.split(DELIMITER);
for(String token1 : tokens2)
{
vertex1IDName = tokens2[0];
vertex2IDName = tokens2[1];
valueString = tokens2[2];
if(tokens2.length - 1 == 3) {
extra = tokens2[tokens2.length - 1];
}
else {
extra = "";
}
vertex1ID = Integer.parseInt(vertex1IDName);
vertex2ID = Integer.parseInt(vertex2IDName);
value = Float.parseFloat(valueString);
}
System.out.println("value: "+ value + " vertex1ID:"+ vertex1ID +" vertex2ID:"+ vertex2ID+ " extra:" + extra);
//if vertex 1 name or vertex 2 name in vertex.getID()
for(int i = 0; i< indexVertex; i++) {
for(int j = 0; j< indexVertex; j++) {
if(vertex1ID == vertex[i].getID() && vertex2ID == vertex[j].getID()) {
vertex[i].addNeighbour(edge[indexEdge] = new Edge(value,vertex[i],vertex[j],extra));
indexEdge++;
}
}
}
}
Sonarqube complains that the condition
if(inputMsgPath==null || outputFormat==null || swiftStdsVersion==null)
(see snippet below) always evaluates to true, but it doesn't. Is this just a sonarqube bug?
String inputMsgPath = null;
String outputFormat = null;
String swiftStdsVersion = null;
String assertionsPath = null;
List<Assertion> assertions = null;
for( int i=0; i<args.length; i+=2){
if("-i".equals(args[i])){
inputMsgPath = args[++i];
}
else if("-o".equals(args[i])){
outputFormat = args[++i];
}
else if("-s".equals(args[i])){
swiftStdsVersion = args[++i];
}
else if("-a".equals(args[i])){
assertionsPath = args[++i];
}
}
if(inputMsgPath==null || outputFormat==null || swiftStdsVersion==null){
printSyntax();
return;
}
I have a series of notifications which appear two at a time to display a series of a total of 6-10 instructions (depending on the results of a web service call.) This portion of the code is working fine. The problem is when clicking BACKWARDS through the notifications cycle (if you click any of the two displayed notifications it will display the previous two notifications) it gets hungup at step 5 and does not display the 5th notifications and I'm having a bit of trouble determining why.
SCREENSHOT:
http://datasettings.site90.net/Screenshot_2013-10-03-11-37-20.png
SPECIFIC SOURCE:
private void setNotificationStrings(Bundle extras) {
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
// The code below sets the values of the current (field and value),
// previous, and beforePrevious
// Those hold the strings to display in the 2 notifications and the
// strings to go back to
// if the user decides to back track
if (i == count) {
done = true;
}
if (extras != null) {
if (((tm.getSimOperator()).equals(getString(R.string.numeric_tmo)))) {
Log.w(TAG, "Extras not null");
previousValue = extras.getString(getString(R.string.config_name_label));
value = extras.getString(getString(R.string.apn_label));
if (previousValue != null && value == null) {
previousField = getString(R.string.config_name_label);
previousValue = valuez.getAsString("name");
Log.w("previousValue", previousValue);
beforePreviousField = "step1";
beforePreviousValue = "> New APN";
//
field = getString(R.string.apn_label);
value = valuez.getAsString("apn");
extras.clear();
currentStep = 2;
if (i == 1) {
j++;
}
Log.d("currentStep = ", " 2");
} else {
previousValue = extras.getString(getString(R.string.apn_label));
if (proxyArr.size() > 0)// if proxy and port are not null
value = extras.getString(getString(R.string.proxy_label));
else {
value = extras.getString(getString(R.string.mmsc_label));
}
if (previousValue != null && value == null) {
previousField = getString(R.string.apn_label);
beforePreviousField = getString(R.string.config_name_label);
beforePreviousValue = valuez.getAsString("name");
if (proxyArr.size() > 0) {
field = getString(R.string.proxy_label);
value = valuez.getAsString("proxy");
} else {
field = getString(R.string.mmsc_label);
value = valuez.getAsString("mmsc");
}
extras.clear();
currentStep = 3;
Log.d("currentStep = ", " 3");
} else {
if (proxyArr.size() > 0) {// if proxy and port are not
// null
previousValue = extras.getString(getString(R.string.apn_label));
value = extras.getString(getString(R.string.port_label));
if (previousValue != null && value == null) {
previousField = getString(R.string.apn_label);
beforePreviousField = getString(R.string.config_name_label);
beforePreviousValue = valuez.getAsString("name");
field = getString(R.string.port_label);
value = valuez.getAsString("port");
extras.clear();
currentStep = 4;
Log.d("currentStep = ", " 4");
} else {
previousValue = extras.getString(getString(R.string.port_label));
value = extras.getString(getString(R.string.mmsc_label));
if (previousValue != null && value == null) {
previousField = getString(R.string.port_label);
beforePreviousField = getString(R.string.proxy_label);
beforePreviousValue = valuez.getAsString("proxy");
field = getString(R.string.mmsc_label);
value = valuez.getAsString("mmsc");
extras.clear();
currentStep = 5;
Log.d("currentStep = ", " 5");
} else {
previousValue = extras.getString(getString(R.string.port_label));
if (mmsproxyArr.size() > 0) {// if mmsproxy
// and
// mmsport
// are not
// null
value = extras.getString(getString(R.string.mms_proxy_label));
} else {
value = extras.getString(getString(R.string.type_label));
}
if (previousValue != null && value == null) {
previousField = getString(R.string.mmsc_label);
beforePreviousField = getString(R.string.port_label);
beforePreviousValue = valuez.getAsString("port");
if (mmsproxyArr.size() > 0) {
field = getString(R.string.mms_proxy_label);
value = valuez.getAsString("mmsproxy");
} else {
field = getString(R.string.type_label);
value = getString(R.string.type);
}
extras.clear();
currentStep = 6;
if (i < nameArr.size() - 1 && currentStep == 6) {
i++;
Log.d("currentStep = ", " 6");
} else {
if (mmsproxyArr.size() > 0) {// if
// mmsproxy
// and
// mmsport
// are
// not
// null
previousValue = extras.getString(getString(R.string.mms_proxy_label));
value = extras.getString(getString(R.string.mms_port_label));
if (previousValue != null && value == null) {
previousField = getString(R.string.mms_proxy_label);
beforePreviousField = getString(R.string.mmsc_label);
beforePreviousValue = valuez.getAsString("mmsc");
field = getString(R.string.mms_port_label);
value = valuez.getAsString("mmsport");
extras.clear();
currentStep = 7;
Log.d("currentStep = ", " 7");
} else {
previousValue = extras.getString(getString(R.string.mms_port_label));
value = extras.getString(getString(R.string.type_label));
if (previousValue != null && value == null) {
previousField = getString(R.string.mms_port_label);
beforePreviousField = getString(R.string.mms_proxy_label);
beforePreviousValue = valuez.getAsString("mmsproxy");
field = getString(R.string.type_label);
value = getString(R.string.type);
extras.clear();
currentStep = 8;
Log.d("currentStep = "," 8");
FULL SOURCE:
https://docs.google.com/document/d/1EjAo4bpnEjj6jExt7RY28EiA-fZIa1ExMBOfxzdGc3I/edit?usp=sharing
As per the following codes:
char Secgrp = 0;
try{
String a = (String) comboName.getSelectedItem();
String fill = "Select recDate, attendant, grp from log order by id DESC";
ps = conn.prepareStatement(fill);
rs = ps.executeQuery();
String x = cDate();
while (rs.next()){
java.sql.Date dDate = rs.getDate("recDate");
String bName = rs.getString("attendant");
char[] cbuf = new char[1];
rs.getCharacterStream("grp").read(cbuf);
char theValue = cbuf[0];
String grp = Character.toString(theValue);
if(x.equals(dDate.toString()) && group1 == theValue && a.equals(bName)){
Secgrp = theValue++ ;
}
else if(x.equals(dDate.toString()) && theValue > group1 && a.equals(bName))
{ Secgrp = theValue++;
}
else if(x.equals(dDate.toString()) && group1 > theValue && a.equals(bName))
{ Secgrp = group1;
}
As per the above codes, I'm trying to check if a char is equal to my resultset record. e.g. if A is equal to A, if date = date and name = name than do something.
But when I setText(String.valueOf(Secgrp)), no char is being inserted.
Please advice how can I retrieve a char e.g 'A' from resultSet.
Solution: Add breaks after each blocks
if(x.equals(dDate.toString()) && group1 == theValue && a.equals(bName)){
Secgrp = theValue++ ;
Break;
}
else if(x.equals(dDate.toString()) && theValue > group1 && a.equals(bName))
{ Secgrp = theValue++;
Break;
}
else if(x.equals(dDate.toString()) && group1 > theValue && a.equals(bName))
{ Secgrp = group1;
Break;
}