dynamic array list usage to iterate object Arraylist and obtain results base don object name
Tag : java , By : Marie Ramos
Date : March 29 2020, 07:55 AM
should help you out You have to change your design. I'd like suggest to use Outer-Inner class and TreeSet. class Foo {
private String name;
private TreeSet<Item> items;
public Foo(String name) {
this.name = name;
items = new TreeSet<Item>();
}
public String getName() { return name; }
public void setName(String name) {this.name = name;}
public TreeSet<Item> getItems() {return items; }
public void addItem(Integer id, Integer value) {
items.add(new Item(id, value));
}
public class Item implements Comparable {
@Override
public int compareTo(Object arg0) {
Item i = (Item) arg0;
if (id == i.id)
return 0;
else if (id > i.id)
return 1;
else
return -1;
}
private Integer id;
private Integer value;
public Item(Integer id, Integer value) {
this.id = id;
this.value = value;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
}
List<Foo> list = new ArrayList<Foo>();
list.add(new Foo("aa"));
list.add(new Foo("bb"));
list.add(new Foo("cc"));
list.add(new Foo("dd"));
list.get(0).addItem(1, 4);
list.get(0).addItem(2, 2);
list.get(0).addItem(3, 3);
list.get(1).addItem(3, 1);
list.get(1).addItem(1, 1);
list.get(1).addItem(2, 8);
list.get(2).addItem(3, 3);
list.get(3).addItem(2, 10);
list.get(0).addItem(5, 10);
for (Foo foo : list) {
System.out.print(foo.getName());
Foo.Item[] ar = foo.getItems().toArray(new Foo.Item[0]);
for (int i = 1, j = 0; i <= 8; i++) {
if (j >= ar.length)
System.out.print(" - ");
else if (ar[j].getId() == i) {
System.out.print(" " + ar[j].getValue());
j++;
} else
System.out.print(" - ");
}
System.out.println();
}
|
Iterate through JS object/array, and if you find a match change the value and return the original object/array structure
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am trying to get a functionality like PHP in Javascript/Jquery, where we pass the address of a value (&$value) and edit its value in the actual array structure in PHP. For example I have a object in the following format, , This recursively applies a function to a nested object: transform = function(obj, fun) {
if (typeof obj != "object")
return fun(obj);
Object.keys(obj).forEach(function(k) {
obj[k] = transform(obj[k], fun);
});
return obj;
}
transform(yourData, function(val) {
if (val.replace)
return val.replace(/bad/g, "censored");
else
return val;
})
|
Javascript (ExtJS) iterate through object array, find duplicates and summarize into new object
Date : March 29 2020, 07:55 AM
it should still fix some issue I've been working with JS (ExtJS) for a while and I'm trying to do the following, assuming this array of objects: , You can do something like var array = [{
ticket: 'TICKET1',
associated_val: 'AB'
}, {
ticket: 'TICKET1',
associated_val: 'XY'
}, {
ticket: 'TICKET1',
associated_val: 'CD'
}, {
ticket: 'TICKET2',
associated_val: 'YZ'
}, {
ticket: 'TICKET2',
associated_val: 'EF'
}, {
ticket: 'TICKET3',
associated_val: 'AB'
}, {
ticket: 'TICKET4',
associated_val: null
}];
var newarray = [],
tmp = {},
item;
for (var i = 0; i < array.length; i++) {
item = array[i];
if (!tmp[item.ticket]) {
tmp[item.ticket] = {
ticket: item.ticket,
associated_val_array: []
};
newarray.push(tmp[item.ticket]);
}
if (item.associated_val != null) {
tmp[item.ticket].associated_val_array.push(item.associated_val);
}
}
console.log(newarray)
|
AngularJS ng-repeat: How to iterate on object's property array while iterating the object array
Date : March 29 2020, 07:55 AM
help you fix your problem I have a particular question: , Just iterate over the internal object controller.js $scope.getValues = function(configuration) {
var values = [];
configuration.forEach(function(c) {
values = values.concat(Object.values(c));
});
return values
}
<tr ng-repeat="x in array| filter: {configured: true}">
<td ng-repeat="val in getValues(x.configuration)" ng-bind="::val"></td>
</tr>
|
Angular 5: Iterate over [object].Array[object].[object].property with ngFor
Tag : angular , By : Robin Buitenhuis
Date : March 29 2020, 07:55 AM
may help you . You're setting the toplistByTotalVolume to equal the response in your subscription, which is an object that has the properties, Data, Message, SponserData, and Type. Then, each object in the Data array have the properties CoinInfo and ConversionInfo. So to display the name of each item, Iterate through the data of your toplistByTotalVolumeObject and access the name through the CoinInfo. <ons-button (click)="getToplistByTotalVolume()">Aktualisieren</ons-button>
<ons-list id="crypto-container" *ngFor="let toplistByTotalVolumeItem of toplistByTotalVolume.Data;">
<ons-list-item>
<div class="center">
{{ toplistByTotalVolumeItem.CoinInfo.FullName }}
</div>
</ons-list-item>
</ons-list>
getToplistByTotalVolume() {
this._data.serviceToplistByTotalVolume(this.fiatCurrency)
.subscribe(res => {
this.toplistByTotalVolume = res.Data; //<--Here
console.log(res); //<--This will log the entire response
console.log(this.toplistByTotalVolume); //<--This will only log the `Data` property of the response, which is your array
});
}
<ons-list id="crypto-container" *ngFor="let toplistByTotalVolumeItem of toplistByTotalVolume;">
|