showing table with specefic element - spring-mvc

i have a table full of object(type) when i click "liste des vihicules" i'de like to go to a table full of obeject(vehicule) with this condition:
vihicule.nom_type=type.nom_type
to do this i used this code
////go to vehicule list
#RequestMapping(value="/liste/{nom_type}")
public String listvih(#PathVariable(value = "nom_type") String nom_type, Model model) {
List<Vihicule> l = vihiculeRepository.findAll();
List<Vihicule> l1= null;
for(int i=0; i<l.size(); i++)
{ if(l.get(i).getNom_type()==nom_type)
{
l1.add(i, l.get(i));
}
}
model.addAttribute("v", l1);
return "liste";
}
but it always show an emty table. what could be the problem, please help
update: i did some changes in the code and now everything work fine
#RequestMapping(value="/liste/{nom_type}")
public String listvih(#PathVariable(value = "nom_type") String nom_type, Model model) {
List<Vihicule> l =vihiculeRepository.findAll();
List<Vihicule> l1 = new ArrayList<Vihicule>();
for(int i=0;i<l.size();i++)
{
if(l.get(i).getNom_type().equals(nom_type))
{int j=0;
l1.add(j, l.get(i));
j++;
}
}
model.addAttribute("v",l1);
return "liste";
}

Related

lineChart Using JavaFx

I'm creating line chart using Java FX. On update, I have a list of checkbox to select or deselect the series of linechart. When all are deselected but tick points or animated tick points are there and so on by doing the same thing again or adding new data for line chart it is same. I'm unable to add images to make it easier for you. Please do some help.
private static void printChartAnalysis(analysisResults r){
clearAnalsisChartData();
int [][]analysisResult=r.getAnalysisResult();
ArrayList<String> versionss=r.getVersions();
int k=0;
for(String x:versionss){
String z=new String();
for(int i=0;i<x.length();i++){
if(Character.isDigit(x.charAt(i))){
z+=x.charAt(i);
}
}
dataLOC.add(new XYChart.Data(z,(int)analysisResult[k][0]));
dataComm.add(new XYChart.Data(z,(int)analysisResult[k][1]));
dataCond.add(new XYChart.Data(z,(int)analysisResult[k][2]));
dataLoops.add(new XYChart.Data(z,(int)analysisResult[k][3]));
dataMem.add(new XYChart.Data(z,(int)analysisResult[k][4]));
k++;
}
seriesLOC.setData(dataLOC);
seriesCond.setData(dataCond);
seriesComm.setData(dataComm);
seriesLoop.setData(dataLoops);
seriesMem.setData(dataMem);
lineChart.getData().setAll(seriesLOC,seriesComm,seriesCond,seriesLoop,seriesMem);
lineChart.setTitle("Line Chart for "+r.getSoftwareName());
for (int i = 0; i < names.length; i++) {
final CheckBox cb = cbs[i];
cb.setSelected(true);
}
}
private static void printChartCost(cocomoResults est){
clearAnalsisChartData();
clearCostChartData();
for(COCOMO cost:est.getVersionsResult()){
String version=cost.getVersion();
String z=new String();
for(int i=0;i<version.length();i++){
if(Character.isDigit(version.charAt(i))){
z+=version.charAt(i);
}
}
dataEffort.add(new XYChart.Data(z,(int)cost.getEffort()));
dataDura.add(new XYChart.Data(z,(int)cost.getDuration()));
dataStaff.add(new XYChart.Data(z,(int)cost.getStaff()));
dataProd.add(new XYChart.Data(z,(int)cost.getProductivity()));
}
seriesEffort.setData(dataEffort);
seriesDura.setData(dataDura);
seriesStaff.setData(dataStaff);
seriesProd.setData(dataProd);
lineChart.getData().setAll(seriesEffort,seriesDura,seriesStaff,seriesProd);
}
private static void clearAnalsisChartData(){
lineChart.getData().removeAll(seriesLOC);
lineChart.getData().removeAll(seriesComm);
lineChart.getData().removeAll(seriesCond);
lineChart.getData().removeAll(seriesLoop);
lineChart.getData().removeAll(seriesMem);
dataLOC.clear();
dataLoops.clear();
dataComm.clear();
dataCond.clear();
dataMem.clear();
}
As far as I understood
cb.setOnAction(event -> {
if (lineChart.contains(*NAME_OF_YOUR_ELEMENT*))
lineChart.remove(*NAME_OF_YOUR_ELEMENT*)
else
lineChart.remove(*NAME_OF_YOUR_ELEMENT*)
});

load an object as values to ObjectChoiceField from sqlite database

