Add an object to a java arraylist only if it isn't already there
I have an arrayList that I want to add to, as long as the value isn't
already stored in it. For example if my array is like this:
H
LK
KL
LS
And I have the value LS, it wouldn't be added. But if the value was A, it
would be.
I was thinking that the code should look something like this:
value = A;
no = 0;
for (int o; arraylist.length; o++)
if (arraylist.get(o).equals(value)){
continue;
}else{
no++;
}
}
if (arraylist.length = no){
arraylist.add(value);
}
But there has to be an easier way to do it. Does anyone know a more
concise way to do this?
Tuesday, 10 September 2013
JavaScript code explanation (events + canvas) [sigma.js]
JavaScript code explanation (events + canvas) [sigma.js]
Here is some code that I have from sigma.js:
function f(event)
{
sigInst.iterNodes(function(n){
node = n;
},[event.content[0]]);
alert();
}
sigInst.bind('click',f).bind('outnodes',f).draw();
I don't understand this:
from where function f gets the event? no one passes it.
line },[event.content[0]]);
Can I add events to canvas elements? sigma.js draws a canvas and then (I
don't understand how) there is an event listeners on click and outnodes.
How does this happens?
Thanks
Here is some code that I have from sigma.js:
function f(event)
{
sigInst.iterNodes(function(n){
node = n;
},[event.content[0]]);
alert();
}
sigInst.bind('click',f).bind('outnodes',f).draw();
I don't understand this:
from where function f gets the event? no one passes it.
line },[event.content[0]]);
Can I add events to canvas elements? sigma.js draws a canvas and then (I
don't understand how) there is an event listeners on click and outnodes.
How does this happens?
Thanks
Symfony2.3 many to many form
Symfony2.3 many to many form
I'm having some issues getting many to many to work on my form.
My form is laid out in the following way:
User (FOSUserBundle)
Member (custom class)
Region (custom class)
The member form is a subform of the user form, and the region form is a
subform of the member form.
Firstly, the error I'm getting is:
Neither the property "region" nor one of the methods "setRegion()",
"_set()" or "_call()" exist and have public access in class
"Netsite\Bundle\AdminBundle\Entity\Member".
This happens when I submit the form and it hits the:
$form->handleRequest($request);
Here is all the relevant code:
Member.orm.yml
Netsite\Bundle\AdminBundle\Entity\Member:
type: entity
table: member
id:
id:
type: integer
generator:
strategy: AUTO
fields:
security_question:
type: string
length: 255
security_answer:
type: string
length: 255
----- SNIP -----
manyToMany:
region:
targetEntity: Region
cascade: ["persist", "remove"]
Entity\Member.php
<?php
namespace Netsite\Bundle\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Member
*/
class Member
{
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $region;
/**
* Constructor
*/
public function __construct()
{
$this->region = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add region
*
* @param \Netsite\Bundle\AdminBundle\Entity\Region $region
* @return Member
*/
public function addRegion(\Netsite\Bundle\AdminBundle\Entity\Region
$region)
{
$this->region[] = $region;
return $this;
}
/**
* Remove region
*
* @param \Netsite\Bundle\AdminBundle\Entity\Region $region
*/
public function removeRegion(\Netsite\Bundle\AdminBundle\Entity\Region
$region)
{
$this->region->removeElement($region);
}
/**
* Get region
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRegion()
{
return $this->region;
}
Form\MemberType.php
<?php
namespace Netsite\Bundle\AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
class MemberType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array
$options) {
$builder
->add('region', new RegionType())
Region.orm.yml
Netsite\Bundle\AdminBundle\Entity\Region:
type: entity
table: region
id:
id:
type: integer
generator:
strategy: AUTO
fields:
region:
type: string
length: 255
Entity\Region.php
<?php
namespace Netsite\Bundle\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Region
*/
class Region
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $region;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set region
*
* @param string $region
* @return Region
*/
public function setRegion($region)
{
$this->region = $region;
return $this;
}
/**
* Get region
*
* @return string
*/
public function getRegion()
{
return $this->region;
}
}
Form\RegionType.php
<?php
namespace Netsite\Bundle\AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class RegionType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array
$options) {
$builder
->add('region', 'entity', array(
'class' => 'Netsite\Bundle\AdminBundle\Entity\Region',
'property' => 'region',
'empty_data' => null,
'multiple' => true,
'expanded' => true,
'required' => false,
'label' => false
))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Netsite\Bundle\AdminBundle\Entity\Region',
'cascade_validation' => true
));
}
public function getName() {
return 'RegionType';
}
}
I have no idea what I'm doing wrong.
I'm having some issues getting many to many to work on my form.
My form is laid out in the following way:
User (FOSUserBundle)
Member (custom class)
Region (custom class)
The member form is a subform of the user form, and the region form is a
subform of the member form.
Firstly, the error I'm getting is:
Neither the property "region" nor one of the methods "setRegion()",
"_set()" or "_call()" exist and have public access in class
"Netsite\Bundle\AdminBundle\Entity\Member".
This happens when I submit the form and it hits the:
$form->handleRequest($request);
Here is all the relevant code:
Member.orm.yml
Netsite\Bundle\AdminBundle\Entity\Member:
type: entity
table: member
id:
id:
type: integer
generator:
strategy: AUTO
fields:
security_question:
type: string
length: 255
security_answer:
type: string
length: 255
----- SNIP -----
manyToMany:
region:
targetEntity: Region
cascade: ["persist", "remove"]
Entity\Member.php
<?php
namespace Netsite\Bundle\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Member
*/
class Member
{
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $region;
/**
* Constructor
*/
public function __construct()
{
$this->region = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add region
*
* @param \Netsite\Bundle\AdminBundle\Entity\Region $region
* @return Member
*/
public function addRegion(\Netsite\Bundle\AdminBundle\Entity\Region
$region)
{
$this->region[] = $region;
return $this;
}
/**
* Remove region
*
* @param \Netsite\Bundle\AdminBundle\Entity\Region $region
*/
public function removeRegion(\Netsite\Bundle\AdminBundle\Entity\Region
$region)
{
$this->region->removeElement($region);
}
/**
* Get region
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRegion()
{
return $this->region;
}
Form\MemberType.php
<?php
namespace Netsite\Bundle\AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
class MemberType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array
$options) {
$builder
->add('region', new RegionType())
Region.orm.yml
Netsite\Bundle\AdminBundle\Entity\Region:
type: entity
table: region
id:
id:
type: integer
generator:
strategy: AUTO
fields:
region:
type: string
length: 255
Entity\Region.php
<?php
namespace Netsite\Bundle\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Region
*/
class Region
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $region;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set region
*
* @param string $region
* @return Region
*/
public function setRegion($region)
{
$this->region = $region;
return $this;
}
/**
* Get region
*
* @return string
*/
public function getRegion()
{
return $this->region;
}
}
Form\RegionType.php
<?php
namespace Netsite\Bundle\AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class RegionType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array
$options) {
$builder
->add('region', 'entity', array(
'class' => 'Netsite\Bundle\AdminBundle\Entity\Region',
'property' => 'region',
'empty_data' => null,
'multiple' => true,
'expanded' => true,
'required' => false,
'label' => false
))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Netsite\Bundle\AdminBundle\Entity\Region',
'cascade_validation' => true
));
}
public function getName() {
return 'RegionType';
}
}
I have no idea what I'm doing wrong.
NSTimeZone timeZoneWithName:@"America/New_York" works not properly
NSTimeZone timeZoneWithName:@"America/New_York" works not properly
The server returns me the right date & time. New York time zone.
2013-09-10 05:37:07 +0000 (the right time, when comment was posted)
Here's how I format it in the app:
[format setDateFormat:@"dd MMM, yyyy HH:mm"];
[format setTimeZone:[NSTimeZone timeZoneWithName:@"America/New_York"]];
And as the result I have
10 sept, 2013 01:37
What's wrong?
UPD
The code
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setTimeZone:[NSTimeZone timeZoneWithName:@"America/New_York"]];
[format setDateFormat:@"dd MMM, yyyy hh:mm"];
NSString *stringDate = [format stringFromDate:Date]; //Date is
"2013-09-10 05:37:07 +0000"
The server returns me the right date & time. New York time zone.
2013-09-10 05:37:07 +0000 (the right time, when comment was posted)
Here's how I format it in the app:
[format setDateFormat:@"dd MMM, yyyy HH:mm"];
[format setTimeZone:[NSTimeZone timeZoneWithName:@"America/New_York"]];
And as the result I have
10 sept, 2013 01:37
What's wrong?
UPD
The code
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setTimeZone:[NSTimeZone timeZoneWithName:@"America/New_York"]];
[format setDateFormat:@"dd MMM, yyyy hh:mm"];
NSString *stringDate = [format stringFromDate:Date]; //Date is
"2013-09-10 05:37:07 +0000"
how to create a calculated column in mysql which calculate date from timestamp column having varchar type
how to create a calculated column in mysql which calculate date from
timestamp column having varchar type
I m stuck in a big problem. I want to create a calculated column in an
existing table having a column name LS_TimeStamp of Varchar(20) type which
store both date and time in format (0000-00-00 . 00:00:00) and i want a
calculated column which extract only date from that column and stores in
'Date' column which is also a Varchar(20) type.
Thanks in advance :)
timestamp column having varchar type
I m stuck in a big problem. I want to create a calculated column in an
existing table having a column name LS_TimeStamp of Varchar(20) type which
store both date and time in format (0000-00-00 . 00:00:00) and i want a
calculated column which extract only date from that column and stores in
'Date' column which is also a Varchar(20) type.
Thanks in advance :)
Monday, 9 September 2013
Maximum clients connected to server
Maximum clients connected to server
I am using Windows environment and i am not able to check the number of
clients getting connected to one of the ports on my server.
I have tried netstat command but it does not meet my requirement. Can
anyone please let me know how to find this out?
I am using Windows environment and i am not able to check the number of
clients getting connected to one of the ports on my server.
I have tried netstat command but it does not meet my requirement. Can
anyone please let me know how to find this out?
The Command-T how to use current file own NERDTree bookmark as search directory?
The Command-T how to use current file own NERDTree bookmark as search
directory?
I like NERDTree and Command-T. So i want use Command-T search file for
current project. (I use NERDTree bookmark as project). Because the
Command-T use :CommandT to active search , and default is pwd. I want
change the to current file own NERDTree bookmark path.
Like this:
I have a bookmark called "TestProject" and the path is "~/testproject".
Now ,I'm writing file is "~/testproject/class/test.php", If use :CommandT
, I will get search directory is "~/testproject/class/" . But i want
search global project ("~/test/project"),and i don't want to type
:CommandT ~/testproject/ .
Thx!
directory?
I like NERDTree and Command-T. So i want use Command-T search file for
current project. (I use NERDTree bookmark as project). Because the
Command-T use :CommandT to active search , and default is pwd. I want
change the to current file own NERDTree bookmark path.
Like this:
I have a bookmark called "TestProject" and the path is "~/testproject".
Now ,I'm writing file is "~/testproject/class/test.php", If use :CommandT
, I will get search directory is "~/testproject/class/" . But i want
search global project ("~/test/project"),and i don't want to type
:CommandT ~/testproject/ .
Thx!
Subscribe to:
Posts (Atom)