In ActionScript I have string as
str="subject,r1,r2:a,b:1,2:3,4";
dynamically i have split this string and build array collection as given below
arraycoll.addItem({subject:a ,r1:1,r2:3});
this example of one set
the arraycollection should be built dynamic i have tried but not successful
var str:String ="subject,r1,r2:a,b:1,2:3,4";
var parts:Array = str.split(":");
var props:Array = parts[0].split(",");
var count:Number = parts[1].split(",").length;
var items:Array = [];
var values:Array = [];
var i:Number, j:Number;
for(i = 0; i < props.length; i++)
values.push(parts[i + 1].split(","));
for(i = 0; i < count; i++)
{
items.push({});
for(var j = 0; j < props.length; j++)
{
items[i][props[j]] = values[j][i];
}
}
var arCol:ArrayCollection = new ArrayCollection(items);
Related
This is code for assigning parameters of one DTO to another
List<Projectdto> matchedProjects = new List<Projectdto>();
List<Projectdto> obj1 = new List<Projectdto>();
List<ProjectDTO> obj = matchedProjectsDetails;
Projectdto projectdto = new Projectdto();
for (int i = 0; i < matchedProjectsDetails.Count; i++)
{
projectdto.Name = obj[i].Name;
projectdto.PID = obj[i].PID;
projectdto.PNKC = obj[i].MatchedPNKC;
projectdto.PNKCCount = obj[i].MatchedPnkcCount;
obj1.Add(projectdto);
}
Here, after execute for loop obj1 had same array of parameters, Whats wrong with this?
Move Projectdto projectdto = new Projectdto(); inside your loop, you are just altering one item at the moment rather than creating a new copy for each iteration of the loop:
for (int i = 0; i < matchedProjectsDetails.Count; i++)
{
Projectdto projectdto = new Projectdto();
projectdto.Name = obj[i].Name;
projectdto.PID = obj[i].PID;
projectdto.PNKC = obj[i].MatchedPNKC;
projectdto.PNKCCount = obj[i].MatchedPnkcCount;
obj1.Add(projectdto);
}
For example:
IP Address: 130.45.34.36
Mask: 255.255.240.0
What would be Net ID/Subnet Address, and
Broadcast Address?
Let's write both in binary:
130.45.34.36 = 10000010.00101101.00100010.00100100
255.255.240.0 = 11111111.11111111.11110000.00000000
A bitwise AND between the two would give us the network address:
10000010.00101101.00100010.00100100 (ip address)
AND
11111111.11111111.11110000.00000000 (subnet mask)
=
10000010.00101101.00100000.00000000 = 130.45.32.0 (the resulting network address)
A bitwise OR between the network address and the inverted subnet mask would give us the broadcast address:
10000010.00101101.00100000.00000000 (netadress)
OR
00000000.00000000.00001111.11111111 (inverted subnet mask)
=
10000010.00101101.00101111.11111111 = 130.45.47.255 (broadcast address)
var network = calculateNetworkIP("192.168.0.101", "255.255.255.0");
var broadcast = calculateBroadcastIP("192.168.0.101", "255.255.255.0");
function calculateNetworkIP(ipAddress, maskIP){
var binaryIP = convertIPToBinaryIP(ipAddress);
var maskBinaryIP = convertIPToBinaryIP(maskIP);
var binaryNetwork = [];
for (var j = 0; j < maskBinaryIP.length; j++) {
binaryNetwork.push(bitwiseAND(binaryIP[j], maskBinaryIP[j]));
}
var NetworkIPArr = convertBinaryIPToDecIP(binaryNetwork);
var NetworkIPStr = "";
for (var k = 0; k < NetworkIPArr.length; k++) {
NetworkIPStr += NetworkIPArr[k]+".";
}
return NetworkIPStr.slice(0, -1);
}
function calculateBroadcastIP(ipAddress, maskIP){
var binaryIP = convertIPToBinaryIP(ipAddress);
var maskBinaryIP = convertIPToBinaryIP(maskIP);
var invertedMark = [];
for (var i = 0; i < maskBinaryIP.length; i++) {
invertedMark.push(invertedBinary(maskBinaryIP[i]));
}
var binaryBroadcast = [];
for (var j = 0; j < maskBinaryIP.length; j++) {
binaryBroadcast.push(bitwiseOR(binaryIP[j], invertedMark[j]));
}
var broadcastIPArr = convertBinaryIPToDecIP(binaryBroadcast);
var broadcastIPStr = "";
for (var k = 0; k < broadcastIPArr.length; k++) {
broadcastIPStr += broadcastIPArr[k]+".";
}
return broadcastIPStr.slice(0, -1);
}
function invertedBinary(number){
var no = number+"";
var noArr = no.split("");
var newNo = "";
for(var i = 0; i < noArr.length; i++){
if(noArr[i] == "0"){
newNo += "1";
}else{
newNo += "0";
}
}
return newNo;
}
function bitwiseAND(firstBinary, secondBinary){
var firstArr = [];
var secondArr = [];
firstArr = firstBinary.split("");
secondArr = secondBinary.split("");
var newAdded = "";
for(var i = 0; i < firstArr.length; i++){
if(firstArr[i]+"+"+secondArr[i] == "1+0"){
newAdded += "0";
}else if(firstArr[i]+"+"+secondArr[i] == "0+1"){
newAdded += "0";
}else if(firstArr[i]+"+"+secondArr[i] == "1+1"){
newAdded += "1";
}else if(firstArr[i]+"+"+secondArr[i] == "0+0"){
newAdded += "0";
}
}
return newAdded;
}
function bitwiseOR(firstBinary, secondBinary){
var firstArr = [];
var secondArr = [];
firstArr = firstBinary.split("");
secondArr = secondBinary.split("");
var newAdded = "";
for(var i = 0; i < firstArr.length; i++){
if(firstArr[i]+"+"+secondArr[i] == "1+0"){
newAdded += "1";
}else if(firstArr[i]+"+"+secondArr[i] == "0+1"){
newAdded += "1";
}else if(firstArr[i]+"+"+secondArr[i] == "1+1"){
newAdded += "1";
}else if(firstArr[i]+"+"+secondArr[i] == "0+0"){
newAdded += "0";
}
}
return newAdded;
}
function convertBinaryIPToDecIP(binaryIPArr){
var broadcastIP = [];
for (var i = 0; i < binaryIPArr.length; i++) {
broadcastIP.push(parseInt(parseInt(binaryIPArr[i]), 2));
}
return broadcastIP;
}
function convertIPToBinaryIP(ipAddress) {
var ipArr = ipAddress.split(".");
var binaryIP = [];
for (var i = 0; i < ipArr.length; i++) {
var binaryNo = parseInt(ipArr[i]).toString(2);
if(binaryNo.length == 8){
binaryIP.push(binaryNo);
}else{
var diffNo = 8 - binaryNo.length;
var createBinary = '';
for (var j = 0; j < diffNo; j++) {
createBinary += '0';
}
createBinary += binaryNo;
binaryIP.push(createBinary);
}
}
return binaryIP;
}
Code example based on Malt's answer:
const
ipadr = '130.45.34.36',
subnet = '255.255.240.0',
ipadrs = ipadr.split('.'),
subnets = subnet.split('.');
let networks = [],
broadcasts = [];
for (let i in ipadrs) {
networks[i] = ipadrs[i] & subnets[i];
}
console.log('netaddress: ', networks.join('.')) // netaddress: 130.45.32.0
for (let i in networks) {
broadcasts[i] = networks[i] | ~subnets[i] + 256;
}
console.log('broadcast address: ', broadcasts.join('.')) // broadcast address: 130.45.47.255
Another short cut for broadcast address calculation after getting netwotk address is:
calculate total no of hosts (in this case it is 2^12 = 4096)
Divide it by 256(in this case it is 16) and add the result - 1(in this case 15) in *corresponding octet(in this case second octet i.e.
32+15=47) and make other octet 255
*we can get the corresponding octet by looking at the no of hosts. e.g if the no of hosts are greater than 256 then we have to add it to the 2nd octet of network address and so on
typescript version
function getBroadcastAddress({ address, netmask }: NetworkInterfaceInfo) {
const addressBytes = address.split(".").map(Number);
const netmaskBytes = netmask.split(".").map(Number);
const subnetBytes = netmaskBytes.map(
(_, index) => addressBytes[index] & netmaskBytes[index]
);
const broadcastBytes = netmaskBytes.map(
(_, index) => subnetBytes[index] | (~netmaskBytes[index] + 256)
);
return broadcastBytes.map(String).join(".")
}
/*
// test
getBroadcastAddress({ address: "192.168.1.93", netmask: "255.255.255.0" }) == '192.168.1.255'
*/
I'm using Google Earth plugin in order to show multiple polygons(circles) at the same time, how can I do this?, I have a listbox with lat or geoDataSplit[0] and lng or geoDataSplit[1], Want to go through this listbox latlngs, pass them to polygonplacemark, store all the circles may be in an array or what would you suggest and show all of them, the code below prints all the circles but one by one and not all at the same time:
var setOfPlacemarks = [];
function createCircle(centerLat, centerLng, radius) {
function make2Circle(centerLat, centerLng, radius) {
var ring = ge.createLinearRing('');
var steps = 25;
var pi2 = Math.PI * 2;
for (var i = 0; i < steps; i++) {
var lat = parseFloat(centerLat) + radius * Math.cos(i / steps * pi2);
var lng = centerLng + radius * Math.sin(i / steps * pi2);
ring.getCoordinates().pushLatLngAlt(lat, lng, 0);
}
return ring;
}
var polygonPlacemark = ge.createPlacemark('');
polygonPlacemark.setGeometry(ge.createPolygon(''));
var outer = ge.createLinearRing('');
var dlist = document.getElementById('salesList');
for (var i = 0; i < dlist.options.length; i++) {
var geoData = dlist.options[i].text;
geoDataSplit = geoData.split(",");
polygonPlacemark.getGeometry().setOuterBoundary(make2Circle(parseFloat(geoDataSplit[0]), parseFloat(geoDataSplit[1]), .00001*parseInt(geoDataSplit[2])/5));
polygonPlacemark.setName(geoDataSplit[2]);
ge.getFeatures().appendChild(polygonPlacemark);
setOfPlacemarks.push(polygonPlacemark);
}
printAllPlacemarks();
}
function printAllPlacemarks() {
var kmlObjectList = ge.getFeatures().getChildNodes();
alert(kmlObjectList);
for (var i = 0; i < setOfPlacemarks.length; i++) {
alert(setOfPlacemarks[i]);
ge.getFeatures().appendChild(setOfPlacemarks[i]);
}
}
So what I am looking to do is to get future six months in a dropdown box and I was trying something like
public List<String> GetTrainingDates()
{
var monthList = new List<String>();
var currentMonth = DateTime.Now.Month;
for(var i = currentMonth; i <= currentMonth + 6; i++)
{
monthList.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(i));
}
return monthList;
}
But ofcourse this goes greater than 12, so would have to restart at 12 and then start from 1 again.
Just wondering if anybody has a good idea how to do this ?
Just use the % modulus operator:
monthList.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(
((i - 1) % 12) + 1));
public List<String> GetTrainingDates()
{
var monthList = new List<String>();
var currentDate = DateTime.Now();
for(var i = 0; i <= 6; i++)
{
monthList.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(currentDate.AddMonths(i).Month));
}
return monthList;
}
Use the .AddMonths function of the DateTime class...
public List<String> GetTrainingDates()
{
var monthList = new List<String>();
var month;
for(var i = 1; i <= 6; i++)
{
month = DateTime.Now.AddMonths(i).Month;
monthList.Add(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month));
}
return monthList;
}
Simply, you can use LINQ expression with Range.....
List<string> listMonth = Enumerable.Range(1, 6).ToList()
.Select(i => CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.AddMonths(i).Month))
.ToList();
I am working on the platform confirmit, which creates online surveys. This is a script node that results in the runtime error "object required", I would be grateful if you could help me fix it.. It is supposed to check whether certain codes hold 1 or 2 in the questions q2b and q3a (questions are referenced with the function f() - f(question id)[code]) - the
'//skip ?' part. Then it recodes a maximum of four of the codes into another question (h_q4) for further use.
var flag1 : boolean = false;
var flag2 : boolean = false;
//null
for(var i: int=0; i <9; i++)
{
var code = i+1;
f("h_q4")[code].set(null);
}
f("h_q4")['95'].set(null);
//skip ?
for(var k: int=1; k <16; k+=2)
{
var code = k;
if(f("q2b")[code].none("1", "2"))
flag1;
else
{
flag1 = 0;
break;
}
}
if(f("q3a")['1'].none("1", "2"))
flag2;
if(flag1 && flag2)
f("h_q4")['95'].set("1");
//recode
else
{
var fromForm = f("q2b");
var toForm = f("h_q4");
const numberOfItems : int = 4;
var available = new Set();
if(!flag1)
{
for( i = 1; i < 16; i+=2)
{
var code = i;
if(f("q2b")[i].any("1", "2"))
available.add(i);
}
}
if(!flag2)
{
available.add("9");
}
var selected = new Set();
if(available.size() <= numberOfItems)
{
selected = available;
}
else
{
while(selected.size() < numberOfItems)
{
var codes = available.members();
var randomNumber : float = Math.random()*codes.length;
var randomIndex : int = Math.floor(randomNumber);
var selectedCode = codes[randomIndex];
available.remove(selectedCode);
selected.add(selectedCode);
}
}
var codes = fromForm.domainValues();
for(var i = 0;i<codes.length;i++)
{
var code = codes[i];
if(selected.inc(code))
{
toForm[code].set("1");
}
else
{
toForm[code].set("0");
}
}
}
the first part of the code (//null) empties the 'recepient' question to ease testing
.set(), .get(), .any(), .none() are all valid