Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ejb file
package com.washingtonpost.mentionmachine.processing.beans;
import javax.annotation.PostConstruct;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import java.util.Calendar;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.*;
/**
* Session Bean implementation class MentionMachineQueryBean
*/
@Singleton
@LocalBean
public class MentionMachineQueryBean {
public HashMap<String, HashMap> Symbols;
/**
* Default constructor.
*/
public MentionMachineQueryBean() {
// TODO Auto-generated constructor stub
}
@PostConstruct
public void postConstruct(){
//creating hashtable 1
Symbols = new HashMap<String, HashMap>();
Symbols.put("ATVI",new HashMap<Long, AtomicInteger>());
Symbols.put("ADBE",new HashMap<Long, AtomicInteger>());
Symbols.put("AKAM",new HashMap<Long, AtomicInteger>());
Symbols.put("EVAN",new HashMap<Long, AtomicInteger>());
System.out.println(Symbols);
Calendar currentHour = Calendar.getInstance();
currentHour.set(Calendar.MILLISECOND, 0);
currentHour.set(Calendar.SECOND, 0);
currentHour.set(Calendar.MINUTE, 0);
long epoch = currentHour.getTimeInMillis();
int counter = 0;
}
public void processMessage(String message) {
boolean matches = checkForEntity("AAPL", message);
System.out.println(matches);
}
public void printSymbols(){
do {
for ( String key : Symbols.keySet()){
HashMap<Long,AtomicInteger> countMap = Symbols.get(key);
AtomicInteger i = countMap.get(epoch);
if (i != null) {
i.getAndIncrement();
}
else {
//give separate atomic ints for values. then add a new hashmap. iterate number of hashmap.
countMap.put(epoch, new AtomicInteger(1));
}
}
System.out.println(Symbols);
counter++;
} while (counter < 5);
}
private boolean checkForEntity(String entity, String message) {
int match = message.indexOf(entity);
if (match == -1 ) {
return false;
} else {
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment