id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
2c3688e9-7217-4218-b528-fbfb882815df | public void draw() {
logic();
glPushMatrix();
glTranslated(x, y, 0);
glColor3d(0.9, 0, 0);
glBegin(GL_QUADS);
glVertex2d(-8, 0);
glVertex2d(8, 0);
glVertex2d(8, 16);
glVertex2d(-8, 16);
glEnd();
glPopMatrix();
} |
e4106362-bf26-4bda-9c41-7684bd25c9d2 | public void kill() {
double coins = 4 + Math.random()*15;
for (int i = 0; i < coins; i++) Game.coinList.add(new Coin(x, y));
x = Math.random()*640 + Player.x;
kills++;
kill = true;
init();
if (kill) {
wavEffect.playAsSoundEffect(1.3f, 0.04f, false);
}
} |
dd404847-ec57-4512-86bc-7b7102e0cf1f | public static void drawString(String s, int x, int y) {
int startX = x;
GL11.glBegin(GL11.GL_POINTS);
for (char c : s.toLowerCase().toCharArray()) {
if (c == 'a') {
for (int i = 0; i < 8; i++) {
GL11.glVertex2f(x + 1, y + i);
GL11.glVertex2f(x + 7, y + i);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 8);
GL11.glVertex2f(x + i, y + 4);
}
x += 8;
} else if (c == 'b') {
for (int i = 0; i < 8; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 1; i <= 6; i++) {
GL11.glVertex2f(x + i, y);
GL11.glVertex2f(x + i, y + 4);
GL11.glVertex2f(x + i, y + 8);
}
GL11.glVertex2f(x + 7, y + 5);
GL11.glVertex2f(x + 7, y + 7);
GL11.glVertex2f(x + 7, y + 6);
GL11.glVertex2f(x + 7, y + 1);
GL11.glVertex2f(x + 7, y + 2);
GL11.glVertex2f(x + 7, y + 3);
x += 8;
} else if (c == 'c') {
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y);
GL11.glVertex2f(x + i, y + 8);
}
GL11.glVertex2f(x + 6, y + 1);
GL11.glVertex2f(x + 6, y + 2);
GL11.glVertex2f(x + 6, y + 6);
GL11.glVertex2f(x + 6, y + 7);
x += 8;
} else if (c == 'd') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y);
GL11.glVertex2f(x + i, y + 8);
}
GL11.glVertex2f(x + 6, y + 1);
GL11.glVertex2f(x + 6, y + 2);
GL11.glVertex2f(x + 6, y + 3);
GL11.glVertex2f(x + 6, y + 4);
GL11.glVertex2f(x + 6, y + 5);
GL11.glVertex2f(x + 6, y + 6);
GL11.glVertex2f(x + 6, y + 7);
x += 8;
} else if (c == 'e') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 1; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 0);
GL11.glVertex2f(x + i, y + 8);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 4);
}
x += 8;
} else if (c == 'f') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 1; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 8);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 4);
}
x += 8;
} else if (c == 'g') {
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y);
GL11.glVertex2f(x + i, y + 8);
}
GL11.glVertex2f(x + 6, y + 1);
GL11.glVertex2f(x + 6, y + 2);
GL11.glVertex2f(x + 6, y + 3);
GL11.glVertex2f(x + 5, y + 3);
GL11.glVertex2f(x + 7, y + 3);
GL11.glVertex2f(x + 6, y + 6);
GL11.glVertex2f(x + 6, y + 7);
x += 8;
} else if (c == 'h') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
GL11.glVertex2f(x + 7, y + i);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 4);
}
x += 8;
} else if (c == 'i') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 3, y + i);
}
for (int i = 1; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 0);
GL11.glVertex2f(x + i, y + 8);
}
x += 7;
} else if (c == 'j') {
for (int i = 1; i <= 8; i++) {
GL11.glVertex2f(x + 6, y + i);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 0);
}
GL11.glVertex2f(x + 1, y + 3);
GL11.glVertex2f(x + 1, y + 2);
GL11.glVertex2f(x + 1, y + 1);
x += 8;
} else if (c == 'k') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
}
GL11.glVertex2f(x + 6, y + 8);
GL11.glVertex2f(x + 5, y + 7);
GL11.glVertex2f(x + 4, y + 6);
GL11.glVertex2f(x + 3, y + 5);
GL11.glVertex2f(x + 2, y + 4);
GL11.glVertex2f(x + 2, y + 3);
GL11.glVertex2f(x + 3, y + 4);
GL11.glVertex2f(x + 4, y + 3);
GL11.glVertex2f(x + 5, y + 2);
GL11.glVertex2f(x + 6, y + 1);
GL11.glVertex2f(x + 7, y);
x += 8;
} else if (c == 'l') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 1; i <= 6; i++) {
GL11.glVertex2f(x + i, y);
}
x += 7;
} else if (c == 'm') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
GL11.glVertex2f(x + 7, y + i);
}
GL11.glVertex2f(x + 3, y + 6);
GL11.glVertex2f(x + 2, y + 7);
GL11.glVertex2f(x + 4, y + 5);
GL11.glVertex2f(x + 5, y + 6);
GL11.glVertex2f(x + 6, y + 7);
GL11.glVertex2f(x + 4, y + 5);
x += 8;
} else if (c == 'n') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
GL11.glVertex2f(x + 7, y + i);
}
GL11.glVertex2f(x + 2, y + 7);
GL11.glVertex2f(x + 2, y + 6);
GL11.glVertex2f(x + 3, y + 5);
GL11.glVertex2f(x + 4, y + 4);
GL11.glVertex2f(x + 5, y + 3);
GL11.glVertex2f(x + 6, y + 2);
GL11.glVertex2f(x + 6, y + 1);
x += 8;
} else if (c == 'o' || c == '0') {
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + 1, y + i);
GL11.glVertex2f(x + 7, y + i);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 8);
GL11.glVertex2f(x + i, y + 0);
}
x += 8;
} else if (c == 'p') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 8);
GL11.glVertex2f(x + i, y + 4);
}
GL11.glVertex2f(x + 6, y + 7);
GL11.glVertex2f(x + 6, y + 5);
GL11.glVertex2f(x + 6, y + 6);
x += 8;
} else if (c == 'q') {
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + 1, y + i);
if (i != 1)
GL11.glVertex2f(x + 7, y + i);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 8);
if (i != 6)
GL11.glVertex2f(x + i, y + 0);
}
GL11.glVertex2f(x + 4, y + 3);
GL11.glVertex2f(x + 5, y + 2);
GL11.glVertex2f(x + 6, y + 1);
GL11.glVertex2f(x + 7, y);
x += 8;
} else if (c == 'r') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 8);
GL11.glVertex2f(x + i, y + 4);
}
GL11.glVertex2f(x + 6, y + 7);
GL11.glVertex2f(x + 6, y + 5);
GL11.glVertex2f(x + 6, y + 6);
GL11.glVertex2f(x + 4, y + 3);
GL11.glVertex2f(x + 5, y + 2);
GL11.glVertex2f(x + 6, y + 1);
GL11.glVertex2f(x + 7, y);
x += 8;
} else if (c == 's') {
for (int i = 2; i <= 7; i++) {
GL11.glVertex2f(x + i, y + 8);
}
GL11.glVertex2f(x + 1, y + 7);
GL11.glVertex2f(x + 1, y + 6);
GL11.glVertex2f(x + 1, y + 5);
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 4);
GL11.glVertex2f(x + i, y);
}
GL11.glVertex2f(x + 7, y + 3);
GL11.glVertex2f(x + 7, y + 2);
GL11.glVertex2f(x + 7, y + 1);
GL11.glVertex2f(x + 1, y + 1);
GL11.glVertex2f(x + 1, y + 2);
x += 8;
} else if (c == 't') {
for (int i = 0; i <= 8; i++) {
GL11.glVertex2f(x + 4, y + i);
}
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + i, y + 8);
}
x += 7;
} else if (c == 'u') {
for (int i = 1; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
GL11.glVertex2f(x + 7, y + i);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 0);
}
x += 8;
} else if (c == 'v') {
for (int i = 2; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
GL11.glVertex2f(x + 6, y + i);
}
GL11.glVertex2f(x + 2, y + 1);
GL11.glVertex2f(x + 5, y + 1);
GL11.glVertex2f(x + 3, y);
GL11.glVertex2f(x + 4, y);
x += 7;
} else if (c == 'w') {
for (int i = 1; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
GL11.glVertex2f(x + 7, y + i);
}
GL11.glVertex2f(x + 2, y);
GL11.glVertex2f(x + 3, y);
GL11.glVertex2f(x + 5, y);
GL11.glVertex2f(x + 6, y);
for (int i = 1; i <= 6; i++) {
GL11.glVertex2f(x + 4, y + i);
}
x += 8;
} else if (c == 'x') {
for (int i = 1; i <= 7; i++)
GL11.glVertex2f(x + i, y + i);
for (int i = 7; i >= 1; i--)
GL11.glVertex2f(x + i, y + 8 - i);
x += 8;
} else if (c == 'y') {
GL11.glVertex2f(x + 4, y);
GL11.glVertex2f(x + 4, y + 1);
GL11.glVertex2f(x + 4, y + 2);
GL11.glVertex2f(x + 4, y + 3);
GL11.glVertex2f(x + 4, y + 4);
GL11.glVertex2f(x + 3, y + 5);
GL11.glVertex2f(x + 2, y + 6);
GL11.glVertex2f(x + 1, y + 7);
GL11.glVertex2f(x + 1, y + 8);
GL11.glVertex2f(x + 5, y + 5);
GL11.glVertex2f(x + 6, y + 6);
GL11.glVertex2f(x + 7, y + 7);
GL11.glVertex2f(x + 7, y + 8);
x += 8;
} else if (c == 'z') {
for (int i = 1; i <= 6; i++) {
GL11.glVertex2f(x + i, y);
GL11.glVertex2f(x + i, y + 8);
GL11.glVertex2f(x + i, y + i);
}
GL11.glVertex2f(x + 6, y + 7);
x += 8;
} else if (c == '1') {
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y);
}
for (int i = 1; i <= 8; i++) {
GL11.glVertex2f(x + 4, y + i);
}
GL11.glVertex2f(x + 3, y + 7);
x += 8;
} else if (c == '2') {
for (int i = 1; i <= 6; i++) {
GL11.glVertex2f(x + i, y);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 8);
}
GL11.glVertex2f(x + 1, y + 7);
GL11.glVertex2f(x + 1, y + 6);
GL11.glVertex2f(x + 6, y + 7);
GL11.glVertex2f(x + 6, y + 6);
GL11.glVertex2f(x + 6, y + 5);
GL11.glVertex2f(x + 5, y + 4);
GL11.glVertex2f(x + 4, y + 3);
GL11.glVertex2f(x + 3, y + 2);
GL11.glVertex2f(x + 2, y + 1);
x += 8;
} else if (c == '3') {
for (int i = 1; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 8);
GL11.glVertex2f(x + i, y);
}
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + 6, y + i);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 4);
}
x += 8;
} else if (c == '4') {
for (int i = 2; i <= 8; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 2; i <= 7; i++) {
GL11.glVertex2f(x + i, y + 1);
}
for (int i = 0; i <= 4; i++) {
GL11.glVertex2f(x + 4, y + i);
}
x += 8;
} else if (c == '5') {
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + i, y + 8);
}
for (int i = 4; i <= 7; i++) {
GL11.glVertex2f(x + 1, y + i);
}
GL11.glVertex2f(x + 1, y + 1);
GL11.glVertex2f(x + 2, y);
GL11.glVertex2f(x + 3, y);
GL11.glVertex2f(x + 4, y);
GL11.glVertex2f(x + 5, y);
GL11.glVertex2f(x + 6, y);
GL11.glVertex2f(x + 7, y + 1);
GL11.glVertex2f(x + 7, y + 2);
GL11.glVertex2f(x + 7, y + 3);
GL11.glVertex2f(x + 6, y + 4);
GL11.glVertex2f(x + 5, y + 4);
GL11.glVertex2f(x + 4, y + 4);
GL11.glVertex2f(x + 3, y + 4);
GL11.glVertex2f(x + 2, y + 4);
x += 8;
} else if (c == '6') {
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y);
}
for (int i = 2; i <= 5; i++) {
GL11.glVertex2f(x + i, y + 4);
GL11.glVertex2f(x + i, y + 8);
}
GL11.glVertex2f(x + 7, y + 1);
GL11.glVertex2f(x + 7, y + 2);
GL11.glVertex2f(x + 7, y + 3);
GL11.glVertex2f(x + 6, y + 4);
x += 8;
} else if (c == '7') {
for (int i = 0; i <= 7; i++)
GL11.glVertex2f(x + i, y + 8);
GL11.glVertex2f(x + 7, y + 7);
GL11.glVertex2f(x + 7, y + 6);
GL11.glVertex2f(x + 6, y + 5);
GL11.glVertex2f(x + 5, y + 4);
GL11.glVertex2f(x + 4, y + 3);
GL11.glVertex2f(x + 3, y + 2);
GL11.glVertex2f(x + 2, y + 1);
GL11.glVertex2f(x + 1, y);
x += 8;
} else if (c == '8') {
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + 1, y + i);
GL11.glVertex2f(x + 7, y + i);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 8);
GL11.glVertex2f(x + i, y + 0);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 4);
}
x += 8;
} else if (c == '9') {
for (int i = 1; i <= 7; i++) {
GL11.glVertex2f(x + 7, y + i);
}
for (int i = 5; i <= 7; i++) {
GL11.glVertex2f(x + 1, y + i);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 8);
GL11.glVertex2f(x + i, y + 0);
}
for (int i = 2; i <= 6; i++) {
GL11.glVertex2f(x + i, y + 4);
}
GL11.glVertex2f(x + 1, y + 0);
x += 8;
} else if (c == '.') {
GL11.glVertex2f(x + 1, y);
x += 2;
} else if (c == ',') {
GL11.glVertex2f(x + 1, y);
GL11.glVertex2f(x + 1, y + 1);
x += 2;
} else if (c == '\n') {
y -= 10;
x = startX;
} else if (c == ' ') {
x += 8;
}
}
GL11.glEnd();
} |
3bfccf8c-4f45-4dc0-969b-e8e56da54c7d | public static void end() {
if (Enemy.kills == 10 && Player.deaths <= 10) {
Player.y = -32;
Enemy.y = 0;
glBegin(GL_QUADS);
glColor3d(0.7, 0.8, 0.9);
glVertex2d(0, 0);
glVertex2d(640, 0);
glColor3d(0.5, 0.6, 0.8);
glVertex2d(640, 480);
glVertex2d(0, 480);
glEnd();
glColor3d(0.9, 0, 0);
DrawString.drawString("You Win!", 320, 240);
DrawString.drawString("Press SPACE to play again!", 320, 220);
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
Enemy.kills = 0;
Enemy.y = 32;
Player.deaths = 0;
Player.y = 32;
Game.killCommand = 1;
}
} else if (Player.deaths == 10) {
Player.y = -32;
Enemy.y = 0;
glBegin(GL_QUADS);
glColor3d(0.7, 0.8, 0.9);
glVertex2d(0, 0);
glVertex2d(640, 0);
glColor3d(0.5, 0.6, 0.8);
glVertex2d(640, 480);
glVertex2d(0, 480);
glEnd();
glColor3d(0.9, 0, 0);
DrawString.drawString("You Lose!", 320, 240);
DrawString.drawString("Press SPACE to try again!", 320, 220);
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
Enemy.kills = 0;
Enemy.y = 32;
Player.deaths = 0;
Player.y = 32;
Game.killCommand = 1;
}
}
} |
8ed2a3b5-6e7f-40b5-9f79-ca64daeb0e41 | @Override
public void init(NutConfig config) {
// log.debug("config ioc:" + config.getIoc());
Dao dao = config.getIoc().get(Dao.class);
for (Class<?> clazz : Scans.me().scanPackage("com.gemas.platform")) {
if (null != clazz.getAnnotation(Table.class)) {
dao.create(clazz, false);
}
}
if (dao.count(User.class) == 0) {
User admin = new User();
admin.setName("admin");
admin.setPasswd("123456");
dao.insert(admin);
}
} |
d4198d44-6971-4f45-9cb3-2de3ad488910 | @Override
public void destroy(NutConfig config) {
} |
2969ba90-2e68-4a7e-9822-3435e5526816 | @At
public boolean login(@Param("name") String name,
@Param("passwd") String passwd, HttpSession session) {
if (Strings.isBlank(name) || Strings.isBlank(passwd)) {
return false;
}
name = name.trim().intern();
passwd = passwd.trim().intern();
User user = dao.fetch(User.class,
Cnd.where("name", "=", name).and("passwd", "=", passwd));
if (user == null) {
return false;
} else {
session.setAttribute("user", user);
return true;
}
} |
07ffe90c-9bb2-4811-a9e2-afb5be6a0fa2 | @At
@Ok(">>:/")
public void logout(HttpSession session) {
session.invalidate();
} |
801da574-6672-4843-8c53-d8899ee2cf03 | @At
public User me(@Attr("user") User user) {
return user;
} |
15baeaec-55d2-40ec-ae8c-afb0e95b3fdc | @At("/ping")
public Object ping() {
log.debug("Dao == " + dao);
Date date = new Date();
return date;
} |
bdaf9749-5137-4e65-a292-30651dd34dab | public Integer getId() {
return id;
} |
4c172177-ea5e-4e0e-b109-84b89e23d232 | public void setId(Integer id) {
this.id = id;
} |
77fdf47f-7525-471e-a74b-7f5021062c5f | public String getName() {
return name;
} |
fa5ecd64-1a54-4358-abd9-5b34e4d59280 | public void setName(String name) {
this.name = name;
} |
67626654-4dbb-458c-99bd-1c29dd9cc89a | public String getPasswd() {
return passwd;
} |
bfbd353b-e2b7-4340-b554-ba65c8f441b1 | public void setPasswd(String passwd) {
this.passwd = passwd;
} |
e4bf868b-03d5-4c0a-af62-e4f9e8fe3999 | GridLocation(int locationRow, int locationCol)
{
row = locationRow;
col = locationCol;
clear();
} |
cab6ff81-050d-4776-9c25-7f7da041dbc8 | void clear()
{
seed = Content.EMPTY;
} |
400a0d5e-5082-4655-975c-b8061a56a133 | void drawCell()
{
switch(seed)
{
case CROSS : System.out.print("X");
break;
case NOUGHT : System.out.print("O");
break;
case EMPTY : System.out.print(" ");
break;
}
} |
83f15e24-60c2-457c-a13d-adb812fb9df7 | Grid()
{
// initializing the cell array, allocating memory
cell = new GridLocation[ROWS][COLS];
emptySpacesRemaining = ROWS * COLS;
for(int i = 0 ; i<ROWS ; i++)
{
for(int j=0 ; j<COLS ; j++)
{
// initializing each cell in the array
cell[i][j] = new GridLocation(i, j);
}
}
} |
a1a0c767-892a-4210-ab57-cfd4927282bf | public void init()
{
for (int row = 0; row < ROWS; ++row)
{
for (int col = 0; col < COLS; ++col)
{
cell[row][col].clear();
}
}
} |
3d0991bb-3d37-47b0-94ca-fcf7cb4652e0 | void drawGrid()
{
for(int i=0 ; i<ROWS ; i++)
{
for(int j=0 ; j<COLS ; j++)
{
cell[i][j].drawCell();
if (j < COLS - 1) System.out.print("|");
}
System.out.println();
if (i < ROWS - 1)
{
System.out.println("-------");
}
}
} |
dfd25363-5ae8-4890-9cbc-4626a883f825 | boolean isDraw()
{
// the grid does not have any empty space hence the game is drawn
if(emptySpacesRemaining == 0)
return true;
else return false;
} |
0fd1170f-88cd-4359-b082-00f90d719d9e | boolean hasWon(Content thisSeed)
{ // checking rows for victory
return ( (cell[currentRow][0].seed == thisSeed &&
cell[currentRow][1].seed == thisSeed &&
cell[currentRow][2].seed == thisSeed)
|| // checking columns for victory
(cell[0][currentCol].seed == thisSeed &&
cell[1][currentCol].seed == thisSeed &&
cell[2][currentCol].seed == thisSeed)
|| // checking the diagonal '\' for victory
(currentRow == currentCol &&
cell[0][0].seed == thisSeed &&
cell[1][1].seed == thisSeed &&
cell[2][2].seed == thisSeed)
|| // checking the diagonal '/' for victory
(currentRow + currentCol == 2 &&
cell[0][2].seed == thisSeed &&
cell[1][1].seed == thisSeed &&
cell[2][0].seed == thisSeed));
} |
3307939e-b63d-4911-8113-5d502f6853e0 | static void about()
{
System.out.println("About entered");
} |
59319b41-b2cf-4f17-a617-91914e4af51f | static void instructions()
{
System.out.println("Instructions entered");
} |
7741c3fa-245c-4565-b1d4-9880c6d8ac0a | public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
GameState cont = null ;
int choice;
do{
System.out.println("MENU:");
System.out.println("--------------------");
System.out.println("1) About");
System.out.println("2) Intructions");
System.out.println("3) Play Game");
System.out.println("4) Exit");
System.out.println("--------------------");
choice = input.nextInt();
switch(choice)
{
case 1:
about();
break;
case 2:
instructions();
break;
case 3:
GameWorld newGame = new GameWorld();
cont = newGame.getState();
break;
case 4:
break;
default:
System.out.println("Please enter a valid input");
choice = 0;
}
}
while(choice >= 0 && choice<4 || cont != null);
} |
9da1bdcc-1b41-4731-b79d-ea3dd0254551 | GameWorld()
{
// creating the grib object
gameGrid = new Grid();
// initializing the world
worldInit();
do
{
// letting the current player make a move
playerMove(currentPlayer);
// updating the grid and print the grid.
gameGrid.drawGrid();
// update the game state after the move.
updateGameState(currentPlayer);
if(currentState == GameState.CROSS_WON)
System.out.println("Player X Won the game");
else if(currentState == GameState.NOUGHT_WON)
System.out.println("Player O Won the game");
else if(currentState == GameState.DRAW)
System.out.println("Game Drawn. Bye!");
if(currentPlayer == Content.CROSS)
currentPlayer = Content.NOUGHT;
else if(currentPlayer == Content.NOUGHT)
currentPlayer = Content.CROSS;
}
// keep on playing until one player wins or the game is drawn
while(currentState == GameState.PLAYING);
} |
4cbef0b6-1dd6-4924-9622-bec8648857d6 | GameState getState()
{
return this.currentState;
} |
1e713154-ca0f-42c0-835a-a5546a684ade | void playerMove(Content thisSeed)
{
// flag that keeps track of the correctness of the input
boolean validInput = true;
do
{
// player X's turn
if(thisSeed == Content.CROSS)
System.out.println("Player X please enter the location where you want to place your "+thisSeed+"\n"
+ "The input should be (row[1-3] , column[1-3]) WITHOUT commas, and ONLY SPACES between two digits");
// Player O's turn
else if(thisSeed == Content.NOUGHT)
System.out.println("Player O please enter the location where you want to place your "+thisSeed+"\n"
+ "The input should be (row[1-3] , column[1-3]) WITHOUT commas, and ONLY SPACES between two digits");
int row = input.nextInt()-1;
int col = input.nextInt()-1;
// checking the correctness of the input and seeing whether that cell to be filled is empty.
if(row>=0 && row<3 && col>=0 && col<3 && gameGrid.cell[row][col].seed == Content.EMPTY)
{
// placing the symbol on the mentioned rows and columns
gameGrid.cell[row][col].seed = thisSeed;
gameGrid.currentRow = row;
gameGrid.currentCol = col;
// reducing the the number of empty spaces after filling the cell
gameGrid.emptySpacesRemaining--;
validInput = true;
}
else
{
System.out.println(" The entered input is incorrect please enter it again");
validInput = false;
}
}
// till the input is valid.
while(!validInput);
} |
ec22b7fa-b2a9-4724-b1c5-d7b228b0d9b0 | void worldInit()
{
gameGrid.init();
currentState = GameState.PLAYING;
currentPlayer = Content.NOUGHT;
} |
cf5f516d-c2a6-47da-a8d3-b3e5320e871d | void updateGameState(Content thisSeed)
{
// updating the state of the game on the basis of who won the game or game drawn, accordingly
if(gameGrid.hasWon(thisSeed))
{
if(thisSeed == Content.CROSS)
currentState = GameState.CROSS_WON;
if(thisSeed == Content.NOUGHT)
currentState = GameState.NOUGHT_WON;
}
else if(gameGrid.isDraw())
currentState = GameState.DRAW;
} |
1aac3a7f-c6e0-4ca8-a9fc-562451c6ede6 | proxy2()
{
createproxy();
readaddr();
Thread t=new Thread(this);
t.start();
} |
b2d3803a-1694-4532-8b53-005897264887 | void readaddr()
{
try
{
fin=new FileInputStream("tracker.txt");
while((ch=fin.read())!=-1)
trackeraddr+=(char)ch;
trackeraddr.trim();
System.out.println(trackeraddr);
fin=new FileInputStream("proxy1.txt");
while((ch=fin.read())!=-1)
proxy1addr+=(char)ch;
proxy1addr.trim();
}
catch(Exception e)
{
System.out.println(e);
}
} |
9d991833-2cba-4cb4-ad9c-5daae6a756e3 | void createproxy()
{
jf=new JFrame("PROXY_SERVER");
Container cp=jf.getContentPane();
cp.setLayout(null);
JLabel jl=new JLabel("PROXY SERVER ##2",JLabel.CENTER);
jl.setFont(new Font("Times New Roman",Font.BOLD,28));
jl.setForeground(Color.BLACK);
JLabel jl1=new JLabel("Details of Requests given to Proxy1:");
jta=new JTextArea("Waiting for request..\n");
JScrollPane jsp=new JScrollPane(jta);
jta.setBackground(Color.WHITE);
jta.setForeground(Color.BLACK);
JLabel jl2=new JLabel("List of available files in the proxy Server:");
String dirname="C:\\Users\\vamshi krishna s\\Desktop\\proxyserverfiles1";
File f=new File(dirname);
String files[]=f.list();
for (int i=0;i<files.length;i++)
v.add(files[i]);
jlist=new JList(files);
JScrollPane jsp2=new JScrollPane(jlist) ;
jbexit=new JButton("EXIT");
proxyinfo=new JButton("System Info");
stats=new JButton("Statistics");
JLabel jla=new JLabel("CSE FINAL YEAR PROJECT 2012",JLabel.RIGHT);
cp.add(jl);
cp.add(jl1);
cp.add(jsp);
cp.add(jl2);
cp.add(jsp2);
cp.add(jbexit);
cp.add(jla);
cp.add(proxyinfo);
cp.add(stats);
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
jl.setBounds(0,0,d.width,30);
jl1.setBounds(10,50,400,20);
jsp.setBounds(10,80,600,600);
jl2.setBounds(630,50,300,30);
jsp2.setBounds(630,80,300,300);
jbexit.setBounds(700,400,150,30);
proxyinfo.setBounds(700,500,150,30);
stats.setBounds(700,600,150,30);
jf.setSize(d.width,d.height);
jf.setVisible(true);
jbexit.addActionListener(this);
proxyinfo.addActionListener(this);
stats.addActionListener(this);
} |
d69328ec-9a6b-472f-9ef5-aa0545347372 | public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==jbexit)
{
System.exit(0);
}
else if(ae.getSource()==proxyinfo)
{
System.out.print("System Info");
try {
JOptionPane.showMessageDialog(null,"IP Address of the System: "+InetAddress.getLocalHost().getHostAddress()+"\nHost Name:"+InetAddress.getLocalHost().getHostName()+"\n");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(ae.getSource()==stats)
{
JOptionPane.showMessageDialog(null,"Total No of Requests handled By Proxy Server In this Session\n "+no_of_req+"\n");
}
} |
55eeb05d-89c3-457b-ac60-f0669d15f84a | public void run()
{
try
{
jta.append("Thread Started.");
Socket soc=new Socket(trackeraddr,2000);
DataOutputStream dout=new DataOutputStream(soc.getOutputStream());
dout.writeUTF("PROXY2INFO");
ObjectOutputStream oos=new ObjectOutputStream(soc.getOutputStream());
oos.writeObject(v);
oos.close();
dout.close();
soc.close();
ServerSocket ss=new ServerSocket(1800);
while(true)
{
Socket s=ss.accept();
jta.append("\nNew Client Request Received..\n");
new processreqq(this,s);
}
}
catch(Exception e)
{
System.out.println(e+"Error in Server");
e.printStackTrace();
}
} |
021ed72e-dd7d-41d8-8ea8-a65f4ece6fac | public static void main(String args[])
{
new proxy2();
} |
64afe38d-7ec9-471c-a5c4-d5b01c7166e8 | processreqq(proxy2 obj,Socket s)
{
parent=obj;
soc=s;
//readaddr();
Thread t=new Thread(this);
t.start();
} |
188a0081-a086-40d8-a3bc-d03cf222afed | public void run()
{
try
{
String trackeraddr=parent.trackeraddr,proxy1addr=parent.proxy1addr;
DataInputStream din=new DataInputStream(soc.getInputStream());
String req=din.readUTF();
System.out.println(req);
if (req.equals("download"))
{
parent.no_of_req++;
parent.jta.append("Request is download..\n");
String ip=din.readUTF();
int port=din.readInt();
String fname=din.readUTF();
parent.jta.append("check for file in list\n");
File f=new File(dirname);
File files[]=f.listFiles();
int i=0;
for (i=0;i<files.length;i++)
{
String name=files[i].getName();
if (fname.equalsIgnoreCase(name))
{
FileInputStream fin=new FileInputStream(dirname+"//"+name);
byte b[]=new byte[fin.available()];
fin.read(b);
fin.close();
Socket s=new Socket(ip,port);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SUCCESS");
dout.writeUTF(name);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
parent.jta.append("File found and forwarded to client..\n") ;
oos.close();
dout.close();
s.close();
break;
}
}
if (i==files.length)
{
parent.jta.append("File not found\n");
Socket s=new Socket(trackeraddr,2000);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("PROXY2REQ");
dout.writeUTF(ip);
dout.writeInt(port);
dout.writeUTF(fname);
dout.close();
s.close();
parent.jta.append("Request forwarded to tracker.\n");
}
// din.close();
// soc.close();
}
else
if (req.equals("SERVERRESPONSE1"))
{
parent.jta.append("File response from server\n");
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
ObjectInputStream oin=new ObjectInputStream(soc.getInputStream());
byte b[]=(byte[]) oin.readObject();
FileOutputStream fout=new FileOutputStream(dirname+"//"+fname);
fout.write(b);
fout.close();
parent.jta.append("File saved in proxy.\n");
Socket s=new Socket(cip,cport);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SUCCESS");
dout.writeUTF(fname);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
parent.jta.append("File forwardedt to client\n");
oos.close();
dout.close();
s.close();
oin.close();
File f=new File(dirname);
String files[]=f.list();
Vector<String> v=new Vector<String>();
for (int i=0;i<files.length;i++)
v.add(files[i]);
parent.jlist.setListData(v);
Socket soc1=new Socket(trackeraddr,2000);
DataOutputStream dout1=new DataOutputStream(soc1.getOutputStream());
dout1.writeUTF("PROXY2INFO");
ObjectOutputStream oos1=new ObjectOutputStream(soc1.getOutputStream());
oos1.writeObject(v);
oos1.close();
dout1.close();
soc1.close();
}
else
if (req.equals("SERVERRESPONSE2"))
{
parent.jta.append("File response from server\n");
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
Socket s=new Socket(cip,cport);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("FAIL");
dout.writeUTF(fname);
parent.jta.append("File not found, response forwarded to client.\n");
dout.close();
s.close();
}
else
if (req.equals("download1"))
{
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
parent.jta.append("check for file in list\n");
File f=new File(dirname);
File files[]=f.listFiles();
int i=0;
for (i=0;i<files.length;i++)
if (fname.equalsIgnoreCase(files[i].getName()))
break;
FileInputStream fin=new FileInputStream(dirname+"//"+files[i].getName());
byte b[]=new byte[fin.available()];
fin.read(b);
fin.close();
Socket s=new Socket(proxy1addr,1500);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("FORWARD");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(files[i].getName());
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
parent.jta.append("File found and forwarded to Proxy1..\n") ;
oos.close();
dout.close();
s.close();
}
else
if (req.equals("FORWARD"))
{
parent.jta.append("File response from Proxy1\n");
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
ObjectInputStream oin=new ObjectInputStream(soc.getInputStream());
byte b[]=(byte[]) oin.readObject();
FileOutputStream fout=new FileOutputStream(dirname+"//"+fname);
fout.write(b);
fout.close();
parent.jta.append("File saved in proxy.\n");
Socket s=new Socket(cip,cport);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SUCCESS");
dout.writeUTF(fname);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
parent.jta.append("File forwarded to client\n");
oos.close();
dout.close();
s.close();
oin.close();
File f=new File(dirname);
String files[]=f.list();
Vector<String> v=new Vector<String>();
for (int i=0;i<files.length;i++)
v.add(files[i]);
parent.jlist.setListData(v);
Socket soc1=new Socket(trackeraddr,2000);
DataOutputStream dout1=new DataOutputStream(soc1.getOutputStream());
dout1.writeUTF("PROXY2INFO");
ObjectOutputStream oos1=new ObjectOutputStream(soc1.getOutputStream());
oos1.writeObject(v);
oos1.close();
dout1.close();
soc1.close();
}
din.close();
soc.close();
}
catch(Exception e)
{
System.out.println("in process req:"+e);
}
} |
1ef19a9c-83cf-400e-ba45-610f67c7ebc8 | tracker()
{
create_tracker();
Thread t=new Thread(this);
t.start();
} |
7696ead7-5c6e-4ec6-9d41-ca9d3a52bd9d | void create_tracker()
{
jf=new JFrame("Tracker");
Container cp=jf.getContentPane();
cp.setLayout(null);
JLabel jl=new JLabel("TRACKER",JLabel.CENTER);
jl.setFont(new Font("Times new Roman",Font.BOLD,28));
jl.setForeground(Color.BLACK);
JLabel jl1=new JLabel("Details of Requests given to Tracker:");
jta=new JTextArea("Waiting for request..\n");
JScrollPane jsp=new JScrollPane(jta);
jta.setBackground(Color.WHITE);
jta.setForeground(Color.RED);
JLabel jl2=new JLabel("List of Files Available in Proxy Server 1:");
jlist1=new JList();
JScrollPane jsp2=new JScrollPane(jlist1) ;
JLabel jl3=new JLabel("List of available files in Proxy Server 2:");
jlist2=new JList();
JScrollPane jsp3=new JScrollPane(jlist2) ;
exit=new JButton("EXIT");
trackerinfo=new JButton("Tracker Info");
stats=new JButton("Statistics");
cp.add(jl);
cp.add(jl1);
cp.add(jsp);
cp.add(jl2);
cp.add(jsp2);
cp.add(jl3);
cp.add(jsp3);
cp.add(exit);
cp.add(trackerinfo);
cp.add(stats);
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
jl.setBounds(0,0,d.width,30);
jl2.setBounds(10,50,300,20);
jsp2.setBounds(10,80,300,300);
jl3.setBounds(380,50,300,20);
jsp3.setBounds(380,80,300,300);
jl1.setBounds(10,420,400,20);
jsp.setBounds(10,450,600,200);
exit.setBounds(700,400,150,30);
trackerinfo.setBounds(700,500,150,30);
stats.setBounds(700,600,150,30);
jf.setSize(d.width,d.height);
jf.setVisible(true);
exit.addActionListener(this);
trackerinfo.addActionListener(this);
stats.addActionListener(this);
} |
074d75ee-5a1e-46e3-884a-32a6cad5934f | public void run()
{
try
{
jta.append("Thread Started in Tracker\n");
ServerSocket ss=new ServerSocket(2000);//opening server port in tracker
while (true)
{
Socket soc=ss.accept();
jta.append("Request from proxy.\n");
//no_of_reqs++;
new proxyinfo(this,soc);
}
}
catch(Exception e)
{
System.out.println(e);
}
} |
cfe5ec54-bcea-4460-980e-6c91d6701316 | public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==exit)
System.exit(0);
else if(ae.getSource()==trackerinfo)
{
try {
JOptionPane.showMessageDialog(null,"IP Address of the System: "+InetAddress.getLocalHost().getHostAddress()+"\nHost Name:"+InetAddress.getLocalHost().getHostName()+"\n");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(ae.getSource()==stats)
{
//System.out.println("No of requests handled by tracker in this session::\n"+no_of_reqs+"\n No of reqs Forwarded 2 Server in this session"+no_of_server);
JOptionPane.showMessageDialog(null,"No of requests handled by tracker in this session::\n"+no_of_reqs+"\n No of reqs Forwarded 2 Server in this session::\n"+no_of_server);
}
} |
644f7167-f9e0-4a9b-bbde-c9a2b32bddc7 | public static void main(String args[])
{
new tracker();
} |
ed18e2e8-14ec-4ced-bc18-2c1bba567a00 | proxyinfo(tracker obj,Socket s)
{
parent=obj;
soc=s;
readaddr();
Thread t=new Thread(this);
t.start();
} |
530046f3-58b5-462f-8af9-5f8f5d4d9758 | void readaddr()
{
try
{
fin=new FileInputStream("server.txt");
while((ch=fin.read())!=-1)
serveraddr+=(char)ch;
serveraddr.trim();
System.out.println(serveraddr);
fin=new FileInputStream("proxy1.txt");
while((ch=fin.read())!=-1)
proxy1addr+=(char)ch;
proxy1addr.trim();
System.out.println(proxy1addr);
fin=new FileInputStream("proxy2.txt");
while((ch=fin.read())!=-1)
proxy2addr+=(char)ch;
proxy2addr.trim();
System.out.println(proxy2addr);
}
catch(Exception e)
{
System.out.println(e);
}
} |
4fc0579f-d00e-4a8f-9fae-ca974e5a6751 | public void run()
{
try
{
DataInputStream din=new DataInputStream(soc.getInputStream());
String req=din.readUTF();
if (req.equals("PROXY1INFO"))
{
parent.jta.append("File names received from proxy1.\n");
ObjectInputStream oin=new ObjectInputStream(soc.getInputStream());
Vector<String> v=(Vector<String>) oin.readObject();
oin.close();
parent.jlist1.setListData(v);
}
else
if (req.equals("PROXY2INFO"))
{
parent.jta.append("File names received from proxy2.\n");
ObjectInputStream oin=new ObjectInputStream(soc.getInputStream());
Vector<String> v=(Vector<String>) oin.readObject();
oin.close();
parent.jlist2.setListData(v);
}
else
if (req.equals("PROXY1REQ"))
{
parent.no_of_reqs++;
parent.jta.append("Request for file from proxy1..\n");
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
int size=parent.jlist2.getModel().getSize();
boolean found=false;
for (int i=0;i<size;i++)
{
if ((parent.jlist2.getModel().getElementAt(i).toString()).equalsIgnoreCase(fname))
{
found=true;
break;
}
}
if (found)
{
Socket s=new Socket(proxy2addr,1800);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("download1");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(fname);
dout.close();
parent.jta.append("Request forwarded to Proxy2.\n");
}
else
{
parent.no_of_server++;
Socket s=new Socket(serveraddr,1900);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("PROXY1REQ");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(fname);
dout.close();
parent.jta.append("Request forwarded to server.\n");
}
}
else
if (req.equals("PROXY2REQ"))
{
parent.no_of_reqs++;
parent.jta.append("Request for file from proxy2..\n");
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
int size=parent.jlist1.getModel().getSize();
boolean found=false;
for (int i=0;i<size;i++)
{
if ((parent.jlist1.getModel().getElementAt(i).toString()).equalsIgnoreCase(fname))
{
found=true;
break;
}
}
if (found)
{
Socket s=new Socket(proxy1addr,1500);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("download1");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(fname);
dout.close();
parent.jta.append("Request forwarded to Proxy1.\n");
}
else
{
parent.no_of_server++;
Socket s=new Socket(serveraddr,1900);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("PROXY2REQ");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(fname);
dout.close();
parent.jta.append("Request forwarded to server.\n");
}
}
din.close();
soc.close();
}
catch(Exception e)
{
System.out.println(e);
}
} |
719f12f3-5dcd-437e-aa26-efa8d1e22a7b | void readaddr()
{
try
{
fin=new FileInputStream("tracker.txt");
while((ch=fin.read())!=-1)
trackeraddr+=(char)ch;
trackeraddr.trim();
fin=new FileInputStream("proxy2.txt");
while((ch=fin.read())!=-1)
proxy2addr+=(char)ch;
proxy2addr.trim();
}
catch(Exception e)
{
System.out.println(e);
}
} |
14bbc715-6e98-40b7-897b-fafb5f10464c | proxyserver()
{
createproxy();
readaddr();
Thread t=new Thread(this);
t.start();
} |
e413c602-7a8e-460c-9986-2268d916f6b4 | void createproxy()
{
jf=new JFrame("PROXY_SERVER");
Container cp=jf.getContentPane();
cp.setLayout(null);
JLabel jl=new JLabel("PROXY SERVER ##1",JLabel.CENTER);
jl.setFont(new Font("Times New Roman",Font.BOLD,28));
jl.setForeground(Color.BLACK);
JLabel jl1=new JLabel("Details of Requests given to Proxy1:");
jta=new JTextArea("Waiting for request..\n");
JScrollPane jsp=new JScrollPane(jta);
jta.setBackground(Color.WHITE);
jta.setForeground(Color.BLACK);
JLabel jl2=new JLabel("List of available files in the proxy Server:");
String dirname="C:\\Users\\vamshi krishna s\\Desktop\\proxyserverfiles";
File f=new File(dirname);
String files[]=f.list();
for (int i=0;i<files.length;i++)
v.add(files[i]);
jlist=new JList(files);
JScrollPane jsp2=new JScrollPane(jlist) ;
jbexit=new JButton("EXIT");
proxyinfo=new JButton("System Info");
stats=new JButton("Statistics");
JLabel jla=new JLabel("CSE FINAL YEAR PROJECT 2012",JLabel.RIGHT);
cp.add(jl);
cp.add(jl1);
cp.add(jsp);
cp.add(jl2);
cp.add(jsp2);
cp.add(jbexit);
cp.add(jla);
cp.add(proxyinfo);
cp.add(stats);
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
jl.setBounds(0,0,d.width,30);
jl1.setBounds(10,50,400,20);
jsp.setBounds(10,80,600,600);
jl2.setBounds(630,50,300,30);
jsp2.setBounds(630,80,300,300);
jbexit.setBounds(700,400,150,30);
proxyinfo.setBounds(700,500,150,30);
stats.setBounds(700,600,150,30);
jf.setSize(d.width,d.height);
jf.setVisible(true);
jbexit.addActionListener(this);
proxyinfo.addActionListener(this);
stats.addActionListener(this);
} |
c3fc5c56-f459-4319-9a5b-24d458c7139f | public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==jbexit)
{
System.exit(0);
}
else if(ae.getSource()==proxyinfo)
{
System.out.print("System Info");
try {
JOptionPane.showMessageDialog(null,"IP Address of the System: "+InetAddress.getLocalHost().getHostAddress()+"\nHost Name:"+InetAddress.getLocalHost().getHostName()+"\n");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(ae.getSource()==stats)
{
JOptionPane.showMessageDialog(null,"Total No of Requests handled By Proxy Server In this Session\n "+no_of_req+"\n");
}
} |
06e8821e-5e38-423f-ac5d-3bc0b562d303 | public void run()
{
try
{
jta.append("Thread Started.");
Socket soc=new Socket(trackeraddr,2000);
DataOutputStream dout=new DataOutputStream(soc.getOutputStream());
dout.writeUTF("PROXY1INFO");
ObjectOutputStream oos=new ObjectOutputStream(soc.getOutputStream());
oos.writeObject(v);
oos.close();
dout.close();
soc.close();
ServerSocket ss=new ServerSocket(1500);
while(true)
{
Socket s=ss.accept();
jta.append("\nNew Client Request Received..\n");
new processreq(this,s);
}
}
catch(Exception e)
{
System.out.println(e+"PServer");
e.printStackTrace();
}
} |
4f3e93eb-c26c-4c39-a74f-44199e346412 | public static void main(String args[])
{
new proxyserver();
} |
fe121912-daf4-4c0f-96f6-5a3296ef7a84 | processreq(proxyserver obj,Socket s)
{
parent=obj;
soc=s;
//readaddr();
Thread t=new Thread(this);
t.start();
} |
fe46776a-f65b-4013-bba3-f6201b80b035 | public void run()
{
try
{
String trackeraddr=parent.trackeraddr,proxy2addr=parent.proxy2addr;
DataInputStream din=new DataInputStream(soc.getInputStream());
String req=din.readUTF();
System.out.println(req);
if (req.equals("download"))
{
parent.no_of_req++;
parent.jta.append("Request is download..\n");
String ip=din.readUTF();
int port=din.readInt();
String fname=din.readUTF();
parent.jta.append("check for file in list\n");
File f=new File(dirname);
File files[]=f.listFiles();
int i=0;
for (i=0;i<files.length;i++)
{
String name=files[i].getName();
if (fname.equalsIgnoreCase(name))
{
FileInputStream fin=new FileInputStream(dirname+"\\"+name);
byte b[]=new byte[fin.available()];
fin.read(b);
fin.close();
Socket s=new Socket(ip,port);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SUCCESS");
dout.writeUTF(name);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
parent.jta.append("File found and forwarded to client..\n") ;
oos.close();
dout.close();
s.close();
break;
}
}
if (i==files.length)
{
parent.jta.append("File not found\n");
Socket s=new Socket(trackeraddr,2000);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("PROXY1REQ");
dout.writeUTF(ip);
dout.writeInt(port);
dout.writeUTF(fname);
dout.close();
s.close();
parent.jta.append("Request forwarded to tracker.\n");
}
// din.close();
// soc.close();
}
else
if (req.equals("SERVERRESPONSE1"))
{
parent.jta.append("File response from server\n");
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
ObjectInputStream oin=new ObjectInputStream(soc.getInputStream());
byte b[]=(byte[]) oin.readObject();
FileOutputStream fout=new FileOutputStream(dirname+"\\"+fname);
fout.write(b);
fout.close();
parent.jta.append("File saved in proxy.\n");
Socket s=new Socket(cip,cport);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SUCCESS");
dout.writeUTF(fname);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
parent.jta.append("File forwardedt to client\n");
oos.close();
dout.close();
s.close();
oin.close();
File f=new File(dirname);
String files[]=f.list();
Vector<String> v=new Vector<String>();
for (int i=0;i<files.length;i++)
v.add(files[i]);
parent.jlist.setListData(v);
Socket soc1=new Socket(trackeraddr,2000);
DataOutputStream dout1=new DataOutputStream(soc1.getOutputStream());
dout1.writeUTF("PROXY1INFO");
ObjectOutputStream oos1=new ObjectOutputStream(soc1.getOutputStream());
oos1.writeObject(v);
oos1.close();
dout1.close();
soc1.close();
}
else
if (req.equals("SERVERRESPONSE2"))
{
parent.jta.append("File response from server\n");
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
Socket s=new Socket(cip,cport);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("FAIL");
dout.writeUTF(fname);
parent.jta.append("File not found, response forwarded to client.\n");
dout.close();
s.close();
}
else
if (req.equals("download1"))
{
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
parent.jta.append("check for file in list\n");
File f=new File(dirname);
File files[]=f.listFiles();
int i=0;
for (i=0;i<files.length;i++)
if (fname.equalsIgnoreCase(files[i].getName()))
break;
FileInputStream fin=new FileInputStream(dirname+"//"+files[i].getName());
byte b[]=new byte[fin.available()];
fin.read(b);
fin.close();
Socket s=new Socket(proxy2addr,1800);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("FORWARD");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(files[i].getName());
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
parent.jta.append("File found and forwarded to client..\n") ;
oos.close();
dout.close();
s.close();
}
else
if (req.equals("FORWARD"))
{
parent.jta.append("File response from Proxy2\n");
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
ObjectInputStream oin=new ObjectInputStream(soc.getInputStream());
byte b[]=(byte[]) oin.readObject();
FileOutputStream fout=new FileOutputStream(dirname+"//"+fname);
fout.write(b);
fout.close();
parent.jta.append("File saved in proxy.\n");
Socket s=new Socket(cip,cport);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SUCCESS");
dout.writeUTF(fname);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
parent.jta.append("File forwardedt to client\n");
oos.close();
dout.close();
s.close();
oin.close();
File f=new File(dirname);
String files[]=f.list();
Vector<String> v=new Vector<String>();
for (int i=0;i<files.length;i++)
v.add(files[i]);
parent.jlist.setListData(v);
Socket soc1=new Socket(trackeraddr,2000);
DataOutputStream dout1=new DataOutputStream(soc1.getOutputStream());
dout1.writeUTF("PROXY1INFO");
ObjectOutputStream oos1=new ObjectOutputStream(soc1.getOutputStream());
oos1.writeObject(v);
oos1.close();
dout1.close();
soc1.close();
}
din.close();
soc.close();
}
catch(Exception e)
{
System.out.println("in process proxy server 1:"+e);
}
} |
665c4577-0d84-4763-9545-39ad6d4378a3 | server()
{
createwin();
Thread t=new Thread(this);
t.start();
} |
998068d3-b4c8-460f-abcc-b1a78983e921 | void createwin()
{
jf=new JFrame("SERVER");
Container cp=jf.getContentPane();
cp.setLayout(null);
JLabel jl=new JLabel("Server Side of the Architecture ",JLabel.CENTER);
jl.setFont(new Font("Dialog",Font.BOLD,20));
jl.setForeground(Color.BLACK);
JLabel jl1=new JLabel("Server Activity:");
jta=new JTextArea("Waiting for request..\n");
JScrollPane jsp=new JScrollPane(jta);
jta.setBackground(Color.WHITE);
jta.setForeground(Color.BLUE);
JLabel jl2=new JLabel("List of available files:");
String dirname="C:\\Users\\vamshi krishna s\\Desktop\\serverfiles";
File f=new File(dirname);
String files[]=f.list();
jlist=new JList(files);
JScrollPane jsp2=new JScrollPane(jlist) ;
jbexit=new JButton("EXIT");
info=new JButton("System Info");
stats=new JButton("Statistics");
cp.add(jl);
cp.add(jl1);
cp.add(jsp);
cp.add(jl2);
cp.add(jsp2);
cp.add(jbexit);
cp.add(info);
cp.add(stats);
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
jl.setBounds(0,0,d.width,30);
jl1.setBounds(10,50,400,20);
jsp.setBounds(10,80,600,600);
jl2.setBounds(630,50,150,20);
jsp2.setBounds(630,80,300,300);
jbexit.setBounds(700,400,100,30);
info.setBounds(850,400,150,30);
stats.setBounds(700,550,150,30);
jf.setSize(d.width,d.height);
jf.setVisible(true);
jbexit.addActionListener(this);
info.addActionListener(this);
stats.addActionListener(this);
} |
4acddb51-f29b-4554-ba3f-6f68d0844c51 | public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==jbexit)
{
System.exit(0);
}
else if(ae.getSource()==info)
{
System.out.print("System Info");
try {
JOptionPane.showMessageDialog(null,"IP Address of the System: "+InetAddress.getLocalHost().getHostAddress()+"\nHost Name:"+InetAddress.getLocalHost().getHostName()+"\n");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(ae.getSource()==stats)
{
JOptionPane.showMessageDialog(null,"Total No of Requests handled By Server In this Session\n "+no_of_req+"\n");
}
} |
a472b7ae-f709-4a91-8a05-18aa58a163ab | public void run()
{
try
{
ServerSocket ss=new ServerSocket(1900);
while(true)
{
Socket s=ss.accept();
jta.append("\nRequest recedived from tracker\n");
// no_of_req++;
new serverprocess(this,s);
}
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
} |
ff13a93e-dd8b-4b7f-ae0b-b0637a48f66c | public static void main(String args[])
{
new server();
} |
c715877e-a17d-42d4-8fd1-3fe707a98173 | serverprocess(server obj,Socket s)
{
parent=obj;
soc=s;
readaddr();
Thread t=new Thread(this);
parent.jta.append("Server Thread Started");
t.start();
} |
c191c706-92dc-4015-951d-48ca0b1fdea2 | void readaddr()
{
try
{
fin=new FileInputStream("proxy1.txt");
while((ch=fin.read())!=-1)
proxy1addr+=(char)ch;
proxy1addr.trim();
fin=new FileInputStream("proxy2.txt");
while((ch=fin.read())!=-1)
proxy2addr+=(char)ch;
proxy2addr.trim();
}
catch(Exception e)
{
System.out.println(e);
}
} |
ba0f46a3-94f5-481f-bb89-c01f656bbcf9 | public void run()
{
try
{
parent.no_of_req++;
DataInputStream din=new DataInputStream(soc.getInputStream());
String req=din.readUTF();
String cip=din.readUTF();
int cport=din.readInt();
String fname=din.readUTF();
parent.jta.append("File Name is "+fname+"\n");
boolean found=false;
int size=parent.jlist.getModel().getSize();
int i=0;
for (i=0;i<size;i++)
{
if ((parent.jlist.getModel().getElementAt(i).toString()).equalsIgnoreCase(fname))
{
found=true;
break;
}
}
if (req.equals("PROXY1REQ"))
{
if (found)
{
FileInputStream fin=new FileInputStream(dirname+"//"+parent.jlist.getModel().getElementAt(i).toString());
byte b[]=new byte[fin.available()];
fin.read(b);
fin.close();
Socket s=new Socket(proxy1addr,1500);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SERVERRESPONSE1");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(fname);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
oos.close();
dout.close();
s.close();
parent.jta.append("File found and forwarded to Proxy1.\n ");
}
else
{
Socket s=new Socket(proxy1addr,1500);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SERVERRESPONSE2");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(fname);
dout.close();
s.close();
parent.jta.append("File not found. Response sent to proxy1.\n");
}
}
else
if (req.equals("PROXY2REQ"))
{
if (found)
{
FileInputStream fin=new FileInputStream(dirname+"//"+parent.jlist.getModel().getElementAt(i).toString());
byte b[]=new byte[fin.available()];
fin.read(b);
fin.close();
Socket s=new Socket(proxy2addr,1800);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SERVERRESPONSE1");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(fname);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(b);
oos.close();
dout.close();
s.close();
parent.jta.append("File found and frowarded to Proxy2.\n");
}
else
{
Socket s=new Socket(proxy2addr,1800);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("SERVERRESPONSE2");
dout.writeUTF(cip);
dout.writeInt(cport);
dout.writeUTF(fname);
dout.close();
s.close();
parent.jta.append("File not found. Response sent to proxy2.\n");
}
}
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
} |
b9688ef9-39e5-4025-bf74-c786f47ad055 | public Query(List<QueryItem> items) {
mItems = items;
} |
e348936b-2daf-476c-a7c2-6338b8766fa8 | public List<QueryItem> getItems() {
return mItems;
} |
3e50e562-bd9c-4a77-aef3-84d8fc9afb7b | public String toString() {
StringBuilder sb = new StringBuilder();
for (QueryItem item : mItems) {
sb.append(item.toString());
sb.append(' ');
}
return sb.toString().trim();
} |
bd118f6f-388e-46ed-be1c-73afef222016 | @Test
public void testTrivialEquation() {
String expected = "2";
String actual = CalcParser.solve("1+1");
assertEquals("1+1 should equal 2", expected, actual);
} |
46e622df-c8dc-4dae-a6a2-ce8ddfce0ffd | @Test
public void testAnotherTrivialEquation() {
String expected = "4";
String actual = CalcParser.solve("2*2");
assertEquals("2*2 should equal 4", expected, actual);
} |
bbf11dca-1d0c-408e-a1ce-6b841cf06938 | @Test
public void testTrivialWithWhiteSpaceEquation() {
String expected = "4";
String actual = CalcParser.solve("2 * 2");
assertEquals("2 * 2 should equal 4", expected, actual);
} |
c2d796d7-9b90-4440-9bd3-1a17b859db49 | @Test
public void testComprehensiveStrings(){
for(String[] equationPair : testStr){
String expected = equationPair[0];
String actual = CalcParser.solve(equationPair[1]);
assertEquals(
String.format("Comprehensive test of \"%s\"", equationPair[1]),
expected,
actual);
}
} |
3ded0506-ce13-44e3-8a1c-a1b1a46da716 | public SearchEngine(String filepath) {
dataFilepath = filepath;
} |
ef56fb52-b302-46af-997a-c372a0f413f4 | public static boolean isMatch(String sentence, String query) {
SearchEngine e = new SearchEngine(PATH);
QueryParser q = new QueryParser();
Query qobj = q.parse(query);
List<String> a = new ArrayList<String>();
a.add(sentence);
for (QueryItem item : qobj.getItems()) {
a = e.searchSentence(a, item);
}
return a.size() > 0;
} |
224de425-790e-4f6a-9761-1dc9bfb8d7ac | public List<String> search(Query query) {
// load data
List<String> searchResults = DataRetriever.getData(dataFilepath);
for (QueryItem subQuery : query.getItems()) {
searchResults = searchSentence(searchResults, subQuery);
}
return searchResults;
} |
a972b388-4f58-490d-9781-89b613a1c6a9 | private List<String> searchSentence(List<String> data, QueryItem query) {
String queryWord = query.getWord();
queryWord = queryWord.toLowerCase();
switch(query.getBeforeOperator()) {
case Not:
queryNOT(data, queryWord);
break;
case Or:
queryOR(data, queryWord);
break;
case And:
queryAND(data, queryWord, query.getAtLeast());
break;
}
return data;
} |
44287b84-4c05-4b0f-a86c-cae43687c4b2 | private void queryNOT(List<String> data, String word) {
String[] dataAr = new String[data.size()];
for(int i = 0; i < data.size(); i++){
dataAr[i] = data.get(i);
}
for (String sentence : dataAr) {
String caseInsensitiveSentence = sentence.toLowerCase();
if (caseInsensitiveSentence.contains(word)) {
data.remove(sentence);
}
}
} |
477dd92b-c7d7-431a-a2ff-63491a127aa5 | private void queryOR(List<String> data, String word) {
} |
81e22bc4-9a5f-4ebd-8847-b6002ec6189e | private void queryAND(List<String> data, String word, int atLeast) {
String[] dataAr = new String[data.size()];
for(int i = 0; i < data.size(); i++){
dataAr[i] = data.get(i);
}
for (String sentence : dataAr) {
String caseInsensitiveSentence = sentence.toLowerCase();
if (!queryANDHasAtLeast(caseInsensitiveSentence, word, atLeast)) {
data.remove(sentence);
}
}
} |
2b1f2280-ee57-46fc-9673-92b7224d24dd | private boolean queryANDHasAtLeast(String sentence, String word, int atLeast) {
if (atLeast < 0) {
return true;
}
else if (sentence.contains(word)) {
String strippedSentence = sentence.replaceFirst(word, "");
return queryANDHasAtLeast(strippedSentence, word, atLeast - 1);
}
return false;
} |
9bb4de75-945c-4099-97f3-7a95a16fa8aa | private void queryEXACT(List<String> data, String word) {
String[] dataAr = new String[data.size()];
for(int i = 0; i < data.size(); i++){
dataAr[i] = data.get(i);
}
for (String sentence : dataAr) {
String caseInsensitiveSentence = sentence.toLowerCase();
if (!caseInsensitiveSentence.contains(word)) {
data.remove(sentence);
}
}
} |
13d4e042-af5a-45a5-8c5a-f71f0c9d843b | private void queryRANGE(List<String> data, String word) {
String[] dataAr = new String[data.size()];
for(int i = 0; i < data.size(); i++){
dataAr[i] = data.get(i);
}
for (String sentence : dataAr) {
String caseInsensitiveSentence = sentence.toLowerCase();
if (!caseInsensitiveSentence.matches("([0-9])+(\\s..){1}([0-9])+")) {
data.remove(sentence);
}
}
} |
570fa78c-0826-4b41-97c7-64e181309442 | public static String solve(String equation){
String cleanEqn = stripWhitespace(equation);
return pythonEval(cleanEqn);
} |
ac6e0d15-83fe-4b5a-80f2-0910460f2ee3 | private static String stripWhitespace(String equation) {
return equation.replaceAll("\\s", "");
} |
af74a4b1-28ae-4bbc-81c7-3a772d0b2db9 | private static String pythonEval(String equation){
PrintStream tempWriter = null;
BufferedReader reader = null;
try {
// create the python program
File tempFile = new File("temp.py");
tempWriter = new PrintStream(tempFile);
tempWriter.printf("print(%s)", equation);
// prepare it
Process python = new ProcessBuilder("python", "temp.py").start();
reader = new BufferedReader(new InputStreamReader(python.getInputStream()));
// let it run
python.waitFor();
// get the output of the python program
String response = reader.readLine();
// kill the python process
python.destroy();
// cleanup
tempFile.delete();
return response;
} catch (IOException e) {
// don't care
} catch (InterruptedException e) {
// don't care
} finally {
close(tempWriter);
close(reader);
}
return "";
} |
6a4546f4-3fc1-4b7d-a031-b4264ece98a0 | private static void close(Closeable c){
if(c != null){
try {
c.close();
} catch (IOException e) {
// don't care!!
}
}
} |
2f637cdd-a883-432e-8814-a7001982b1a2 | public Query parse(String query) {
query = preprocess(query);
String[] tokens = tokenize(query);
List<QueryItem> items = parse(tokens);
return new Query(items);
} |
80d88d09-fe05-4222-9c11-d7f730dc866c | private String[] tokenize(String query) {
int position = 0;
boolean inQuotes = false;
ArrayList<String> words = new ArrayList<String>();
StringBuilder sb = new StringBuilder();
while (position < query.length()) {
char c = query.charAt(position++);
if (inQuotes) {
if (c == '"') {
words.add(sb.toString());
sb.setLength(0);
} else {
sb.append(c);
}
} else if (c == '{' && sb.length() > 0) {
words.add(sb.toString());
sb.setLength(0);
sb.append(c);
} else if (c == ' ') {
words.add(sb.toString());
sb.setLength(0);
} else if (c != '"') {
sb.append(c);
}
if (c == '"') {
inQuotes = !inQuotes;
}
}
if (sb.length() > 0) {
words.add(sb.toString());
}
return words.toArray(new String[words.size()]);
} |
fdf21fce-7e76-4bf7-8d6b-f651dbdb54df | private List<QueryItem> parse(String[] tokens) {
ArrayList<QueryItem> items = new ArrayList<QueryItem>();
QueryOperator nextOp = QueryOperator.And;
for (String token : tokens) {
token = token.toLowerCase();
if (token.charAt(0) == '{') {
token = token.substring(1, token.length()-1);
items.get(items.size()-1).setAtLeast(Integer.parseInt(token));
} else if (token.equals("and")) {
nextOp = QueryOperator.And;
} else if (token.equals("or")) {
nextOp = QueryOperator.Or;
} else if (token.equals("not")) {
nextOp = QueryOperator.Not;
} else {
QueryItem item = new QueryItem(token, nextOp);
items.add(item);
nextOp = QueryOperator.And;
}
}
return items;
} |
8e29d525-b031-414b-a585-7a77d651dfe9 | private String preprocess(String query) {
// Extract CALC operations
CalcParser calc = new CalcParser();
Matcher m = RE_CALC.matcher(query);
StringBuilder sb = new StringBuilder();
int position = 0;
while (!m.hitEnd()) {
if (m.find()) {
// Add everything before the match to the StringBuilder
sb.append(query.substring(position, m.start()));
position = m.start();
// Extract the match, process it, append to the StringBuilder
String match = m.group(1);
sb.append(calc.solve(match));
// Advance the position by the length of the match
position += match.length() + "{CALC }".length();
}
}
// Add the rest of the query to the end of the QueryParser
if (position >= 0 && position < query.length()) {
sb.append(query.substring(position));
}
return sb.toString();
} |
8b501f42-a7ee-465f-8728-4d49a7b627cb | private static void main(String[] argv) {
QueryParser q = new QueryParser();
System.out.println(q.parse("The{5}"));
System.out.println(q.parse("\"the * example\"{4} {CALC 8*(8+9/3)}..{CALC 90000/10+1} OR *park NOT bench"));
System.out.println(q.parse("Test {CALC 8+1+3+5/2} oaeu {calc 4+2}"));
System.out.println(q.parse("an example {CALC 3}"));
System.out.println(q.parse("{CALC 3} an example"));
} |
8f5d8d07-66a4-4a46-8153-7d50b403f388 | public static void main(String[] args) throws FileNotFoundException {
List<String> sentences = loadSentences(args[0]);
String query = args[1];
for (String sentence : sentences) {
if (SearchEngine.isMatch(sentence, query)) {
System.out.println(sentence);
}
}
} |
453115e6-c14a-49e6-a1f1-433fd4258e78 | private static List<String> loadSentences(String filename) throws FileNotFoundException {
Scanner scanner = new Scanner(new File(filename));
scanner.useDelimiter("\n");
List<String> sentences = new ArrayList<String>();
while (scanner.hasNext()) {
sentences.add(scanner.next().trim());
}
scanner.close();
return sentences;
} |
9f4c7be1-690a-4eb6-a263-38856b3dc301 | public QueryItem(String word, QueryOperator op) {
this.mWord = word;
mBeforeOperator = op;
} |
456141ad-44f9-4313-9394-dd0e9c3340cf | public String getWord() {
return mWord;
} |
f06676b9-41c7-486b-9bb0-c80b3554c925 | public int getAtLeast() {
return mAtLeast;
} |
e76f04ea-0660-4801-bbae-db853101815c | public void setAtLeast(int v) {
mAtLeast = v;
} |
e5d3e37b-f499-4608-a3e9-b8a83ba2bc9d | public QueryOperator getBeforeOperator() {
return mBeforeOperator;
} |
a5764a10-5b4f-48c4-904d-5b005a54afeb | public String toString() {
String r = this.mWord;
if (mWord.contains(" ")) {
r = '"' + r + '"';
}
r = mBeforeOperator.toString().toUpperCase() + " " + r;
if (mAtLeast > 0) {
r += "{" + Integer.toString(mAtLeast) + "}";
}
return r;
} |
8704f789-e22b-4a13-a4e4-fb1133a5ea41 | public static List<String> getData(String filepath) {
ArrayList<String> sentenceData = new ArrayList<String>();
try {
// get file
File rawData = new File(filepath);
// load file
FileInputStream inputStream = new FileInputStream(rawData);
StringBuilder sentence = new StringBuilder();
// read data
while (true) {
int character = inputStream.read();
if ( character == END_OF_FILE ) {
sentenceData.add(sentence.toString());
break;
}
else if ( character == NEWLINE ) {
// newline = add sentence and clear string builder
sentenceData.add(sentence.toString());
sentence = new StringBuilder();
}
else {
sentence.append((char)character);
}
}
// LOWERCASING
for (String str : sentenceData) {
str = str.toLowerCase();
}
inputStream.close(); //cleanup
}
catch (FileNotFoundException e) {
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sentenceData;
} |
39fc5d7c-6ca1-48e3-af34-0a05b28f0a9f | public void setup() {
size(1280,520);
kinect = new Kinect(this);
kinect.start();
kinect.enableDepth(depth);
kinect.enableRGB(rgb);
int h = kinect.getVideoImage().height;
int w = kinect.getVideoImage().width;
int hd = kinect.getDepthImage().height;
int wd = kinect.getDepthImage().width;
System.out.println("h:"+h+" w:"+w + " hd:"+ hd + " wd:"+wd);
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.