问:
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 16 path $.locations[0]

code for response class

```<code>public class LocationHealth implements HealthStatusIdentifiable{

@SerializedName("health")
int health;
@SerializedName("location")
String location;
@SerializedName("company")
String company;
@SerializedName("pos")
CompanyPos companyPos;
@SerializedName("rosters")
RosterHealth rosterHelath;
@SerializedName("cafe_tabs")
CafeHealth cafeHealth;

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getCompany() {
    return company;
}

public void setCompany(String company) {
    this.company = company;
}

public CompanyPos getCompanyPos() {
    return companyPos;
}

public void setCompanyPos(CompanyPos companyPos) {
    this.companyPos = companyPos;
}

public RosterHealth getRosterHelath() {
    return rosterHelath;
}

public void setRosterHelath(RosterHealth rosterHelath) {
    this.rosterHelath = rosterHelath;
}

public CafeHealth getCafeHealth() {
    return cafeHealth;
}

public void setCafeHealth(CafeHealth cafeHealth) {
    this.cafeHealth = cafeHealth;
}

@Override
public String toString() {
    return location+" : "+company+" : "+health;
}

@Override
public int getHealthStatus() {
    if(health==100){
        return GOOD;
    }else if(health>50){
        return WARN;
    }else
        return ALERT;
}
</code>```

}

/CompanyPos.java/

```<code> public class CompanyPos implements HealthStatusIdentifiable{

@SerializedName("inactive")
int inactive;
@SerializedName("active")
int active;
@SerializedName("name")
String name;
@SerializedName("health")
int health;

public int getTotal(){
    return inactive+active;
}

public int getInactive() {
    return inactive;
}

public void setInactive(int inactive) {
    this.inactive = inactive;
}

public int getActive() {
    return active;
}

public void setActive(int active) {
    this.active = active;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

@Override
public int getHealthStatus() {
    if(inactive==0)
        return GOOD;
    if(inactive==1)
        return WARN;
    else
        return ALERT;
} }
</code>```

JSON FORMAT

