How to programmatically get all neighbor cells info? - java

I am creating an android app with signal info and I want to have access in android libraries through which can see all the neighbor cells as the image I have below. Does anybody know how I can it?
I have tried the code below but the result it isn't that I want
List<NeighboringCellInfo> NeighboringList = tm.getNeighboringCellInfo();
String stringNeighboring = "Lac : Cid : RSSI\n";
for(int i=0; i < NeighboringList.size(); i++){
String dBm;
int rssi = NeighboringList.get(i).getRssi();
if(rssi == NeighboringCellInfo.UNKNOWN_RSSI){
dBm = "Unknown RSSI";
}else{
dBm = String.valueOf(-113 + (2 * rssi)) + " dBm";
}
stringNeighboring = stringNeighboring + String.valueOf(NeighboringList.get(i).getLac()) +" : " + String.valueOf(NeighboringList.get(i).getCid()) +" : " + dBm +"\n";
}

Related

get untitled column data from CSV file [duplicate]

This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 2 years ago.
I have this code, which supposed to retrieve data from CSV file, the file (set of files) structure is as following: [Mary, 7, 17] but the columns are not titled, so I only got A, B, C
when I run the code I seem to have only the first result in the column.
can anybody help me to iterate throw all records?
public void searchFiles()
{
int count = 0;
DirectoryResource c = new DirectoryResource();
int summ = 0;
int currentrow = 0;
String name = "ff";
String k = "Susan";
for(File f : c.selectedFiles())
{
FileResource fr = new FileResource(f);
CSVParser currentFile = fr.getCSVParser(false);
currentrow = 0;
for (CSVRecord row : currentFile)
{
currentrow++;
name = row.get(0);
if(row.get(0) == k)
{
count++;
summ = summ + currentrow;
System.out.println("Row is : " + row.getRecordNumber() + " / " + currentrow);
break;
}
else
{
System.out.println("found");
}
}
System.out.println(count + " / " + currentrow + " / " + name);
}
System.out.println("count is: " + count);
System.out.println("Summ is: " + summ);
System.out.println("Avg is: " + (summ / count));
}
I should use .equals() insted of == in the if statement
if(row.get(0).equals(k))

Tapestry t:palette NPE when options selected

I have a palette who's model is populated by a user search of customers. This works perfectly when searching initially, however once a customer is selected and the user continues to search for more customers to select a NPE is thrown.
Code from .tml
<t:palette t:id="custSelect" model="customerModel" t:encoder="stringValueEncoder"
availableLabel="Search Results" t:selected="custSelected" value="custSelected">
${custSelected}
</t:palette>
Coresponding .java
Object listResults(List<TbgWebIntCustomer> customers) {
log.debug("LISTRESULTS");
customerList = new ArrayList<String>();
if (customerList != null) {
customerList.clear();
if (request.isXHR()) {
ajaxResponseRenderer.addRender(resultZone);
}
}
String result;
log.debug("LISTRESULTS2 " + customers.size());
for (int i = 0; i <= customers.size() - 1; i++) {
log.debug("counter: " + i);
TbgWebIntCustomer currentCustomer = customers.get(i);
String customerNumber = currentCustomer.getCustomerId();
// Remove leading zeros
String customerName = currentCustomer.getLocationName();
result = customerNumber + " - " + customerName + " - "
+ currentCustomer.getCity();
log.debug(result);
customerList.add(result);
}
log.debug("LISTRESULTS3");
log.debug("customer list size: " + customerList.size());
getCustomerModel();
log.debug("customermodel after customerlist: "
+ getCustomerModel().size());
if (customerList.size() == 100) {
resultsMessage = "Search returned over 100 results. Showing top 100.";
log.debug(resultsMessage);
} else {
String numResults = Integer.toString(customerList.size());
resultsMessage = "Search returned " + numResults + " customers";
log.debug(resultsMessage);
}
log.debug("LISTRESULTS4");
log.debug("customerModel returns at i 0: " + getCustomerModel().get(0));
return request.isXHR() ? resultZone.getBody() : null;
}
Note: getCustomerModel() returns getCustomerList().
I understand that NPEs in Palette happen when one of the selected options is not present in the model you passed to it however I can't identify where it is I'm doing this. I can post setupRender() code if necessary, just trying to keep OP compact.