I can load an object as values into an ObjectChoiceField from a sqlite database. I need an example, I get the values of the database into a vector, but the drop-down list does not accept this type single array.
clase BaseData
public Vector verSectores(){
Vector v=new Vector();
try{
URI uri=URI.create("/SDCard/Databases/app/semana_calculadora.db");
sqliteDB= DatabaseFactory.open(uri);
Statement st= sqliteDB.createStatement("select Sector from sectores_app");
st.prepare();
Cursor c= st.getCursor();
Row r;
while (c.next()){
r=c.getRow();
Sectores s= new Sectores(r.getString(0));
v.addElement(s);
}
st.close();
sqliteDB.close();
}catch(Exception e){}
return v;
}
class Result
public class Resultados extends MainScreen{
private Vector v;
public Resultados(Vector v) {
this.v = v;
for (int i = 0; i < v.size(); i++) {
Sectores s=(Sectores)v.elementAt(i);
//add(new LabelField(s.getName_sector()+ ""));
add(new SeparatorField());
}
}
as I have to pass the value of the vector to ObjectChoiceField?
class Screen
comboFormato = new ObjectChoiceField("Format:", ********, 0){
public void layout(int width, int height){
width=350;
super.layout(getWidth(), getHeight());
super.layout(width, height);
setExtent(width, super.getHeight());
}
public void paint(Graphics g) {
g.setColor(Color.RED);
super.paint(g);
}
};
You can't use a Vector as the basis of an ObjectChoiceField, but you can use an array of Objects, and it is easy to convert a Vector to an array, using, for example, facilities provided by the Arrays class or just brute force as follows:
Sectores [] array = new Sectores [v.size()];
for ( int i = 0; i < array.length; i++ ) {
array[i] = (Sectores)v.elementAt(i);
}
Now you can provide 'array' to your ObjectChoiceField, but be aware the text that the ObjectChoiceField will display for each choice, will be the String generated by using each element's toString() method.

List of all uncommon elements in arraylist

I have 2 ArrayList, which contains the filenames, now one list has more names and other might have less, or sometime equal, i want to list the filenames which are not common in both arraylist and accordingly update the database, i was able to check whether they are equal or not, but i am unable to list which list has extra elements and which are they.
Here is a code which i am currently using.
ArrayList DatabaseSavedThumbnail = objSlideShow.GetAllThumbnailBySlideShowId();
string[] FolderSavedThumbnail = Directory.GetFiles(Server.MapPath("~/Portals/2/SlideShowThumbnails/" + SlideShowName));
if (Directory.GetFiles(Server.MapPath("~/Portals/2/SlideShowThumbnails/" + SlideShowName)).Length > 0)
{
if (!Object.Equals(DatabaseSavedThumbnail, FolderSavedThumbnail))
{
for (int i = 0; i < DatabaseSavedThumbnail.Count && i < FolderSavedThumbnail.Length; i++)
{
if (!object.Equals(DatabaseSavedThumbnail[i], FolderSavedThumbnail[i]))
{
if (DatabaseSavedThumbnail.Count > FolderSavedThumbnail.Length)
{
objSlideShow.Thumbnail = "/Portals/2/SlideShowThumbnails/" + SlideShowName + "/" + Path.GetFileName(DatabaseSavedThumbnail[i].ToString());
}
else
{
objSlideShow.Thumbnail = "/Portals/2/SlideShowThumbnails/" + SlideShowName + "/" + Path.GetFileName(FolderSavedThumbnail[i].ToString());
}
}
Response.Write(objSlideShow.Thumbnail + "<br>");
/*objSlideShow.SlideTitle = String.Empty;
objSlideShow.SlideDescription = string.Empty;
objSlideShow.AddSlide();*/
}
}
}
But this list all the elements of the arraylist which has more elements, i just want the differential elements, so that i can update the database with those elements only.
Can anyone tell me how could i get the differential records comparing 2 array list.
Try this to get elements not common in both lists (assuming DatabaseSavedThumbnail has strings):
using System.Linq;
...
...
var dstArray = DatabaseSavedThumbnail.ToArray(typeof(string));
var fstArray = FolderSavedThumbnail;
var notCommonElements = dstArray.Union(fstArray).Except(dstArray.InterSect(fstArray));
A very naive iterative approach can be:
private IEnumerable<string> GetNotCommonElements(string[] array1, string[] array2)
{
foreach (var item in array1)
{
if (!array2.Contains(item))
{
yield return item;
}
}
foreach (var item in array2)
{
if (!array1.Contains(item))
{
yield return item;
}
}
}
Then use it like:
foreach(var item in GetNotCommonElements(dstArray, fstArray))
{
// Do stuff with item
}
you can get idea from this
List<int> intersection = first.Cast<int>().Intersect(second.Cast<int>()).ToList();
or
ArrayList intersection = new ArrayList();
foreach (var i in first.Cast<int>().Intersect(second.Cast<int>()))
intersection.Add(i);
More detail
Two ArrayList manipulation

Lucene number of occurrences

I am using Lucene.net in my Web App.
Everithing works fine, but now i have to show the number of occurrences of my 'searchstring' in every single document of the hits array.
How can i do this? I use usual BooleanQuery.
That is my search:
BooleanQuery bq = new BooleanQuery();
bq.Add(QueryParser.Parse(Lquery, "", CurIndexDescritor.GetLangAnalizer()), false,false);
BooleanQuery.SetMaxClauseCount(int.MaxValue);
IndexSearcher searcher = new IndexSearcher(indexPath);
Hits hits = (filter != null) ? searcher.Search(bq, filter) : searcher.Search(bq);
for (int i = 0; i < hits.Length(); i++)
{
Document doc = hits.Doc(i);
SearchResultItem MyDb = new SearchResultItem();
MyDb.key = doc.Get(KeyField);
MyDb.score = hits.Score(i);
result.Add(MyDb);
}
Where can i get the number of occurrences?
Thanks!
If you dont want the score back and dont want to order the results using score you could probably build a custom Similarity implementation.
I quickly tested the following code, and it appears to work fine with TermQueries and PhraseQueries, i didnt test more query types tho. A PhraseQuery hit counts as a single occurence.
public class OccurenceSimilarity : DefaultSimilarity
{
public override float Tf(float freq)
{
return freq;
}
public override float Idf(int docFreq, int numDocs)
{
return 1;
}
public override float Coord(int overlap, int maxOverlap)
{
return 1;
}
public override float QueryNorm(float sumOfSquaredWeights)
{
return 1;
}
public override Explanation.IDFExplanation idfExplain(System.Collections.ICollection terms, Searcher searcher)
{
return CACHED_IDF_EXPLAIN;
}
public override Explanation.IDFExplanation IdfExplain(Term term, Searcher searcher)
{
return CACHED_IDF_EXPLAIN;
}
public override float SloppyFreq(int distance)
{
return 1;
}
private static Explanation.IDFExplanation CACHED_IDF_EXPLAIN = new ExplainIt();
private class ExplainIt : Explanation.IDFExplanation
{
public override string Explain()
{
return "1";
}
public override float GetIdf()
{
return 1.0f;
}
}
}
To use it:
Similarity.SetDefault(new OccurenceSimilarity());

Blackberry grid layout customizations

How to add margins to the grid elements in grid manager layout of blackberry.I want it to appear exactly like it looks on a sqlite table with rows and columns having neat margins.Also i would like to add color to each row of the grid.The elements in the grid have been fetched from sqlite table string by string.
I have the following code:
GridFieldManager grid = new GridFieldManager(10,5,0);
grid.add(new LabelField("Date"));
grid.add(new LabelField("Bill"));
grid.add(new LabelField("Receipt"));
grid.add(new LabelField("Narration"));
grid.add(new LabelField("ID"));
grid.setColumnPadding(15);
grid.setRowPadding(20);
for (int i = 1; i < grid.getRowCount(); i++) {
System.out.println("Inside for first loops");
for (int j = 0; j < grid.getColumnCount() ; j++) {
System.out.println("Inside for second loops");
while(c.next()) {
System.out.println("Inside while");
Row r;
r = c.getRow();
for (int k = 4; k >=0; k--) {
System.out.println("Inside for loops");
if(k==0 || k==3) {
System.out.println("Retrieving date or narration");
grid.insert(new LabelField(r.getString(k)) {
public void paint(Graphics graphics) {
graphics.setColor(Color.BROWN);
super.paint(graphics);
}
},i,j);
} else {
System.out.println("Retrieving other values");
String p = "" + r.getInteger(k);
grid.insert(new LabelField(p) {
public void paint(Graphics graphics) {
graphics.setColor(Color.BROWN);
super.paint(graphics);
}
},i,j);
}
grid.setBackground(
BackgroundFactory.createLinearGradientBackground(
Color.GOLD,Color.CHOCOLATE,Color.GOLDENROD,Color.CORAL));
}
System.out.println("Exiting while");
}
System.out.println("Exiting sec for");
break;
}
System.out.println("Exiting first for");
break;
}
With the above code I am getting a linear gradient background color being applied to the whole screen. Also the elements of the grid excluding the headings are in brown color.
What I now want to achieve is separate colors for each row.
Anyone aware on the solution to this please share. Thanks.
To add color to the fetched rows you could use this code:
for (int k = 4; k >=0; k--)
{
System.out.println("Inside for loops");
//Check for whether column retrieved is date or naraation
if(k==0 || k==3)
{
System.out.println("Retrieving date or narration");
grid.insert(new LabelField(r.getString(k))
{
public void paint(Graphics graphics)
{
graphics.setColor(Color.GOLD);
super.paint(graphics);
}
},i,j);
}
else
{
//Check for whether column retrieved is bills,rec or id
System.out.println("Retrieving other values");
String p = "" + r.getObject(k);
//if(r.getString(k) != null)
//{
grid.insert(new LabelField(p)
{
public void paint(Graphics graphics)
{
graphics.setColor(Color.GOLD);
super.paint(graphics);
}
},i,j);
// }
}
Using it in if else manner may help your solution.
You can achieve the color part in two ways:
Override the grid manager paint method (difficult)
Add a custom VerticalFieldManager containing exactly one label field to each cell, instead of adding the labelfield directly. This is the easiest approach IMHO.

Resources