id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
8af123e5-8be8-46f6-8d3b-ac5d9e21f625 | @Override
public int getANumber() {
return ++i;
} |
f87a2e0d-7eb1-4aa7-ab88-d569685c5388 | @Bean
@Override
public NumberProvider getNumberProvider() {
return new NumberProviderImpl();
} |
d5eb6b9f-8704-4ac4-ba42-5113cdea4a3c | public static void main(String[] args) {
MyApp myApp = new MyApp();
myApp.start();
} |
297891d7-af54-4e45-9670-8e902b3fafe5 | private void start() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppSpringConfig.class);
MyLib theLib = context.getBean(MyLib.class);
theLib.doSomeJob();
} |
1bb28c52-d2d8-433b-9406-cc5dfe331a70 | @Override
public int add2Numbers() {
int number1 = libClientNumberProvider.getANumber();
int number2 = libClientNumberProvider.getANumber();
int result = number1 + number2;
return result;
} |
5d88b16d-d878-4719-a3dc-56383f1b2189 | public NumberGeneratorExempleImplConstructor(NumberProvider libClientNumberProvider) {
this.libClientNumberProvider = libClientNumberProvider;
} |
2afbdc72-29dd-4f17-be1d-27260dc35c1d | @Override
public int add2Numbers() {
int number1 = libClientNumberProvider.getANumber();
int number2 = libClientNumberProvider.getANumber();
int result = number1 + number2;
return result;
} |
5f8a3d90-6c8e-4872-aaaf-29a9bee3bd55 | @Bean
public MyLib getMyLib() {
return new MyLib();
} |
d646feb0-c951-4923-8900-2ace549b3c08 | @Bean(name = "numberGenerator1")
public NumberGenerator getNumberGenerator1() {
return new NumberGeneratorExempleImplConstructor(clientConfig.getNumberProvider());
} |
bf1c1b22-c3a3-4177-9b79-0a21a903d13a | @Bean(name = "numberGenerator2")
public NumberGenerator getNumberGenerator2() {
return new NumberGeneratorExempleImplConstructor(clientConfig.getNumberProvider());
} |
00ce919d-6fa2-494a-a899-1799e32d01fc | void doSomeJob() {
int result1 = numberGenerator1.add2Numbers();
int result2 = numberGenerator2.add2Numbers();
log.info("result1= {}, result2= {}", result1, result2);
} |
8a6f2e52-627e-4415-ba80-102a5d13f18f | public int add2Numbers(); |
a7361097-c365-4613-b3d5-c71c7b044b7c | NumberProvider getNumberProvider(); |
575f4e48-f122-426f-b492-c50843130048 | int getANumber(); |
8c52af04-e1b4-410d-ae3a-8fad9fcc99ab | public static synchronized void addLink(String url) {
// which bucket does the url belong in
int bucket = Math.abs(url.hashCode() % mNumThreads);
// Log.d(TAG, String.format("Putting: %s in bucket: %d", url, bucket), 3);
// List of urls for a thread to crawl
ArrayList<String> ite... |
bde15074-2121-49ff-a2e9-d8313e7feb60 | public static ArrayList<String> getQueue(int tid) {
return mLinkQueue.get(tid);
} |
bb2ce818-711e-45e8-8970-c029b5766604 | public static synchronized String getUrl(int tid) {
return mLinkQueue.get(tid).remove(0);
} |
8098f51c-ba09-4720-9a2d-27e82ae86b6f | public static synchronized boolean isQueueEmpty(int tid) {
try {
return mLinkQueue.get(tid).isEmpty();
} catch (NullPointerException e) {
return true;
}
} |
ec7e7cb0-260b-457a-ba4b-dae2209c7899 | public static int getQueueSize(int tid) {
return mLinkQueue.get(tid).size();
} |
090bf563-3241-4a4a-8bc8-69f05feac8cf | public static boolean inQueue(int tid, String u) {
return mLinkQueue.get(tid).contains(u);
} |
a2d8091a-1c8b-4937-a0c2-8e6141c40916 | public static String getFirstPartOfURL(String s) {
return s.split("/")[2];
} |
b362b312-3d5a-4e78-bc49-2d816983450a | public static void setNumThreads(int i) {mNumThreads = i;} |
3ea825f1-ef66-4815-b689-dd6e965dc6e3 | public Parser() {
this.mURLValidator = new UrlValidator(new String[]{"http", "https"});
} |
f9ea2068-dbc9-460f-bb09-3a4638d82c38 | public void parseDocument(String url) {
try{
long begin = System.currentTimeMillis()/1000;
this.mDocument = Jsoup.connect(url).get(); // get the next page
this.pageLoadTime = System.currentTimeMillis()/1000 - begin;
} catch(IOException e) {
Log.d(TAG,Stri... |
aca19772-247b-4813-bee6-9d8c185ae563 | public ArrayList<String> getUrls() {
ArrayList<String> links = new ArrayList<String>();
// Get all the links on a page
// Start building our seed
for(Element e : this.mDocument.getElementsByTag("a")) {
// make sure the url is valid, if it is push it onto our "queue"
... |
1aebfe20-d9b1-454e-9e5b-6e18184a0202 | public String getBody() {
return StringEscapeUtils.escapeHtml(this.mDocument.body().toString());
} |
b6b4d0e0-f087-4f32-8220-f02ec89be15b | public String getTitle() {
return StringEscapeUtils.escapeHtml(this.mDocument.title());
} |
d4cec5b6-65d3-45d7-9ce5-1a5efba02575 | public String getWholePage() {
return StringEscapeUtils.escapeHtml(this.mDocument.html());
} |
1f963d83-1c14-4bbf-8ab6-5b556c89a975 | public long getPageLoadTime(){
return this.pageLoadTime;
} |
cf19464a-e799-4a6a-80c9-27f074d6f01e | public String getHead() {
return StringEscapeUtils.escapeHtml(this.mDocument.head().html());
} |
5537533b-c29d-462a-9744-e29424a6d0db | public MySQLHelper() {
this.connector = Connector.getInstance();
this.connection = this.connector.getConnection();
try {
this.statement = this.connection.createStatement();
this.dbAvailable = true;
} catch(Exception e) {
Log.d(TAG, "Error creating stat... |
36cd25ef-dda2-4a78-bc41-371806bb8886 | public ResultSet runSql(String sql) throws SQLException {
Statement sta = connection.createStatement();
return sta.executeQuery(sql);
} |
c5ce3f6c-6505-4def-8f64-925e2d079c3b | public boolean runSql2(String sql) throws SQLException {
Statement sta = connection.createStatement();
return sta.execute(sql);
} |
e7c50b2b-3ddf-4f7b-8830-d24aeb199077 | public void insertRecord(Map s, Map i) {
String query = String.format("INSERT INTO `records` (`URL`, `Domain`, `Args`, `Title`, `Head`, `Body`, " +
"`Raw`, `UpdateTime`, `LinksTo`, `LinkBacks`, `LoadTime`) VALUES (" +
"\"%s\", \"%s\", \"%s\", \"%s\", " +
"\"%s\", ... |
8f039cdf-3e32-4978-995e-d2a0390cf526 | public int selectRecordIDByURL(String u) {
int id = 0;
String query = String.format("SELECT id from records WHERE url = '%s'", u);
Log.d(TAG, query, 6);
ResultSet s = this.queryForResult(query);
try {
while(s.next()){
id = s.getInt("id");
}... |
96d1b567-0b09-43d7-a1fd-9bd43be327a9 | public void incrementLinkBack(int id) {
int linkBacks = 0;
String query = String.format("SELECT linkbacks FROM records WHERE id = %d", id);
ResultSet s = this.queryForResult(query);
try {
while(s.next()){
linkBacks = s.getInt("LinkBacks");
}
... |
95d4b6a3-9983-460e-acd4-4a1de6064aa6 | public void query(String query) {
if(!this.dbAvailable) {return;}
try {
this.statement.execute(query);
} catch (SQLException e) {
Log.d(TAG, String.format("Error running query: %s\n with query: %s", e.getMessage(), query), 3);
}
} |
18656735-c888-4cf3-97ae-4873287f635b | public ResultSet queryForResult(String query) {
if(!this.dbAvailable){return null;}
ResultSet result;
try {
result = this.statement.executeQuery(query);
} catch (SQLException e) {
Log.d(TAG, String.format("Error running query: %s\n with query: %s", e.getMessage(),... |
1dbf1091-6e55-4436-bef2-beed5f42e322 | public static synchronized void addRuleSets(String domain, final ArrayList<String> allow, final ArrayList<String> deny) {
Map<String, ArrayList<String>> temp = new HashMap<String, ArrayList<String>>();
temp.put("allow", allow);
temp.put("deny", deny);
mRules.put(domain, temp);
te... |
2f0ce675-7e70-4014-8452-4ea9e08d3db0 | public static synchronized void addAllowRule(String domain, final String rule) {
try {
// mRules.get(domain).get("allow");
mRules.get(domain).get("allow").add(rule);
} catch (NullPointerException e) {
// Temporary vars to add our new values to our hashmap
... |
5f8fb5e8-6ec9-4e1f-af52-03b00d7d836f | public static synchronized void addDenyRule(String domain, final String rule) {
try {
// mRules.get(domain).get("deny");
mRules.get(domain).get("deny").add(rule);
} catch (NullPointerException e) {
ArrayList<String> alTemp = new ArrayList<String>();
HashMa... |
ce6f9cf0-73d1-4281-9687-0062456b7c82 | public static synchronized void clearRuleSet(String domain, String action) {
try {
mRules.get(domain).get(action).clear();
} catch(NullPointerException e){}
} |
f33948d0-71f2-487c-9afe-244337e5b53e | public static synchronized boolean isInRobots(String domain) {
return mRules.containsKey(domain);
} |
7de3ae65-6b74-4a3e-84e4-64901490a454 | public static synchronized boolean isAllowed(String domain, String url) {
int size_of_allow = sizeOfHashMap(domain, "allow");
int size_of_deny = sizeOfHashMap(domain, "deny");
// if nothing in deny return true
if(size_of_deny < 1) {
return true;
}
// check fo... |
81a45a95-1a70-422a-871b-227dd371bb29 | public static synchronized int sizeOfHashMap(String domain, String action) {
try {
return mRules.get(domain).get(action).size();
} catch (NullPointerException e) {
return 0;
}
} |
afef5a25-c7a2-4a13-b752-2cbfa2be41e2 | public static void printKeys() {
Set<String> s = mRules.keySet();
for(String q : s) {
Log.d(TAG, "Key: " + s, 7);
}
} |
24af4af0-8b35-4598-9840-704159aa70d5 | public static int translateRule(String key) {
try {
return mDirectives.get(key.toLowerCase());
} catch(NullPointerException e) {
return 1000;
}
} |
cbc5eb6e-e9bb-44e1-81b7-bc4b3c535c70 | public static void printRules(String domain) {
Map<String, ArrayList<String>> hmTemp = new HashMap<String, ArrayList<String>>();
hmTemp = mRules.get(domain);
StringBuilder dsb = new StringBuilder();
try {
for(String s : hmTemp.get("deny")) {
dsb.append(s+"\t")... |
30edbf54-e0e6-41c3-9cd1-dddd3dc91d69 | public Robots() {
this.mDirectives.put("disallow", 1);
this.mDirectives.put("allow", 2);
this.mDirectives.put("user-agent", 3);
this.mDirectives.put("crawl-delay", 4);
this.mDirectives.put("site-map", 5);
this.mDirectives.put("#", 6);
} |
a9a421a3-132f-446c-be0c-4110b89f6f86 | public Robots(String url) {
this.mDomain = url;
} |
99265b0f-4bc3-409a-a4bf-dd1e48aca672 | public void getRobots(String u) {
// Create the new url
URL url;
try {
// get the root domain of the url
u = Robots.getDomain(u);
this.mDomain = u;
} catch(URISyntaxException e) {
Log.d(TAG, String.format("Malformed domain: %s", e.getMessag... |
f0c4a108-0bd6-472b-b439-a140362364d5 | public void parseRobots(InputStream in) {
String line;
String[] rule;
BufferedReader br = new BufferedReader(new InputStreamReader(in));
try {
while((line = br.readLine()) != null) {
if(this.isValidDirectiveLine(line)) {
// split our line ... |
3503861c-489e-42a0-bc27-599fe1eb5761 | public void setCrawlSpeed(int i) {
this.crawlSpeed = i;
} |
c661cbfe-98c5-4692-8bdf-6905d33b2aa2 | public static String getDomain(String u) throws URISyntaxException {
try {
URL urls = new URL(u);
return urls.getAuthority();
} catch(MalformedURLException e) {
Log.d("robots", "MalformedURL: " + e.getMessage(), 4);
return null;
}
} |
7dd4396d-f14f-4974-8b5b-45e7ede0860e | private void getInputStream(URL url) throws IOException{
URLConnection con = url.openConnection();
InputStream in = url.openConnection().getInputStream();
con.setConnectTimeout(1000);
con.setReadTimeout(1000);
this.parseRobots(in);
in.close();
} |
6acc32ef-0513-47ab-8b3a-e326680c1e3c | private void parseDisallow(String s) {
if(this.isGlobalCrawler) {
if(s.equals("/")) {
RobotRules.clearRuleSet(this.mDomain, "allow");
RobotRules.addDenyRule(this.mDomain, "1");
} else {
RobotRules.addDenyRule(this.mDomain, s);
}... |
8e84e638-268d-422e-9d74-a6d685e99100 | private void parseAllow(String s) {
if(this.isGlobalCrawler) {
if(s.equals("/")) {
RobotRules.clearRuleSet(this.mDomain, "deny");
RobotRules.addAllowRule(this.mDomain, "1");
} else {
RobotRules.addAllowRule(this.mDomain, s);
}
... |
e910dca3-2ef7-4dbd-a28f-86fa733d6523 | private void parseUserAgent(String s) {
this.isGlobalCrawler = s.contains("*");
} |
98df56f1-1bab-4e3c-84c8-6c5942e43084 | private boolean isValidDirectiveLine(String s) {
if(s.indexOf("#") == 0){ return false; }
else if(s.length() < 2){ return false; }
else if(s.isEmpty()) { return false; }
else { return s.contains(":"); }
} |
8d9e74e4-d3d8-4bd0-99cf-de909444a6b0 | public Crawler() {} |
f2854c37-3edb-4d5d-8d49-a1b06a953cdd | public Crawler(String[] url) {
//this.mFolderPath = new File(fn);
this.mParser = new Parser();
this.mRobots = new Robots();
// Create a new database connection
if(this.usDB) {
this.db = new MySQLHelper();
}
for(String s : url) {
LinkQueue.a... |
53adba83-1a09-4594-9f31-6bc3a7d21222 | public ArrayList<String> getQueue() {return LinkQueue.getQueue(this.mTid);} |
aced55f7-696e-4c3d-bcf9-c2eb124c156c | public void run() {
String el;
int id = 0;
Log.d(TAG, "Starting to run", 7);
Log.d(TAG, this.mTid + "'s Queue size: " + this.getQueueSize(), 6);
//this.printQueue();
while(!LinkQueue.isQueueEmpty(this.mTid)) {
// pop the first element off the queue
... |
57d6fbd1-fc0e-4c15-81da-e9c677f78a40 | public int getQueueSize() {
try {
return LinkQueue.getQueueSize(this.mTid);
} catch(NullPointerException e) {
return 0;
}
} |
747301f8-d439-42f3-a506-dd72fb198f14 | public void printQueue() {
Log.d(TAG, "Printing queue...", 7);
for(String e : LinkQueue.getQueue(this.mTid)) {
Log.d(TAG, e, 7);
}
} |
a3f9d55f-8ce4-424c-8831-c0b21ec9a124 | public void loadUrls() {
String path;
String[] args;
for(String s : this.mParser.getUrls()) {
/*
TODO: parse the url to get just the right side of the url
*/
// Log.d(TAG, s, 1);
Log.d(TAG, String.format("Right part of url: %s", Li... |
303c086f-13d5-4399-b9bc-eb62b64f45a1 | private void insertRow() {
Map<String, String> strings = new HashMap<String, String>();
Map<String, Integer> ints = new HashMap<String, Integer>();
java.util.Date date= new java.util.Date();
new Timestamp(date.getTime());
// our string based values
strings.put("url", this... |
995281b3-b45c-4211-8ca6-ec38324d905b | private void updateRecord() {
} |
b5101078-7014-439d-aad4-862147aad959 | private int selectRecordIDByURL() {
if(this.usDB) {
return this.db.selectRecordIDByURL(this.currentURL);
} else {
return -1;
}
} |
49d4d3e2-ffa9-4438-a2b2-380d8ea543a6 | private void incrementLinkBack(int id) {
if(this.usDB) {
this.db.incrementLinkBack(id);
}
} |
b31f52df-5607-447a-adc8-3200418753eb | public void setTid(int i) {this.mTid = i;} |
d3f9f8fc-8769-499f-8a1c-8ba0350a0640 | public boolean getIsDone() {return this.isDone;} |
e7a8b871-5698-442e-9f2e-e87954d91f3c | public void setIsDone(boolean b){this.isDone = b;} |
4b544c33-16c8-4232-ab15-731f1c20abde | private Connector() {
Log.d(TAG, String.format("User: %s, Password: %s, Server: %s", user, password, server), 7);
try {
Class.forName("com.mysql.jdbc.Driver");
String url = String.format("jdbc:mysql://%s:%d/%s",
server, port, database);
// Connect ... |
8c6ad379-5584-4066-9fa1-e74365ec697d | public static synchronized Connector getInstance() {
if(connector == null) {
connector = new Connector();
}
return connector;
} |
faf3e29e-68fe-4a86-bc5a-a282e139627c | public Connection getConnection() {
return connection;
} |
b14ed627-c5cd-42e9-9b1e-4b7c00533e8e | public static void closeConnection() {
try {
connection.close();
} catch (SQLException e) {
}
} |
c085b70b-bd0c-4abb-8570-843dd8c3d347 | public static void checkForTables() {
String createStatement = "CREATE TABLE IF NOT EXISTS `records`(\n" +
" `id` INT(11) NOT NULL AUTO_INCREMENT,\n" +
" `url` text NOT NULL,\n" +
" `domain` text NOT NULL,\n" +
" `args` text NOT NULL,\n" +
... |
813a34f2-4a46-4318-ab72-0f461f3e6037 | public static void checkForDatabase() {
try {
Statement statement = connection.createStatement();
statement.executeUpdate("CREATE DATABASE IF NOT EXISTS " + database);
} catch (SQLException e) {
Log.d(TAG, "Error executing query " + e.toString(), 3);
}
} |
5d004ce0-18fc-4b6f-b8d7-a137211112b2 | public static void setDatabaseAddress(String s) {server = s;} |
55d4c624-2fab-408f-9732-7117ff20ea13 | public static void setDatabaseUser(String s) {user = s;} |
69e90cf8-3e8a-4383-a802-86e4a3ee5edf | public static void setDatabasePassword(String s) {password = s;} |
1acd9e8a-92c3-41e9-888b-fed1be4d7cee | public static void main(String[] args) {
// Number of crawlers/threads to create
int totalCrawlers = 2;
// Arraylist holding our threads
ArrayList<Thread> threads = new ArrayList<Thread>();
// Arraylist holding our crawler
ArrayList<Crawler> crawlers = new ArrayList<Crawl... |
75deee85-f40f-4785-86a5-9f7491cd12a0 | public static int getThreadCount() {return mThreadCount;} |
4036ba6f-efcb-4a7a-8c0e-a872379097b3 | public static int validateCrawlers(int i) {
if(i < 1 || i > 5) { return 2; }
else { return i; }
} |
4a5dd540-b45c-47a8-9179-ecf3a626916f | public static int validateLogOutput(int i) {
if(i < 1 || i > 7) { return 3; }
else { return i; }
} |
9d551419-9b1d-4044-bca1-3c51fe381423 | public static void d(String tag, String m, int l) {
if(l <= outputLevel) {
System.out.println(String.format("%s:\t%s:\t%s", tag, getLevel(l), m));
}
} |
6bc28c82-ee3b-40ee-8c66-f4a73f7f2c3d | public static String getLevel(int l) {
String level = "";
switch (l) {
case 0:
level = "Emergency";
break;
case 1:
level = "Alert";
break;
case 2:
level = "Critical";
break... |
e6023364-02e7-4da4-8fdc-e916356ff8fc | public static void setOutputLevel(int i) {outputLevel = i;} |
f4cc6ddd-8678-49ec-a6a4-459fd90a9b54 | protected Query() {
} |
806b3b1c-01b9-47c2-9bab-c13980b4e7c9 | public GroupData()
{} |
4ef219b1-e5ef-4eb6-8f5a-f33c89b2862a | public GroupData(String name, String header, String footer)
{
this.name = name;
this.header = header;
this.footer = footer;
} |
8913e8f7-4dde-4696-abf0-daa02f47941c | public ContactData() {} |
f55ca6eb-64d0-4949-b365-c43c554264ab | @Test
public void modifySomeGroup()
{
app.getNavigationHelper().openMainPage();
app.getNavigationHelper().gotoGroupsPage();
app.getGroupHelper().initGroupModification(1);
GroupData group = new GroupData();
group.name = "new name";
app.getGroupHelper().fillGroupForm(group);
app.getGroupHelper().submit... |
75a673a4-50d2-4c68-8bb2-86db53ab568b | @Test
public void testNonEmptyGroupCreation() throws Exception
{
app.getNavigationHelper().openMainPage();
app.getNavigationHelper().gotoGroupsPage();
app.getGroupHelper().initGroupCreation();
GroupData group = new GroupData();
group.name = "group name 1";
group.header = "header 1";
group.... |
b7feb087-c668-4626-8f01-bce4b9afd129 | @Test
public void testEmptyGroupCreation() throws Exception
{
app.getNavigationHelper().openMainPage();
app.getNavigationHelper().gotoGroupsPage();
app.getGroupHelper().initGroupCreation();
app.getGroupHelper().submitGroupCreation();
app.getNavigationHelper().returnToGroupPage();
} |
a0d0fa03-dac7-45ff-8af6-e2ac0c319a28 | @Test
public void testNonEmptyContactCreation() throws Exception
{
app.getNavigationHelper().openMainPage();
app.getContactHelper().initContactCreation();
ContactData contact = new ContactData();
contact.firstname = "fn1";
contact.lastname = "ln1";
contact.address = "address1";
contact.homephone = ... |
1b9b0da7-df67-411e-bc0d-a979fe3a27e6 | @Test
public void testEmptyContactCreation() throws Exception
{
app.getNavigationHelper().openMainPage();
app.getContactHelper().initContactCreation();
app.getContactHelper().submitContactCreation();
app.getNavigationHelper().returnToHomePage();
} |
ab4cde67-f0c5-46bc-9a04-b287bd1d8172 | @BeforeTest
public void setUp() throws Exception
{
app = new ApplicationManager();
} |
e48c14d2-921e-4dc8-a060-03568c0e2834 | @AfterTest
public void tearDown() throws Exception
{
app.stop();
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.