Trouble Updating a Table Row in Java

Connection conn = SqlConnection.getConnection("jdbc:mysql://localhost:3306/stocks");
Statement statement = conn.createStatement();
File path = new File("/Users/Zack/Desktop/JavaDB/BALANCESHEETS");
for(File file: path.listFiles()) {
if (file.isFile()) {
String fileName = file.getName();
String ticker = fileName.split("\\_")[0];
if (ticker.equals("ASB") || ticker.equals("FRC")) {
if (ticker.equals("ASB")) {
ticker = ticker + "PRD";
}
if (ticker.equals("FRC")) {
ticker = ticker + "PRD";
}
}
//CSVReader reader = new CSVReader(new FileReader(file));
//List entries = reader.readAll();
//ArrayList<String> entry = new ArrayList<String>();
Reader reader = new BufferedReader(new FileReader(file));
StringBuilder builder = new StringBuilder();
int c;
while ((c = reader.read()) != -1) {
builder.append((char) c);
}
String string = builder.toString();
ArrayList<String> stringResult = new ArrayList<String>();
if (string != null) {
String[] splitData = string.split("\\s*,\\s*|\\n");
for (int i = 0; i <splitData.length; i++) {
if (!(splitData[i] == null) || !(splitData[i].length() ==0)) {
stringResult.add(splitData[i].trim());
}
}
}
String columnName = null;
int yearCount = 0;
for (int i = 0; i < stringResult.size(); i++) {
int sL = stringResult.get(i).length();
for (int x = 0; x < sL; x++) {
if (Character.isLetter(stringResult.get(i).charAt(x))) {
yearCount = 0;
System.out.println("index: " + i);
columnName = stringResult.get(i);
columnName = columnName.replace(" ", "_");
System.out.println(columnName);
i++;
break;
}
}
yearCount++;
String value = stringResult.get(i);
System.out.println("Year: " + stringResult.get(yearCount) + " Value: " + value + " Stock: " + ticker + " Column: " + columnName );
if (!(columnName == null)) {
String writeValues = "INSERT INTO BalanceSheet (ticker, Year, " + columnName + ") "
+ "VALUE ('" + ticker + "','" + stringResult.get(yearCount) + "','" + value + "')";
String writeValues2 = "UPDATE BalanceSheet "
+ "SET ticker = '" + ticker + "', "
+ "Year = '" + stringResult.get(yearCount) + "', "
+ columnName + " = '" + value + "' "
+ "WHERE ticker = '" + ticker + "'";
statement.executeUpdate(writeValues2);
}
}
Towards the bottom of the code are two queries I tried, I'm trying to get all data organized by ticker and year into a table, "writeColumns" works but it's making a new row for every new "value" put into "columnName". My second attempt "writeColumns2" doesn't do anything.
I want to update the same row with a certain year for all values and then move onto the next year, then next ticker.
If I have understood your question correctly, you want to insert a row if it doesn't exists but update the values if it already does. You need to use ON DUPLICATE KEY UPDATE
String writeValues = "INSERT INTO BalanceSheet (ticker, Year, " + columnName + ") "
+ "VALUES (?,?,?) "
+"ON DUPLICATE KEY UPDATE " + columnName +"=?";
Statement statement = conn.prepareStatement(writeValues);
statement.setString(1,ticker);
statement.setString(2,stringResult.get(yearCount));
statement.setString(3, value);
This will solve your immidiate problem provided you create a UNIQUE index on ticker,year
However there are lot's of other issues here.
An update for each column - Currently you are doing an insert/update for each column on the table. What you are supposed to do is to insert update all the columns at one.
You are not using prepared statements addressed in my code sample
You shouldn't be doing this at all the best way to batch process data is to use MYSQL's built in LOAD DATA INFILE command. If your data is not in a format that can be easily imported into mysql, what your Java code can do is to transform it into a format that can be. Such a code will be a lot simpler and neater than what you have now

Java and SQL: ResultSetMetaData and ResultSet

I really need help. I am trying to retrieve a data from in my database using ResultSetMetaData and ResultSet. Also I am using a stored Procedure. The program is run find, however when I run it and be expecting 3 result from the row, instead it will give me 2. For example if I ask a user to enter a position and there are 6 player in that position, it will give me 5 players instead of 6 player.
Here is my code
if (!rs.next()) {
System.out.println("There is no match in the database " + position);
}
else {
System.out.println(String.format(" " + " %-19s %s", "Name",
"Rank") + "\t" + String.format("%-11s %s", "Position",
"School") + "\t" + String.format("%-6s %s",
"Age", "War") + "\n-----------------"
+ "-------------------------------------------------");
while (rs.next()) {
int rank = 0, age = 0;
String name = null, pos = null, sch = null;
double war = 0;
for (int i = 1; i < colum - 1; i++) {
rank = rs.getInt(1);
name = rs.getString(2);
pos = rs.getString(3);
sch = rs.getString(4);
age = rs.getInt(5);
war = rs.getDouble(6);
}
When I run my java code I get this result. It's not getting the first index in the list
When I call my stored procedure in MYSQL Workbench, I get this result
You have read first index in
if (!rs.next()) {
itself. This will move the cursor to the next row. You will have to remove this and it will give all the rows.

CR4E Crystal Reports save modified ChartObject

I am attempting to programatically modify a chart within a Crystal Report using Java. The java then feeds the report to the viewer. Removing an item works, modifying does not.
//Experiment : Can we programatically modify a chart?
ReportDefController rdc = reportClientDocument.getReportDefController();
ReportObjectController roc = rdc.getReportObjectController();
ReportObjects ros = roc.getReportObjectsByKind(ReportObjectKind.chart);
logger.debug("There are " + ros.size() + " chart items");
IChartObject ro = null;
IChartObject ro_original = null;
ISection iSection = null;
for (int i = 0; i <ros.size(); i++){
ro = (IChartObject)ros.get(i);
ro_original = (IChartObject)ros.get(i);
String rn = ro.getName();
ChartStyle cs = (ChartStyle) ro.getChartStyle();
cs.setEnableDataAxisAutoRange(false);
cs.setEnableShowLegend(false);
cs.setEnableDepthEffect(true);
cs.setIsVertical(true);
cs.setDataAxisMinValue(-2.0);
cs.setDataAxisMaxValue(100.0);
Double minVal = (Double)cs.getDataAxisMinValue();
Double maxVal = (Double)cs.getDataAxisMaxValue();
boolean d = cs.getEnableDepthEffect();
boolean l = cs.getEnableShowLegend();
boolean a = cs.getEnableDataAxisAutoRange();
boolean v = cs.getIsVertical();
ro.setChartStyle(cs);
int sectionCode = ro.getSectionCode();
iSection = rdc.getReportDefinition().getDetailArea().getSections().getSection(0);
try
{
//roc.modify((IChartObject)ros.get(i), ro);
rdc.modifyChartObject((IChartObject)ros.get(i), ro);
reportClientDocument.refreshReportDocument();
reportClientDocument.save();
} catch (ReportSDKException e){
writer.println("Couldn't modify graph");
e.printStackTrace();
}
logger.debug("Chart named "+rn + " With Min Val " + minVal + " and Max Val " + maxVal +" with depth " + d + " and legend " + l + " autorange " + a + " Vertical " + v);
}
I've tried the modify method of ReportObjectController and the modifychartobject method of ReportDefController, and have tried refreshReportDocument and save to attempt to get something to update, but nothing's happening. Logger is showing that the values are updating as you'd expect. Any ideas?
My mistake was in not cloning the object at...
ro = (IChartObject)ros.get(i)
...so it should read...
ro = (IChartObject)ros.get(i).clone(false)
..so that..
roc.modify((IChartObject)ros.get(i), ro)
.. will now work. Hope this helps someone else having similar fun and games.

Categories