{   "locations": [
      {
        "pos": {
          "inactive": 7,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "FS-Cafeteria-Bangalore",
        "company": "FirstSource",
        "location_id": 1,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Cafe-Hyderabad",
        "company": "General Electric",
        "location_id": 19,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Shankar Narayan Building",
        "company": "Infinera",
        "location_id": 84,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco Space",
        "company": "Northern Trust",
        "location_id": 82,
        "company_id": 70
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "SMS",
        "company": "Genpact",
        "location_id": 79,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Surya Tech Park",
        "company": "Genpact",
        "location_id": 78,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Pritech",
        "company": "Genpact",
        "location_id": 77,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.G-ETAMIN -CSR",
        "company": "Qualcomm",
        "location_id": 70,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Aneja Towers",
        "company": "FirstSource",
        "location_id": 69,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TECCI Park",
        "company": "FirstSource",
        "location_id": 68,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ETA PARK-Chennai",
        "company": "FirstSource",
        "location_id": 67,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Prestige Solitaire Building",
        "company": "Infinera",
        "location_id": 44,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco World",
        "company": "Epicor",
        "location_id": 2,
        "company_id": 3
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TVH Agnitio Park",
        "company": "Qualcomm",
        "location_id": 20,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-BTP",
        "company": "ABB",
        "location_id": 8,
        "company_id": 7
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "GE-Bengaluru",
        "company": "General Electric",
        "location_id": 5,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.E",
        "company": "Qualcomm",
        "location_id": 15,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.D",
        "company": "Qualcomm",
        "location_id": 14,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.C",
        "company": "Qualcomm",
        "location_id": 13,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "INDIA. N & T",
        "company": "Qualcomm",
        "location_id": 12,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.B",
        "company": "Qualcomm",
        "location_id": 11,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO. H- Vector",
        "company": "Qualcomm",
        "location_id": 10,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Britannia Cafe",
        "company": "Britannia",
        "location_id": 17,
        "company_id": 8
      },
      {
        "pos": {
          "inactive": 4,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Ecoworld",
        "company": "British Telecom",
        "location_id": 7,
        "company_id": 6
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Pritech",
        "company": "British Telecom",
        "location_id": 6,
        "company_id": 6
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-HEBBAL",
        "company": "ABB",
        "location_id": 85,
        "company_id": 7
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Corporate",
        "company": "Corporate",
        "location_id": 4,
        "company_id": 4
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Paladion Cafe",
        "company": "Paladion",
        "location_id": 18,
        "company_id": 9
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Mystifly",
        "company": "Mystifly",
        "location_id": 81,
        "company_id": 68
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Whitefield",
        "company": "Technicolor",
        "location_id": 80,
        "company_id": 69
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TEK MEDOWS-Chennai",
        "company": "FirstSource",
        "location_id": 66,
        "company_id": 1
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Bagmane Tech Park",
        "company": "Qualcomm",
        "location_id": 86,
        "company_id": 2
      }   ] }

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 16 path $.locations[0]

答: Use pojo generator to make pojo class </p>

Body:
code for response class

public class LocationHealth implements HealthStatusIdentifiable{

@SerializedName("health")
int health;
@SerializedName("location")
String location;
@SerializedName("company")
String company;
@SerializedName("pos")
CompanyPos companyPos;
@SerializedName("rosters")
RosterHealth rosterHelath;
@SerializedName("cafe_tabs")
CafeHealth cafeHealth;

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getCompany() {
    return company;
}

public void setCompany(String company) {
    this.company = company;
}

public CompanyPos getCompanyPos() {
    return companyPos;
}

public void setCompanyPos(CompanyPos companyPos) {
    this.companyPos = companyPos;
}

public RosterHealth getRosterHelath() {
    return rosterHelath;
}

public void setRosterHelath(RosterHealth rosterHelath) {
    this.rosterHelath = rosterHelath;
}

public CafeHealth getCafeHealth() {
    return cafeHealth;
}

public void setCafeHealth(CafeHealth cafeHealth) {
    this.cafeHealth = cafeHealth;
}

@Override
public String toString() {
    return location+" : "+company+" : "+health;
}

@Override
public int getHealthStatus() {
    if(health==100){
        return GOOD;
    }else if(health>50){
        return WARN;
    }else
        return ALERT;
}

}

/CompanyPos.java/

 public class CompanyPos implements HealthStatusIdentifiable{

@SerializedName("inactive")
int inactive;
@SerializedName("active")
int active;
@SerializedName("name")
String name;
@SerializedName("health")
int health;

public int getTotal(){
    return inactive+active;
}

public int getInactive() {
    return inactive;
}

public void setInactive(int inactive) {
    this.inactive = inactive;
}

public int getActive() {
    return active;
}

public void setActive(int active) {
    this.active = active;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

@Override
public int getHealthStatus() {
    if(inactive==0)
        return GOOD;
    if(inactive==1)
        return WARN;
    else
        return ALERT;
} }

JSON FORMAT

{   "locations": [
      {
        "pos": {
          "inactive": 7,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "FS-Cafeteria-Bangalore",
        "company": "FirstSource",
        "location_id": 1,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Cafe-Hyderabad",
        "company": "General Electric",
        "location_id": 19,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Shankar Narayan Building",
        "company": "Infinera",
        "location_id": 84,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco Space",
        "company": "Northern Trust",
        "location_id": 82,
        "company_id": 70
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "SMS",
        "company": "Genpact",
        "location_id": 79,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Surya Tech Park",
        "company": "Genpact",
        "location_id": 78,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Pritech",
        "company": "Genpact",
        "location_id": 77,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.G-ETAMIN -CSR",
        "company": "Qualcomm",
        "location_id": 70,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Aneja Towers",
        "company": "FirstSource",
        "location_id": 69,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TECCI Park",
        "company": "FirstSource",
        "location_id": 68,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ETA PARK-Chennai",
        "company": "FirstSource",
        "location_id": 67,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Prestige Solitaire Building",
        "company": "Infinera",
        "location_id": 44,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco World",
        "company": "Epicor",
        "location_id": 2,
        "company_id": 3
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TVH Agnitio Park",
        "company": "Qualcomm",
        "location_id": 20,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-BTP",
        "company": "ABB",
        "location_id": 8,
        "company_id": 7
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "GE-Bengaluru",
        "company": "General Electric",
        "location_id": 5,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.E",
        "company": "Qualcomm",
        "location_id": 15,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.D",
        "company": "Qualcomm",
        "location_id": 14,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.C",
        "company": "Qualcomm",
        "location_id": 13,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "INDIA. N & T",
        "company": "Qualcomm",
        "location_id": 12,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.B",
        "company": "Qualcomm",
        "location_id": 11,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO. H- Vector",
        "company": "Qualcomm",
        "location_id": 10,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Britannia Cafe",
        "company": "Britannia",
        "location_id": 17,
        "company_id": 8
      },
      {
        "pos": {
          "inactive": 4,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Ecoworld",
        "company": "British Telecom",
        "location_id": 7,
        "company_id": 6
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Pritech",
        "company": "British Telecom",
        "location_id": 6,
        "company_id": 6
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-HEBBAL",
        "company": "ABB",
        "location_id": 85,
        "company_id": 7
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Corporate",
        "company": "Corporate",
        "location_id": 4,
        "company_id": 4
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Paladion Cafe",
        "company": "Paladion",
        "location_id": 18,
        "company_id": 9
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Mystifly",
        "company": "Mystifly",
        "location_id": 81,
        "company_id": 68
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Whitefield",
        "company": "Technicolor",
        "location_id": 80,
        "company_id": 69
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TEK MEDOWS-Chennai",
        "company": "FirstSource",
        "location_id": 66,
        "company_id": 1
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Bagmane Tech Park",
        "company": "Qualcomm",
        "location_id": 86,
        "company_id": 2
      }   ] }

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 16 path $.locations[0]

Body: Use pojo generator to make pojo class


来源: stackexchange

问:
How to call a function and return variables
please can someone help me understand how to write a beginner function in Python?

The specific thing I want to do is...

I have 2 variables, and I want to apply the same function to both of them, and end up with 2 new things called separate things, how do I best do that?

```<code>a = "abc"
b = "def"

def foo(input):
    thing = len(input)
    return()
</code>```

how do I call foo to end up with distinctly named outputs, based on the variable?

```<code>alen = 3
blen = 3
</code>```

答:
Your function needs to actually return a value. Keep in mind that return isn't a function that you call (like return()) but a statement followed by the thing that you're returning. So in your case, your function should end with return thing.

How to actually use the function is simple:

```<code>a = "abc"
alen = foo(a)
</code>```

ContentLicense: CC BY-SA 3.0

Body:
please can someone help me understand how to write a beginner function in Python?

The specific thing I want to do is...

I have 2 variables, and I want to apply the same function to both of them, and end up with 2 new things called separate things, how do I best do that?

a = "abc"
b = "def"

def foo(input):
    thing = len(input)
    return()

how do I call foo to end up with distinctly named outputs, based on the variable?

alen = 3
blen = 3

Body:
Your function needs to actually return a value. Keep in mind that return isn't a function that you call (like return()) but a statement followed by the thing that you're returning. So in your case, your function should end with return thing.

How to actually use the function is simple:

a = "abc"
alen = foo(a)


问:
Query String Filtering with Datatables in Laravel 5.4
im using YajraBox for Datatables, it is Laravel extension.

I want to make it work with my Query String Filtering, so idea is tah i need to pass search request to ajax request

This is part of my form imput:

```<code>http://127.0.0.1:8000/lots?make%5B%5D=TOYOTA
</code>```

So result have to be: only lots made by TOYOTA

This is my script for datatables with YajraBox:

```<code><script type="text/javascript">
        $(document).ready(function(){
            $('#table').DataTable({
                bInfo: false,
                searching: false,
                processing: true,
                serverSide: true,
                ajax: '{{  url("/data") }}',
                columns: [
                    { data: 'date', name: 'date' },
                    { data: 'bid', name: 'bid' },
                    { data: 'auction_name', name: 'auction_name' },
                    { data: 'pics_urls', name: 'pics_urls' },
                    { data: 'company', name: 'company' },
                    { data: 'model_name_en', name: 'model_name_en' },
                    { data: 'model_type_en', name: 'model_type_en' },
                    { data: 'grade_en', name: 'grade_en' },
                    { data: 'mileage_en', name: 'mileage_en' },
                    { data: 'model_year_en', name: 'model_year_en' },
                    { data: 'color_en', name: 'color_en' },
                    { data: 'displacement', name: 'displacement' },
                    { data: 'transmission_en', name: 'transmission_en' },
                    { data: 'scores_en', name: 'scores_en' },
                    { data: 'start_price_en', name: 'start_price_en' },
                    { data: 'result_en', name: 'result_en' }
                ]
            });
        });
    </script>
</code>```

This is my controllers for view and for ajax:

```<code>public function index()
    {
        return view('lots.browse');
    }

    public function indexData(LotFilters $filters)
    {
       $lots  = Lot::filter($filters);

        return Datatables::eloquent($lots)->make(true);
    }
</code>```

So what i think, i need to pass some howe ?make%5B%5D=TOYOTA to ajax request  ajax: '{{  url("/data") }}',, any one know how to do it?

答:
You can do this like:

```<code>"{{ url('/data') }}" + "?make="+value  // where value contains TOYOTA in it
</code>```

and get this value in controller like:

```<code>Input::get('make');
</code>```

Body:
im using YajraBox for Datatables, it is Laravel extension.

I want to make it work with my Query String Filtering, so idea is tah i need to pass search request to ajax request

This is part of my form imput:

http://127.0.0.1:8000/lots?make%5B%5D=TOYOTA

So result have to be: only lots made by TOYOTA

This is my script for datatables with YajraBox:

This is my controllers for view and for ajax:

public function index()
    {
        return view('lots.browse');
    }

    public function indexData(LotFilters $filters)
    {
       $lots  = Lot::filter($filters);

        return Datatables::eloquent($lots)->make(true);
    }

So what i think, i need to pass some howe ?make%5B%5D=TOYOTA to ajax request  ajax: '{{  url("/data") }}',, any one know how to do it?

Body:
You can do this like:

"{{ url('/data') }}" + "?make="+value  // where value contains TOYOTA in it

and get this value in controller like:

Input::get('make');


问:
How to implement Java/Scala in-memory statistics database?
My need is to aggregate real time statistics of a web application server.
For example:

How many requests of content type X have been done

How long it takes to process request of type Y

And so on.

This data has to be completely in memory, not in a file, for best performance. It doesn't log each and every request but instead only stores counters of various aspects.

The most easy way I know is to store the values in a SQL-like table and do SQL-like queries. The benefit is that the indexing is coming off-the-shelf without development effort. I guess some embedded Java databases like Apache Derby would do the work.

The other way to go is to implement collection (say a list) and hash table for each "index column". This way it's all done with Java/Scala collections API, but I actually have to implement indexing mechanism myself, test it, maintain it, etc.

So my question is what way do you think is preferred, and if there are other ways to easily and quickly implement this feature?

Thanks.

答:
I would imagine you only need one collection per type of information you need to collection.  To improve performance, simplify code I would use TObjectIntHashMap. e.g.

How many requests of content type X have been done

```<code>TObjectIntHashMap<ContentType> contentTypeCount
     = new TObjectIntHashMap<ContentType>();

contentTypeCount.increment(contentType);
</code>```

How long it takes to process request of type Y

```<code>TObjectLongHashMap<ProcessType> contentTypeTime
    = new TObjectLongHashMap<ProcessType>();

contentTypeTime.adjustValue(processType, processTime);
</code>```

I don't see how you can make it any shorter/simpler/faster by using the other approaches you mentioned.

The average time to perform increment(key) on my machines takes 15 ns (billionths of a second)

ContentLicense: CC BY-SA 2.5

Body:
I would imagine you only need one collection per type of information you need to collection.  To improve performance, simplify code I would use TObjectIntHashMap. e.g.

How many requests of content type X have been done

TObjectIntHashMap<ContentType> contentTypeCount
     = new TObjectIntHashMap<ContentType>();

contentTypeCount.increment(contentType);

How long it takes to process request of type Y

TObjectLongHashMap<ProcessType> contentTypeTime
    = new TObjectLongHashMap<ProcessType>();

contentTypeTime.adjustValue(processType, processTime);

I don't see how you can make it any shorter/simpler/faster by using the other approaches you mentioned.

The average time to perform increment(key) on my machines takes 15 ns (billionths of a second)


问:
Where to find bootstrap classes' css definitons?
What I want is, for example, to change the css background color of navigations bar of .navbar-default, which can be done by .navbar-default{background-color:#000;}

But I want is, to see the full css style definitions of .navbar-default class, so I can look and change every element(text-color, hovering colors and every other thing) as I like. Rather than inspecting webpage elements for css codes from browsers, I want to look in a place where the definitions contain.

答: You can find and edit it in bootstrap.min.css


问:
TDD test spring service with remote call
I would test a service method which has a remote call to another server. This remote call is made by restTemplate.

This is part of my code

```<code>    .....
    @Mock
    private RestTemplate restTemplate;

    private MockRestServiceServer server;

    private static String enpointSMS = "http://46.252.156.83:8454/sms";

    @Before
    public void setup() throws Exception {

         .....
        MockitoAnnotations.initMocks(this);

        ReflectionTestUtils.setField(campaignService, "sendSmsEndpointUrl", enpointSMS);

        server = MockRestServiceServer.createServer(restTemplate);
        .....
    }

     @Test
     public void myTest(){
      ......
        server.expect(requestTo(enpointSMS))
            .andExpect(method(POST))
            .andRespond(withSuccess("resultSuccess", MediaType.TEXT_PLAIN));

     ......
        verify(mock, times(1)).method1(any(Foo.class));
        verify(mock, times(1)).method2(any(Foo.class));
        server.verify();

     }
</code>```

All works for verify of mockito but server.verify() get me an error

java.lang.AssertionError: Further request(s) expected leaving 1 unsatisfied expectation(s). 0 request(s) executed.

I can't understand reason, may be I can't use this to mock remote call? If I remove expectation of server (MockRestServiceServer) all works fine.

Any suggestions for this?

答:
You have to share the same RestTemplate object between service and test code.
Otherwise, the MockRestServiceServer will not recieve the http request.
A standard solution is adding a RestTemplate bean inject it in service and test code.

```<code>@Autowired
private RestTemplate restTemplate;

private MockRestServiceServer server;
//...
</code>```

Body:
I would test a service method which has a remote call to another server. This remote call is made by restTemplate.

This is part of my code

    .....
    @Mock
    private RestTemplate restTemplate;

    private MockRestServiceServer server;

    private static String enpointSMS = "http://46.252.156.83:8454/sms";

    @Before
    public void setup() throws Exception {

         .....
        MockitoAnnotations.initMocks(this);

        ReflectionTestUtils.setField(campaignService, "sendSmsEndpointUrl", enpointSMS);

        server = MockRestServiceServer.createServer(restTemplate);
        .....
    }

     @Test
     public void myTest(){
      ......
        server.expect(requestTo(enpointSMS))
            .andExpect(method(POST))
            .andRespond(withSuccess("resultSuccess", MediaType.TEXT_PLAIN));

     ......
        verify(mock, times(1)).method1(any(Foo.class));
        verify(mock, times(1)).method2(any(Foo.class));
        server.verify();

     }

All works for verify of mockito but server.verify() get me an error

java.lang.AssertionError: Further request(s) expected leaving 1 unsatisfied expectation(s). 0 request(s) executed.

I can't understand reason, may be I can't use this to mock remote call? If I remove expectation of server (MockRestServiceServer) all works fine.

Any suggestions for this?

Body:
You have to share the same RestTemplate object between service and test code.
Otherwise, the MockRestServiceServer will not recieve the http request.
A standard solution is adding a RestTemplate bean inject it in service and test code.

@Autowired
private RestTemplate restTemplate;

private MockRestServiceServer server;
//...


问:
auto select checkboxes by retrieving their value in JavaScript
I got some difficulties with one point since 1 week, I have 2 arrays, and I want to auto select checkboxes by retrieving the value inside one of the array.

First of all, I have a loop which create some checkboxes based on the first array choices[].

Every time I check one a checkbox, a text field is updated with a separator. "$#"

I save this text field by my own. But now I have an array with some values as string target[].

I want to auto select checkboxes which has his value inside the array target[]. So if I change a value in target[], and I refresh, the checkbox concerned will be automatically selected.

Here is a snippet to see how it looks like now. Please update it to answer.

I would prefer JavaScript but if you have Jquery it would be ok.

//array of options
var choices = new Array();
choices[0] = "January";
choices[1] = "February";
choices[2] = "March";
choices[3] = "April";
choices[4] = "May";
choices[5] = "Juny";
choices[6] = "July";
choices[7] = "August";
choices[8] = "September";
choices[9] = "October";
choices[10] = "November";
choices[11] = "December";

var target = new Array()
target[0] = "3";
target[1] = "8";

var cbh = document.getElementById('checkboxes');
var val = '';
var cap = "";

var j = "";
var t = document.getElementById('t');

// the loop is creating the checkboxes with name, value...
for (var i in choices) {
  //Name of checkboxes are their number so I convert the i into a string.
  j = i.toString();

  val = j;
  //cap will be the value/text of choices[i]
  var cb = document.createElement('input');
  var label = document.createElement("label");

  cap = choices[i];
  var text = document.createTextNode(cap);
  cb.type = 'checkbox';
  cbh.appendChild(cb);
  cb.name = cap;
  cb.value = val;
  label.appendChild(cb);
  label.appendChild(text);
  cbh.appendChild(label);
  cb.addEventListener('click', updateText)

}

function updateText() {
  t.value = [null, ...document.querySelectorAll('#checkboxes [type="checkbox"]')].reduce((s, el) => el && el.checked ? s = (s || '') + el.value + '$#' : s || '')
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>* {
  box-sizing: border-box;
}

#data {
  padding: 5px;
  width: 100vw;
}

.multiselect {
  overflow: visible;
  padding: 0;
  padding-left: 1px;
  border: none;
  background-color: #eee;
  width: 100vw;
  white-space: normal;
  height: 75px;
}

.checkboxes {
  height: 100px;
  width: 100px;
  border: 1px solid #000;
  background-color: white;
  margin-left: -1px;
  display: inline-block;
}

label {
  display: inline-block;
  border: 1px grey solid;
  padding: 5px;
}</code>```

<form>

</form>

<textarea id="t"></textarea>```

答:
For  selecting the checkbox id given in  target[]  use

```<code>if(target.indexOf(i)>=0){
        cb.checked =true ;
      }
</code>```

this will set checked attribute to the chekbox inside the target[].After that call

```<code>updateText();
</code>```

This will update the value inside the textbox

//array of options
var choices = new Array();
choices[0] = "January";
choices[1] = "February";
choices[2] = "March";
choices[3] = "April";
choices[4] = "May";
choices[5] = "Juny";
choices[6] = "July";
choices[7] = "August";
choices[8] = "September";
choices[9] = "October";
choices[10] = "November";
choices[11] = "December";

var target = new Array()
target[0] = "3";
target[1] = "8";

var cbh = document.getElementById('checkboxes');
var val = '';
var cap = "";

var j = "";
var t = document.getElementById('t');

// the loop is creating the checkboxes with name, value...
for (var i in choices) {
  //Name of checkboxes are their number so I convert the i into a string.
  j = i.toString();

  val = j;
  //cap will be the value/text of choices[i]
  var cb = document.createElement('input');
  var label = document.createElement("label");

  cap = choices[i];
  var text = document.createTextNode(cap);
  cb.type = 'checkbox';
  cbh.appendChild(cb);
  cb.name = cap;
  cb.value = val;
  label.appendChild(cb);
  label.appendChild(text);
  cbh.appendChild(label);
  cb.addEventListener('click', updateText)
  if(target.indexOf(i)>=0){
    cb.checked =true ;
  }

}
updateText();
function updateText() {
  t.value = [null, ...document.querySelectorAll('#checkboxes [type="checkbox"]')].reduce((s, el) => el && el.checked ? s = (s || '') + el.value + '$#' : s || '')
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>* {
  box-sizing: border-box;
}

#data {
  padding: 5px;
  width: 100vw;
}

.multiselect {
  overflow: visible;
  padding: 0;
  padding-left: 1px;
  border: none;
  background-color: #eee;
  width: 100vw;
  white-space: normal;
  height: 75px;
}

.checkboxes {
  height: 100px;
  width: 100px;
  border: 1px solid #000;
  background-color: white;
  margin-left: -1px;
  display: inline-block;
}

label {
  display: inline-block;
  border: 1px grey solid;
  padding: 5px;
}</code>```

<form>

</form>

<textarea id="t"></textarea>```

Body:
I got some difficulties with one point since 1 week, I have 2 arrays, and I want to auto select checkboxes by retrieving the value inside one of the array.

First of all, I have a loop which create some checkboxes based on the first array choices[].

Every time I check one a checkbox, a text field is updated with a separator. "$#"

I save this text field by my own. But now I have an array with some values as string target[].

I want to auto select checkboxes which has his value inside the array target[]. So if I change a value in target[], and I refresh, the checkbox concerned will be automatically selected.

Here is a snippet to see how it looks like now. Please update it to answer.

I would prefer JavaScript but if you have Jquery it would be ok.

//array of options
var choices = new Array();
choices[0] = "January";
choices[1] = "February";
choices[2] = "March";
choices[3] = "April";
choices[4] = "May";
choices[5] = "Juny";
choices[6] = "July";
choices[7] = "August";
choices[8] = "September";
choices[9] = "October";
choices[10] = "November";
choices[11] = "December";

var target = new Array()
target[0] = "3";
target[1] = "8";

var cbh = document.getElementById('checkboxes');
var val = '';
var cap = "";

var j = "";
var t = document.getElementById('t');

// the loop is creating the checkboxes with name, value...
for (var i in choices) {
  //Name of checkboxes are their number so I convert the i into a string.
  j = i.toString();

  val = j;
  //cap will be the value/text of choices[i]
  var cb = document.createElement('input');
  var label = document.createElement("label");

  cap = choices[i];
  var text = document.createTextNode(cap);
  cb.type = 'checkbox';
  cbh.appendChild(cb);
  cb.name = cap;
  cb.value = val;
  label.appendChild(cb);
  label.appendChild(text);
  cbh.appendChild(label);
  cb.addEventListener('click', updateText)

}

function updateText() {
  t.value = [null, ...document.querySelectorAll('#checkboxes [type="checkbox"]')].reduce((s, el) => el && el.checked ? s = (s || '') + el.value + '$#' : s || '')
}

* {
  box-sizing: border-box;
}

#data {
  padding: 5px;
  width: 100vw;
}

.multiselect {
  overflow: visible;
  padding: 0;
  padding-left: 1px;
  border: none;
  background-color: #eee;
  width: 100vw;
  white-space: normal;
  height: 75px;
}

.checkboxes {
  height: 100px;
  width: 100px;
  border: 1px solid #000;
  background-color: white;
  margin-left: -1px;
  display: inline-block;
}

label {
  display: inline-block;
  border: 1px grey solid;
  padding: 5px;
}

<form>

</form>

<textarea id="t"></textarea>

Body:
For  selecting the checkbox id given in  target[]  use

if(target.indexOf(i)>=0){
        cb.checked =true ;
      }

this will set checked attribute to the chekbox inside the target[].After that call

updateText();

This will update the value inside the textbox

//array of options
var choices = new Array();
choices[0] = "January";
choices[1] = "February";
choices[2] = "March";
choices[3] = "April";
choices[4] = "May";
choices[5] = "Juny";
choices[6] = "July";
choices[7] = "August";
choices[8] = "September";
choices[9] = "October";
choices[10] = "November";
choices[11] = "December";

var target = new Array()
target[0] = "3";
target[1] = "8";

var cbh = document.getElementById('checkboxes');
var val = '';
var cap = "";

var j = "";
var t = document.getElementById('t');

// the loop is creating the checkboxes with name, value...
for (var i in choices) {
  //Name of checkboxes are their number so I convert the i into a string.
  j = i.toString();

  val = j;
  //cap will be the value/text of choices[i]
  var cb = document.createElement('input');
  var label = document.createElement("label");

  cap = choices[i];
  var text = document.createTextNode(cap);
  cb.type = 'checkbox';
  cbh.appendChild(cb);
  cb.name = cap;
  cb.value = val;
  label.appendChild(cb);
  label.appendChild(text);
  cbh.appendChild(label);
  cb.addEventListener('click', updateText)
  if(target.indexOf(i)>=0){
    cb.checked =true ;
  }

}
updateText();
function updateText() {
  t.value = [null, ...document.querySelectorAll('#checkboxes [type="checkbox"]')].reduce((s, el) => el && el.checked ? s = (s || '') + el.value + '$#' : s || '')
}

* {
  box-sizing: border-box;
}

#data {
  padding: 5px;
  width: 100vw;
}

.multiselect {
  overflow: visible;
  padding: 0;
  padding-left: 1px;
  border: none;
  background-color: #eee;
  width: 100vw;
  white-space: normal;
  height: 75px;
}

.checkboxes {
  height: 100px;
  width: 100px;
  border: 1px solid #000;
  background-color: white;
  margin-left: -1px;
  display: inline-block;
}

label {
  display: inline-block;
  border: 1px grey solid;
  padding: 5px;
}

<form>
  <div id="data">
    <div class="multiselect">
      <div id="c_b">
        <div id="checkboxes">
        </div>
      </div>
    </div>
  </div>
</form>

<textarea id="t"></textarea>


问:
C# How can I prevent in this code that this error message occurs: Sequence contains no elements?
I have two Dictionaries. One with a list of columns from an Excel sheet and a list of defined columns. I wanna know if the defined columns exists in the sheet. If they exists then they will selected in a chosen dropdownlist.

In the row dropdownList.SelectedValue = selectedItem.First().Key; I get sometimes an errormessage Sequence contains no elements. I thought that I had coded safety. What do I forget?

... the command ...

```<code>SetDataSource(import.ColumnList, import.DefColumnList, ddlSomeColumn, SomeEnum.Zipcode);
</code>```

... and then the calling method ...

```<code>    private void SetDataSource(Dictionary<int, string> columnList, Dictionary<int, string> defColumnList, DropDownList dropdownList, SomeEnum item)
    {
        int index = (int)item;
        dropdownList.BeginUpdate();
        dropdownList.ValueMember = "Key";
        dropdownList.DisplayMember = "Value";
        dropdownList.DataSource = columnList;
        if (defColumnList.ContainsKey(index) && defColumnList[index].Length > 0)
        {
            var selectedItem = columnList.Where(cl => cl.Value == defColumnList[index]);
            if (selectedItem != null)
                dropdownList.SelectedValue = selectedItem.First().Key;
        }
        dropdownList.EndUpdate();
    }
</code>```

答:
The meaning of this error is that selectedItem is having no element while you are trying to access first element which is not possible.

Instead of checking nullability you should check is there any element inside the collection and then should execute First method on collection.

```<code>var selectedItem = columnList.Where(cl => cl.Value == defColumnList[index]);
if (selectedItem.Any())
    dropdownList.SelectedValue = selectedItem.First().Key;
</code>```

Body:
I have two Dictionaries. One with a list of columns from an Excel sheet and a list of defined columns. I wanna know if the defined columns exists in the sheet. If they exists then they will selected in a chosen dropdownlist.

In the row dropdownList.SelectedValue = selectedItem.First().Key; I get sometimes an errormessage Sequence contains no elements. I thought that I had coded safety. What do I forget?

... the command ...

SetDataSource(import.ColumnList, import.DefColumnList, ddlSomeColumn, SomeEnum.Zipcode);

... and then the calling method ...

    private void SetDataSource(Dictionary<int, string> columnList, Dictionary<int, string> defColumnList, DropDownList dropdownList, SomeEnum item)
    {
        int index = (int)item;
        dropdownList.BeginUpdate();
        dropdownList.ValueMember = "Key";
        dropdownList.DisplayMember = "Value";
        dropdownList.DataSource = columnList;
        if (defColumnList.ContainsKey(index) && defColumnList[index].Length > 0)
        {
            var selectedItem = columnList.Where(cl => cl.Value == defColumnList[index]);
            if (selectedItem != null)
                dropdownList.SelectedValue = selectedItem.First().Key;
        }
        dropdownList.EndUpdate();
    }

Body:
The meaning of this error is that selectedItem is having no element while you are trying to access first element which is not possible.

Instead of checking nullability you should check is there any element inside the collection and then should execute First method on collection.

var selectedItem = columnList.Where(cl => cl.Value == defColumnList[index]);
if (selectedItem.Any())
    dropdownList.SelectedValue = selectedItem.First().Key;


问:
table with columns data from different table
I want to create table with two columns and inserting data into columns from
two different tables. I'm using query which generates cross product of source table.

Query below :-

```<code>create table test
as
select a.offer_id as offer_id,b.poid as poid
from (select distinct offer_id from table1 limit 5) a, (select distinct poid from table2 limit 5) b;
</code>```

how to avoid cross product.

答:
I suspect you want something like this:</p>

```<code>select a.offer_id as offer_id, b.poid as poid
from (select offer_id, row_number() over (order by rand()) as seqnum
      from (select distinct offer_id from table1 limit 5) a
     ) a join
     (select poid, row_number() over (order by rand()) as seqnum
      from (select distinct poid from table2 limit 5) b
     ) b
     on a.seqnum = b.seqnum;
</code>```

Body:
I want to create table with two columns and inserting data into columns from
two different tables. I'm using query which generates cross product of source table.

Query below :-

create table test
as
select a.offer_id as offer_id,b.poid as poid
from (select distinct offer_id from table1 limit 5) a, (select distinct poid from table2 limit 5) b;

how to avoid cross product.

Body:
I suspect you want something like this:

select a.offer_id as offer_id, b.poid as poid
from (select offer_id, row_number() over (order by rand()) as seqnum
      from (select distinct offer_id from table1 limit 5) a
     ) a join
     (select poid, row_number() over (order by rand()) as seqnum
      from (select distinct poid from table2 limit 5) b
     ) b
     on a.seqnum = b.seqnum;


问:
Why using parallelStream access and modify Collection get different result?
I got confused about the following code

```<code>  public static void main(String[] args) throws InterruptedException
  {
    Integer[] intArray = {1, 2, 3, 4, 5, 6, 7, 8};
    List<Integer> listOfIntegers =
            new ArrayList<>(Arrays.asList(intArray));
    List<Integer> parallelStorage = new ArrayList<>();//Collections.synchronizedList(new ArrayList<>());
    listOfIntegers
            .parallelStream()
            // Don't do this! It uses a stateful lambda expression.
            .map(e -> {
                parallelStorage.add(e);
                return e;
            })
            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println();
    parallelStorage
            .stream()
            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println();
    System.out.println("Sleep 5 sec");
    TimeUnit.SECONDS.sleep(5);
    parallelStorage
            .stream()
            .forEachOrdered(e -> System.out.print(e + " "));
}
</code>```

EveryTime execute it I got different result which really confused me a lot ,
here are some results :

```<code>Result 1:
1 2 3 4 5 6 7 8
null 3 8 7 1 4 5 6
Sleep 5 sec
null 3 8 7 1 4 5 6

Result 2：
1 2 3 4 5 6 7 8
6 2 4 1 5 7 8
Sleep 5 sec
6 2 4 1 5 7 8
</code>```

Here are two problems:

Q1: Why the size of parallelStorage is uncertain?

I understand parallelStream using fork/join framework, so I guess the problem is caused by some thread who doesn't finish their job, then I paused the main thread for 5 seconds, but seems no help, the size of parallelStorage still kept unchanged;

Q2: Why null elements exist in parallelStorage?

答:
You have written yourself - this is a stateful lambda and these should be avoided. ArrayList is indeed not thread-safe and collecting to such a List will break things in an un-expcted way. Especially when the list needs to double it's size internally and copy elements. Generally there is no way to judge what will happen (or if it happens with such non thread-safe collection).

But even adding Collections.synchronizedList is still wrong, since it does not preserve order (in case you care). The only guarantee that you have is that all elements will be collected indeed, but in an out-of-order way.

```<code>    Integer[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 };
    List<Integer> listOfIntegers = new ArrayList<>(Arrays.asList(intArray));
    List<Integer> parallelStorage = Collections.synchronizedList(new ArrayList<>(1));
    listOfIntegers
            .parallelStream()
            // Don't do this! It uses a stateful lambda expression.
            .map(e -> {
                parallelStorage.add(e);
                return e;
            })
            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println(parallelStorage);
</code>```

The only thing you know for sure is that parallelStorage will indeed have all the elements from listOfIntegers (as opposed to the plain ArrayList where you saw a null); but otherwise the order will still be broken.

You could easily see results like this:

```<code>1 2 3 4 5 6 7 8 [3, 8, 5, 2, 7, 1, 4, 6]
</code>```

forEachOrdered preserves encounter order (if it is not broken by other intermediate operations, say unordered for example), but this order is preserved only for forEachOrdered, it does not mean that elements are still processed in the encounter order.

Body:
I got confused about the following code

  public static void main(String[] args) throws InterruptedException
  {
    Integer[] intArray = {1, 2, 3, 4, 5, 6, 7, 8};
    List<Integer> listOfIntegers =
            new ArrayList<>(Arrays.asList(intArray));
    List<Integer> parallelStorage = new ArrayList<>();//Collections.synchronizedList(new ArrayList<>());
    listOfIntegers
            .parallelStream()
            // Don't do this! It uses a stateful lambda expression.
            .map(e -> {
                parallelStorage.add(e);
                return e;
            })
            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println();
    parallelStorage
            .stream()
            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println();
    System.out.println("Sleep 5 sec");
    TimeUnit.SECONDS.sleep(5);
    parallelStorage
            .stream()
            .forEachOrdered(e -> System.out.print(e + " "));
}

EveryTime execute it I got different result which really confused me a lot ,
here are some results :

Result 1:
1 2 3 4 5 6 7 8
null 3 8 7 1 4 5 6
Sleep 5 sec
null 3 8 7 1 4 5 6

Result 2：
1 2 3 4 5 6 7 8
6 2 4 1 5 7 8
Sleep 5 sec
6 2 4 1 5 7 8

Here are two problems:

Q1: Why the size of parallelStorage is uncertain?

I understand parallelStream using fork/join framework, so I guess the problem is caused by some thread who doesn't finish their job, then I paused the main thread for 5 seconds, but seems no help, the size of parallelStorage still kept unchanged;

Q2: Why null elements exist in parallelStorage?

Body:
You have written yourself - this is a stateful lambda and these should be avoided. ArrayList is indeed not thread-safe and collecting to such a List will break things in an un-expcted way. Especially when the list needs to double it's size internally and copy elements. Generally there is no way to judge what will happen (or if it happens with such non thread-safe collection).

But even adding Collections.synchronizedList is still wrong, since it does not preserve order (in case you care). The only guarantee that you have is that all elements will be collected indeed, but in an out-of-order way.

    Integer[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 };
    List<Integer> listOfIntegers = new ArrayList<>(Arrays.asList(intArray));
    List<Integer> parallelStorage = Collections.synchronizedList(new ArrayList<>(1));
    listOfIntegers
            .parallelStream()
            // Don't do this! It uses a stateful lambda expression.
            .map(e -> {
                parallelStorage.add(e);
                return e;
            })
            .forEachOrdered(e -> System.out.print(e + " "));
    System.out.println(parallelStorage);

The only thing you know for sure is that parallelStorage will indeed have all the elements from listOfIntegers (as opposed to the plain ArrayList where you saw a null); but otherwise the order will still be broken.

You could easily see results like this:

1 2 3 4 5 6 7 8 [3, 8, 5, 2, 7, 1, 4, 6]

forEachOrdered preserves encounter order (if it is not broken by other intermediate operations, say unordered for example), but this order is preserved only for forEachOrdered, it does not mean that elements are still processed in the encounter order.


问:
What is the role of the curly braces when a module is required?
In this code snippet: </p>

```<code>const {set} = require("lodash");
</code>```

<p>What does the {} do ? </p>

答:
It's destructuring assignment.

It's equivalent to

```<code>const set = require('lodash').set
</code>```

Body:
In this code snippet:

const {set} = require("lodash");

What does the {} do ?

Body:
It's destructuring assignment.

It's equivalent to

const set = require('lodash').set


问:
Keychain sharing between two apps
Apple has provided Generic Keychain sample which is written in Swift, I want to go ahead with Objective-C.

I have enabled keychain sharing in both the apps and on canOpenUrl I am able to invoke application B from A, now I want to share username and password from app A to app B. App ID is same for both the applications.

I have looked at various tutorials also don't want to use any third party project.
Could not came to know how to pass the parameter from app A to app B.

答:
step 1:

Set URL Schemes and add the AppA's URL Scheme to the AppB's info.plist like this:<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>Aapp_Scheme</string>
    </array>

step 2:

In app A:

```<code>let url = URL.init(string: "B_Scheme://name=Obama&password=Trump");
    if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.open(url, options: ["":""], completionHandler: nil);
    }
</code>```

step 3:

In app B's AppDelegate.swift add the code:

```<code>func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    var name  = "", password = "";
    let param = url.absoluteString.replacingOccurrences(of: "B_Scheme://", with: "");
    let paramArray = param.components(separatedBy: "&");
    for temp in paramArray {
        if (temp.range(of: "name=") != nil){
            name = temp.replacingOccurrences(of: "name=", with: "");
        }
        else if (temp.range(of: "password=") != nil){
            password = temp.replacingOccurrences(of: "password=", with: "");
        }
    }
    if name == "Obama" && password == "Trump" {
        print("get param success!");
    }
    return true;
}
</code>```

Title: Keychain sharing between two apps

Body:
step 1:

Set URL Schemes and add the AppA's URL Scheme to the AppB's info.plist like this:<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>Aapp_Scheme</string>
    </array>

step 2:

In app A:

let url = URL.init(string: "B_Scheme://name=Obama&password=Trump");
    if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.open(url, options: ["":""], completionHandler: nil);
    }

step 3:

In app B's AppDelegate.swift add the code:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    var name  = "", password = "";
    let param = url.absoluteString.replacingOccurrences(of: "B_Scheme://", with: "");
    let paramArray = param.components(separatedBy: "&");
    for temp in paramArray {
        if (temp.range(of: "name=") != nil){
            name = temp.replacingOccurrences(of: "name=", with: "");
        }
        else if (temp.range(of: "password=") != nil){
            password = temp.replacingOccurrences(of: "password=", with: "");
        }
    }
    if name == "Obama" && password == "Trump" {
        print("get param success!");
    }
    return true;
}


答:
Your mapping is incorrect. Your response indicates that you getting one object back that has an array.

Add this class

```<code>public class MyResponse{
@SerialisedName("locations")
    List< LocationHealthResponse > locationHealthList;
}
</code>```

and your call would be Call<MyResponse> getResponse() instead of Call<LocationHealth> getResponse()

Body:
code for response class

public class LocationHealth implements HealthStatusIdentifiable{

@SerializedName("health")
int health;
@SerializedName("location")
String location;
@SerializedName("company")
String company;
@SerializedName("pos")
CompanyPos companyPos;
@SerializedName("rosters")
RosterHealth rosterHelath;
@SerializedName("cafe_tabs")
CafeHealth cafeHealth;

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getCompany() {
    return company;
}

public void setCompany(String company) {
    this.company = company;
}

public CompanyPos getCompanyPos() {
    return companyPos;
}

public void setCompanyPos(CompanyPos companyPos) {
    this.companyPos = companyPos;
}

public RosterHealth getRosterHelath() {
    return rosterHelath;
}

public void setRosterHelath(RosterHealth rosterHelath) {
    this.rosterHelath = rosterHelath;
}

public CafeHealth getCafeHealth() {
    return cafeHealth;
}

public void setCafeHealth(CafeHealth cafeHealth) {
    this.cafeHealth = cafeHealth;
}

@Override
public String toString() {
    return location+" : "+company+" : "+health;
}

@Override
public int getHealthStatus() {
    if(health==100){
        return GOOD;
    }else if(health>50){
        return WARN;
    }else
        return ALERT;
}

}

/CompanyPos.java/

 public class CompanyPos implements HealthStatusIdentifiable{

@SerializedName("inactive")
int inactive;
@SerializedName("active")
int active;
@SerializedName("name")
String name;
@SerializedName("health")
int health;

public int getTotal(){
    return inactive+active;
}

public int getInactive() {
    return inactive;
}

public void setInactive(int inactive) {
    this.inactive = inactive;
}

public int getActive() {
    return active;
}

public void setActive(int active) {
    this.active = active;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getHealth() {
    return health;
}

public void setHealth(int health) {
    this.health = health;
}

@Override
public int getHealthStatus() {
    if(inactive==0)
        return GOOD;
    if(inactive==1)
        return WARN;
    else
        return ALERT;
} }

JSON FORMAT

{   "locations": [
      {
        "pos": {
          "inactive": 7,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "FS-Cafeteria-Bangalore",
        "company": "FirstSource",
        "location_id": 1,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Cafe-Hyderabad",
        "company": "General Electric",
        "location_id": 19,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Shankar Narayan Building",
        "company": "Infinera",
        "location_id": 84,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco Space",
        "company": "Northern Trust",
        "location_id": 82,
        "company_id": 70
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "SMS",
        "company": "Genpact",
        "location_id": 79,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Surya Tech Park",
        "company": "Genpact",
        "location_id": 78,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Pritech",
        "company": "Genpact",
        "location_id": 77,
        "company_id": 67
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.G-ETAMIN -CSR",
        "company": "Qualcomm",
        "location_id": 70,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Aneja Towers",
        "company": "FirstSource",
        "location_id": 69,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TECCI Park",
        "company": "FirstSource",
        "location_id": 68,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ETA PARK-Chennai",
        "company": "FirstSource",
        "location_id": 67,
        "company_id": 1
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Prestige Solitaire Building",
        "company": "Infinera",
        "location_id": 44,
        "company_id": 22
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "RMZ Eco World",
        "company": "Epicor",
        "location_id": 2,
        "company_id": 3
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TVH Agnitio Park",
        "company": "Qualcomm",
        "location_id": 20,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-BTP",
        "company": "ABB",
        "location_id": 8,
        "company_id": 7
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "GE-Bengaluru",
        "company": "General Electric",
        "location_id": 5,
        "company_id": 5
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.E",
        "company": "Qualcomm",
        "location_id": 15,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.D",
        "company": "Qualcomm",
        "location_id": 14,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.C",
        "company": "Qualcomm",
        "location_id": 13,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 3,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "INDIA. N & T",
        "company": "Qualcomm",
        "location_id": 12,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO.B",
        "company": "Qualcomm",
        "location_id": 11,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BNGLO. H- Vector",
        "company": "Qualcomm",
        "location_id": 10,
        "company_id": 2
      },
      {
        "pos": {
          "inactive": 1,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Britannia Cafe",
        "company": "Britannia",
        "location_id": 17,
        "company_id": 8
      },
      {
        "pos": {
          "inactive": 4,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Ecoworld",
        "company": "British Telecom",
        "location_id": 7,
        "company_id": 6
      },
      {
        "pos": {
          "inactive": 2,
          "active": 0
        },
        "health": 66,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "BT- Pritech",
        "company": "British Telecom",
        "location_id": 6,
        "company_id": 6
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "ABB-HEBBAL",
        "company": "ABB",
        "location_id": 85,
        "company_id": 7
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Corporate",
        "company": "Corporate",
        "location_id": 4,
        "company_id": 4
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Paladion Cafe",
        "company": "Paladion",
        "location_id": 18,
        "company_id": 9
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Mystifly",
        "company": "Mystifly",
        "location_id": 81,
        "company_id": 68
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Whitefield",
        "company": "Technicolor",
        "location_id": 80,
        "company_id": 69
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "TEK MEDOWS-Chennai",
        "company": "FirstSource",
        "location_id": 66,
        "company_id": 1
      },
      {
        "pos": {
          "active": 0,
          "inactive": 0
        },
        "health": 100,
        "rosters": {
          "attended": 0,
          "rosters": 0
        },
        "cafe_tabs": {
          "live_tabs": 0,
          "total_cafe_tabs": 0
        },
        "location": "Bagmane Tech Park",
        "company": "Qualcomm",
        "location_id": 86,
        "company_id": 2
      }   ] }

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 16 path $.locations[0]

Body:
Your mapping is incorrect. Your response indicates that you getting one object back that has an array.

Add this class

public class MyResponse{
@SerialisedName("locations")
    List< LocationHealthResponse > locationHealthList;
}

and your call would be Call<MyResponse> getResponse() instead of Call<LocationHealth> getResponse()


问:
Deleting an element from redis list having stringified JSON as element of list in Node.js
I want to delete comment belonging to a post from redis. I am using list as my data structure. I tried using the LREM command(Syntax: LREM Key count value), but the value in my case is a stringified JSON object. So to  delete any comment for given post, everytime I have to put that whole JSON as the value in LREM. The JSON looks as:

"{\"_id\":\"5935374b535\",\"author\":{\"_id\":\"58382eae771\",\"user_id\":\"58382eae77149\",\"username\":\"hello_37\",,\"post_id\":{\"_id\":\"5919abd3b6a\",\"images\":[],\"description\":\"\",\"title\":\"Testing post\"},\"user_id\":\"58382eae77149d3d02204369\",\"mentions\":[\" cool comment5\"]\"is_approved\":true,\"text\":\" cool comment5\",\"__v\":0}"

This works, but is not a good approach. Can I delete the comment just using id for that comment(_id)? I am not able to find any command for deletion in list other LREM which uses the complete value of element in list.

答: I would suggest using storing each comment as a single entity, i.e create keys like so: POST:{userId}:{postId}:{commentId} and the corresponding value as a string. So if you want to delete a key you can simply say del POST:{userId}:{postId}:{commentId}. This is O(1) compared to O(N) for LREM. If you want to retrieve all the posts of a user then keys POST:{userId}:* will list all the posts' comments keys in redis and likewise for a post you can say keys POST:{userId}:{postId}:*


问:
Performing a bitwise sum
As part of a complex aggregate I want to know the bitwise sum of some data, i.e. if I have rows with values 1,1,1,2,2,8 the bitwise sum is 11. In this case the values are all exact powers of two (single bits), so I can hack around it by grouping and summing over the groups (obviously this example is a bit tortured compared to the real query):

```<code>select SUM(y.test)
from (
    select x.test
    from ( -- garbage test data
        select 1 as [test]
        union all select 1
        union all select 1
        union all select 2
        union all select 2
        union all select 8) x
group by x.test) y
</code>```

but is there a clean way to perform a bitwise sum in [T]SQL?

答:
You have the operator | which performs bitwise or for 2 operands. It is possible to solve your problem using a cursor and this operator.

Edit
yes I mixed up and and or, fixed.

Title: Performing a bitwise sum

Body:
As part of a complex aggregate I want to know the bitwise sum of some data, i.e. if I have rows with values 1,1,1,2,2,8 the bitwise sum is 11. In this case the values are all exact powers of two (single bits), so I can hack around it by grouping and summing over the groups (obviously this example is a bit tortured compared to the real query):

select SUM(y.test)
from (
    select x.test
    from ( -- garbage test data
        select 1 as [test]
        union all select 1
        union all select 1
        union all select 2
        union all select 2
        union all select 8) x
group by x.test) y

but is there a clean way to perform a bitwise sum in [T]SQL?


问:
Invoke-VMScript PowerCLI 6.5 Call Script with Parameters
I am currently developing a Script that should be able to attach a certain Windows share as a network drive with an drive letter in a host system. As the Windows share is dynamic (could change nearly all the time the script get's invoked.) I need to pass this as an parameter to the script running on the VM.

What I currently have.

In my script calling the script stored on my machine.

MainScript.ps1 contains.

```<code>$MyVMName = "somevmname"
$Script = "C:\path\to\script\somescript.ps1 -Path \\some\shared\folder"
Invoke-VMScript -VM $MyVMName -ScriptText $Script -ScriptType PowerShell -GuestCredential $MyGuestCredential
</code>```

somescript.ps1 contains.

```<code>Param(
      [Parameter(Mandatory=$true)]
      $Path,
      [Parameter(Mandatory=$true)]
      $Credentials
)

New-PSDrive -Name "H" -PSProvider FileSystem -Root $Path -Credential $Credentials
</code>```

Every time I'm executing my MainScript.ps1 it will most likely freeze when the Invoke-VMScript command is been executed. Is there another way to pass the parameters to the script?

The documentation found under

https://pubs.vmware.com/vsphere-65/index.jsp#com.vmware.powercli.cmdletref.doc/Invoke-VMScript.html

does not reveal too much using parameters for the invoked script.

答:
You could try to create a new PowerShell running the script:</p>

```<code>$MyVMName = "somevmname"
Invoke-VMScript -VM $MyVMName -ScriptText "powershell.exe -file C:\path\to\script\somescript.ps1 -Path \\some\shared\folder" -ScriptType PowerShell -GuestCredential $MyGuestCredential
</code>```

Body:
I am currently developing a Script that should be able to attach a certain Windows share as a network drive with an drive letter in a host system. As the Windows share is dynamic (could change nearly all the time the script get's invoked.) I need to pass this as an parameter to the script running on the VM.

What I currently have.

In my script calling the script stored on my machine.

MainScript.ps1 contains.

$MyVMName = "somevmname"
$Script = "C:\path\to\script\somescript.ps1 -Path \\some\shared\folder"
Invoke-VMScript -VM $MyVMName -ScriptText $Script -ScriptType PowerShell -GuestCredential $MyGuestCredential

somescript.ps1 contains.

Param(
      [Parameter(Mandatory=$true)]
      $Path,
      [Parameter(Mandatory=$true)]
      $Credentials
)

New-PSDrive -Name "H" -PSProvider FileSystem -Root $Path -Credential $Credentials

Every time I'm executing my MainScript.ps1 it will most likely freeze when the Invoke-VMScript command is been executed. Is there another way to pass the parameters to the script?

The documentation found under

https://pubs.vmware.com/vsphere-65/index.jsp#com.vmware.powercli.cmdletref.doc/Invoke-VMScript.html

does not reveal too much using parameters for the invoked script.

Body:
You could try to create a new PowerShell running the script:

$MyVMName = "somevmname"
Invoke-VMScript -VM $MyVMName -ScriptText "powershell.exe -file C:\path\to\script\somescript.ps1 -Path \\some\shared\folder" -ScriptType PowerShell -GuestCredential $MyGuestCredential


问:
Managing PHP Errors
I have been searching all over the net to try and find a way to catch all errors thrown by PHP (5.3)

I have been reading through the documentation and it looks like set_error_handler is what I need but it doesn't get fatal/parse errors. I'm not sure if this is possible...

Here is my source: https://github.com/tarnfeld/PHP-Error-Handler
Feel free to fork/commit if you know better solutions to all of this.

Thanks in advanced!

Updated!

Using the answers below I finished writing an error handler, it takes care of E_ERROR|E_PARSE|E_WARNING|E_NOTICE and will kill the script when it is fatal! :-)

答:
If you want to catch fatal errors (including parse errors) the the best solution is to set up error_logging in the php.ini file, e.g.</p>

```<code>display_errors = Off
log_errors = On
ignore_repeated_errors = Off
ignore_repeated_source = Off
</code>```

Title: Managing PHP Errors

Body:
If you want to catch fatal errors (including parse errors) the the best solution is to set up error_logging in the php.ini file, e.g.

display_errors = Off
log_errors = On
ignore_repeated_errors = Off
ignore_repeated_source = Off


问:
CAS ReST - Add Service
I am trying to add a new service to CAS via their ReST API. First it said that "Attribute name and/or value must be configured". Then I added attribute name and attribute value with some junk value to the CAS properties. Now it says that the Request could not be authenticated. This is how I am making a request

POST

```<code>localhost:8443/cas/v1/services/add/TGT-1-CHZrXD5XAulLuUgoMDQudTe6j16k5k41XBQH640wHFhbuq9QWY-xoadmin
</code>```

BODY

```<code>{
    "@class" : "org.apereo.cas.services.RegexRegisteredService",
    "serviceId" : "service name",
    "name" : "xosso",
    "id" : 2,
    "evaluationOrder" : 10,
    "proxyPolicy" : {
         "@class" : "org.apereo.cas.services.RegexMatchingRegisteredServiceProxyPolicy",
         "pattern" : "^https?://.*"
    }
}
</code>```

PS : I tried sending it part of the URL, still it says the same error.

答:
You have to add first the header application/x-www-form-urlencoded
also for the value and key you have to add on of the attributes keys from your user attributes and the expected attribute value
for me for example i put : </p>

```<code>cas.rest.attributeName=memberOf
cas.rest.attributeValue=cn=Administrator,....
cas.rest.throttler=neverThrottle
</code>```

ContentLicense: CC BY-SA 4.0

Title: CAS ReST - Add Service

Body:
I am trying to add a new service to CAS via their ReST API. First it said that "Attribute name and/or value must be configured". Then I added attribute name and attribute value with some junk value to the CAS properties. Now it says that the Request could not be authenticated. This is how I am making a request

POST

localhost:8443/cas/v1/services/add/TGT-1-CHZrXD5XAulLuUgoMDQudTe6j16k5k41XBQH640wHFhbuq9QWY-xoadmin

BODY

{
    "@class" : "org.apereo.cas.services.RegexRegisteredService",
    "serviceId" : "service name",
    "name" : "xosso",
    "id" : 2,
    "evaluationOrder" : 10,
    "proxyPolicy" : {
         "@class" : "org.apereo.cas.services.RegexMatchingRegisteredServiceProxyPolicy",
         "pattern" : "^https?://.*"
    }
}

PS : I tried sending it part of the URL, still it says the same error.

Body:
You have to add first the header application/x-www-form-urlencoded
also for the value and key you have to add on of the attributes keys from your user attributes and the expected attribute value
for me for example i put :

cas.rest.attributeName=memberOf
cas.rest.attributeValue=cn=Administrator,....
cas.rest.throttler=neverThrottle


问:
Group and count values in an array
I have an array with objects, like the following.

```<code>b = {
  "issues": [{
    "fields": {
      "status": {
        "id": "200",
        "name": "Backlog"
      }
    }
  }, {
    "fields": {
      "status": {
        "id": "202",
        "name": "close"
      }
    }
  }, {
    "fields": {
      "status": {
        "id": "201",
        "name": "close"
      }
    }
  }]
};
</code>```

I want to count how many issues have status close, and how many have backlog. I'd like to save the count in a new array as follows.

```<code>a = [
  {Name: 'Backlog', count: 1},
  {Name: 'close', count: 2}
];
</code>```

I have tried the following.

```<code>b.issues.forEach(function(i) {
  var statusName = i.fields.status.name;

  if (statusName in a.Name) {
    a.count = +1;
  } else {
    a.push({
      Name: statusName,
      count: 1
    });
  }
});
</code>```

That however doesn't seem to be working. How should I implement this?

答:
Using ES6 Arrow functions you can do it with minimum syntax

```<code>var b = {
    "issues": [{
        "fields": {
            "status": {
                "id": "200",
                "name": "Backlog"
            }
        }
    }, {
        "fields": {
            "status": {
                "id": "202",
                "name": "close"
            }
        }
    }, {
        "fields": {
            "status": {
                "id": "201",
                "name": "close"
            }
        }
    }]
};

var countOfBackLog = b.issues.filter(x => {
return x.fields.status.name === "Backlog"
}).length

var countOfClose = b.issues.filter(x => {
return x.fields.status.name === "close"
}).length

a =[{Name: 'Backlog', count : countOfBackLog}, {Name: 'close', count : countOfClose}]
</code>```

More about arrow functions here

Title: Group and count values in an array

Body:
I have an array with objects, like the following.

b = {
  "issues": [{
    "fields": {
      "status": {
        "id": "200",
        "name": "Backlog"
      }
    }
  }, {
    "fields": {
      "status": {
        "id": "202",
        "name": "close"
      }
    }
  }, {
    "fields": {
      "status": {
        "id": "201",
        "name": "close"
      }
    }
  }]
};

I want to count how many issues have status close, and how many have backlog. I'd like to save the count in a new array as follows.

a = [
  {Name: 'Backlog', count: 1},
  {Name: 'close', count: 2}
];

I have tried the following.

b.issues.forEach(function(i) {
  var statusName = i.fields.status.name;

  if (statusName in a.Name) {
    a.count = +1;
  } else {
    a.push({
      Name: statusName,
      count: 1
    });
  }
});

That however doesn't seem to be working. How should I implement this?

Body:
Using ES6 Arrow functions you can do it with minimum syntax

var b = {
    "issues": [{
        "fields": {
            "status": {
                "id": "200",
                "name": "Backlog"
            }
        }
    }, {
        "fields": {
            "status": {
                "id": "202",
                "name": "close"
            }
        }
    }, {
        "fields": {
            "status": {
                "id": "201",
                "name": "close"
            }
        }
    }]
};

var countOfBackLog = b.issues.filter(x => {
return x.fields.status.name === "Backlog"
}).length

var countOfClose = b.issues.filter(x => {
return x.fields.status.name === "close"
}).length

a =[{Name: 'Backlog', count : countOfBackLog}, {Name: 'close', count : countOfClose}]

More about arrow functions here


问:
jQuery Tabs and Button in IE6
I have an issue in IE6 (no surprise) where button elements are hovering in IE6 rather than being positioned correctly in Firefox, Chrome and Opera. This seems only to occur when clicking a non-selected tab.

The CSS and JS are the latest versions of JQuery UI.

Has anyone experienced this issue?

[Edit] My apologies, I forgot to add a screenshot :)

The issue seems to arise when the content is dynamically generated and I select another tab. When the content generates again (cookie keeps the current selected tab on page refresh), the content moves to the correct place.

答: Seems to be the order in which the JS is called is the issue!</p>

Title: jQuery Tabs and Button in IE6


问:
How can i sort the list and print in react?
How can i sort the data and print in react.
which libraries do i need to use ?
here is the data which is to be sorted field wise</p>

```<code>data = [{
    key: 1,
    name: 'Steve',
    city: 'Paris',
  }, {
    key: 2,
    name: 'Tim',
    city: 'London',
  }, {
    key: 3,
    name: 'Stella',
    city: 'Bankok',
  }, {
    key: 4,
    name: 'John',
    city: 'Paris',
}];
</code>```

答:
Use Array.prototype.sort() for this.

Check this example:

data = [{
    key: 1,
    name: 'Steve',
    city: 'Paris',
  }, {
    key: 2,
    name: 'Tim',
    city: 'London',
  }, {
    key: 3,
    name: 'Stella',
    city: 'Bankok',
  }, {
    key: 4,
    name: 'John',
    city: 'Paris',
}];

data.sort((a,b) => a.name > b.name);

console.log('updated data', data)```

Body:
How can i sort the data and print in react.
which libraries do i need to use ?
here is the data which is to be sorted field wise

data = [{
    key: 1,
    name: 'Steve',
    city: 'Paris',
  }, {
    key: 2,
    name: 'Tim',
    city: 'London',
  }, {
    key: 3,
    name: 'Stella',
    city: 'Bankok',
  }, {
    key: 4,
    name: 'John',
    city: 'Paris',
}];