EmailValidator.getInstance().isValid("some.mail.address@gmail.com");
Make sure to add the Commons Validator jar file and it's dependencies to your project.
Software development and photography related issues
EmailValidator.getInstance().isValid("some.mail.address@gmail.com");
This question should be asked more precisely: How can array of size N filled with numbers up to N (0 to N – 1) be scanned for duplicate values (or more) with one scan (O(n))?
The answer lies in the body of the question: The fact that the array is filled with numbers up to N only, implies that a helper array of size N can be used to store the number of times each number appears in the first array. The value of the number in the first array is used as an index in the helper array. For example, if the first value in the array is: 5, then the 5th element in the helper array is incremented by 1. Of course, before incrementing the value in the helper array, we check if it is larger than 0. If it is larger than 0, the value of the first array was already counted once, and this current value is a duplicate.
The code of such method is very simple, lets have a look:
public class ArrayDuplicates {public static boolean isDuplicate(int[] arr){int size = arr.length;int[] helperArr = new int[size];for (int i = 0; i < size; i++){if (helperArr[arr[i]]++ > 0){return true;}}return false;}public static void main(String[] args){System.out.println(isDuplicate(new int[] { 2, 1, 0 }));System.out.println(isDuplicate(new int[] { 2, 0, 2 }));}}
Note, that incrementing the index of the helper array (according to the value from the first array) and checking if we have already counted this number is all done the “if” sentence.
Person person = new Person("guy");List<Person> persons = new ArrayList<Person>();
persons.add(person);System.out.println(persons.contains(person));
public class GetBits {public static int countBits(byte num){int count = 0;
for (int i = 0; i < 8; i++){if ((num & 1) == 1) // check if right most bit is 1{count++;}num = (byte)(num >>> 1); // shit right 1 bit, including the sign bit}return count;
}
public static int countBits(byte num){int count = 0;
while (num > 0)
{if (num % 2 == 1) // check if number have modulo{count++;}num /= 2; // divide the number by 2
}return count;
}
=OFFSET(data!$A$1,0,0, COUNTA(data!$A:$A), COUNTA(data!$1:$1))
Now, put in your sources root directory (usually the “src”) the file: “seam.quartz.properties” file. A typical file may look like this:<async:quartz-dispatcher/><event type="org.jboss.seam.postInitialization"><action execute="#{quartzController.scheduleTimer}"/></event>
Now, to the Java code. The code is constructed from 2 Seam beans. The first bean contains the Quartz trigger class. I looks like:org.quartz.scheduler.instanceName = Sched1org.quartz.scheduler.instanceId = 1org.quartz.scheduler.rmi.export = falseorg.quartz.scheduler.rmi.proxy = falseorg.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPoolorg.quartz.threadPool.threadCount = 3org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
Note, that when calling to “doJob” method, a cron expression is passed. This expression describes the frequency in which the job will run (event minute in the example).package com.bashan.blog.job;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.async.QuartzTriggerHandle;
import java.io.Serializable;
import java.util.Date;
/**
* @author Bashan*/@Name("quartzController")
@AutoCreatepublic class QuartzController implements Serializable {@InScheduleProcessor processor;private QuartzTriggerHandle quartzTriggerHandleDoJob;
public void scheduleTimer() {quartzTriggerHandleDoJob = processor.doJob(new Date(), "0 0/1 * * * ?");}}
The method “doJob” is a Seam asynchronous method. This method will be executed according to the data of the cron expression given in the class: QuartzController.package com.bashan.blog.job;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.async.Asynchronous;
import org.jboss.seam.annotations.async.Expiration;
import org.jboss.seam.annotations.async.IntervalCron;
import org.jboss.seam.async.QuartzTriggerHandle;
import org.jboss.seam.log.Log;
import java.util.Date;
/**
* @author Bashan*/@Name("processor")
@AutoCreate@Scope(ScopeType.APPLICATION)public class ScheduleProcessor {@Loggerstatic Log log;
@Asynchronouspublic QuartzTriggerHandle doJob(@Expiration Date when, @IntervalCron String interval) {
System.out.println("I am a Quartz job.");
log.debug("Pass some information to the log");
return null;}}