id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
90ac72d0-a832-4aee-ace8-aed251477926 | private boolean checkAttackMove(Square square) {
if (square.isBlocked()) {
if (isWhite != square.getPiece().isWhite) {
moves.add(square);
return false;
}
return false;
}
return false;
} |
5c015413-4945-4dc5-a9f6-65d506ad3297 | public Rook(int x, int y, boolean isWhite) {
super(x, y, isWhite);
} |
c37bb932-7f8e-4271-962d-35d3593f2986 | @Override
public HashSet<Square> getMoves() {
return moves;
} |
1078b852-f1ae-4d90-b07b-4a6fc2f904aa | @Override
public HashSet<Square> calcMoves(ChessBoard board) {
moves = new HashSet<Square>();
for(int i = 1; checkMove(board.getSquare(x+i, y)); i++) {}
for(int i = 1; checkMove(board.getSquare(x-i, y)); i++) {}
for(int i = 1; checkMove(board.getSquare(x, y+i)); i++) {}
for(int i = 1; checkMove(board.getSquare(x, y-i)); i++) {}
return moves;
} |
605daf6d-2747-4a67-bc0e-5351f3090c80 | public Chess() {
// TODO Auto-generated method stub
} |
52f6861f-91e0-4a87-81aa-c3cac7b0ee69 | public King(int x, int y, boolean isWhite) {
super(x, y, isWhite);
} |
3292fbe3-b2de-43d2-97af-8b30b99a8cec | @Override
public HashSet<Square> getMoves() {
return moves;
} |
d88078cc-7c3e-4868-90f0-4224e337b124 | @Override
public HashSet<Square> calcMoves(ChessBoard board) {
moves = new HashSet<Square>();
checkMove(board.getSquare(x+1,y));
checkMove(board.getSquare(x-1,y));
checkMove(board.getSquare(x,y+1));
checkMove(board.getSquare(x,y-1));
checkMove(board.getSquare(x+1,y+1));
checkMove(board.getSquare(x-1,y-1));
checkMove(board.getSquare(x+1,y-1));
checkMove(board.getSquare(x-1,y+1));
return moves;
} |
8e671949-6e43-44b4-b4a2-34f81fc7ef27 | public Bishop(int x, int y, boolean isWhite){
super(x,y,isWhite);
} |
e0ea2367-1e72-44ef-8c9e-ac73196b5a20 | @Override
public HashSet<Square> getMoves() {
return moves;
} |
8dcf0272-56e9-42e8-8836-89fbe9a10039 | @Override
public HashSet<Square> calcMoves(ChessBoard board) {
moves = new HashSet<Square>();
for(int i = 1; checkMove(board.getSquare(x+i, y+i)); i++) {}
for(int i = 1; checkMove(board.getSquare(x+i, y-i)); i++) {}
for(int i = 1; checkMove(board.getSquare(x-i, y+i)); i++) {}
for(int i = 1; checkMove(board.getSquare(x-i, y-i)); i++) {}
return moves;
} |
7f767fb5-7c5a-4b8a-b4b2-0a0b87ee70be | public Piece(int x, int y, boolean isWhite){
this.x = x;
this.y = y;
this.isWhite = isWhite;
} |
4c163186-194c-48ab-a26d-1fae6bfea9e7 | public void setIcon(ImageIcon icon) {
this.icon = icon;
} |
9f7cbd51-752e-4ea3-ad56-9209b788460c | public ImageIcon getIcon() {
return icon;
} |
8937dc5b-31d7-480b-9115-8ad29593c9b2 | public abstract HashSet<Square> getMoves(); |
b377aff3-95a0-4525-a627-f623c40bec40 | public abstract HashSet<Square> calcMoves(ChessBoard board); |
00a15e2c-40ef-4f65-8825-ba75cbacddbb | protected boolean checkMove(Square square) {
if (square == null) return false;
if (square.isBlocked()){
if (isWhite != square.getPiece().isWhite) {
moves.add(square);
return false;
}
return false;
}
moves.add(square);
return true;
} |
18312237-3c96-4d7c-ba60-b225725c04b2 | public Knight(int x, int y, boolean isWhite){
super(x, y, isWhite);
} |
d32be310-334b-4cc8-8505-290e9b8aeafd | @Override
public HashSet<Square> getMoves() {
return moves;
} |
8cff6ec1-50b5-4d3d-a287-1ee34107b01b | @Override
public HashSet<Square> calcMoves(ChessBoard board) {
moves = new HashSet<Square>();
checkMove(board.getSquare(x+2,y+1));
checkMove(board.getSquare(x+1,y+2));
checkMove(board.getSquare(x-2,y-1));
checkMove(board.getSquare(x-1,y-2));
checkMove(board.getSquare(x-2,y+1));
checkMove(board.getSquare(x-1,y+2));
checkMove(board.getSquare(x+2,y-1));
checkMove(board.getSquare(x+1,y-2));
return moves;
} |
1982d164-4ee3-4594-9def-7baedabe1644 | public Location(int row, int column) {
this.row = row;
this.column = column;
} |
ea79eeb9-39e0-49a0-95d4-1e8c8ed71420 | public int getRow() {
return row;
} |
23d505b1-a75c-4e91-a9aa-972efa5a3d3c | public int getColumn() {
return column;
} |
f2bbab25-faef-4b99-803e-ad98834443fe | public Square(String text, Color color, Location location, ActionListener al) {
this.location = location;
//super.setText(text);
super.setPreferredSize(new Dimension(50, 50));
super.setOpaque(true);
super.setForeground(Color.BLACK);
super.setBackground(color);
setBorderColor(Color.BLACK);
super.addActionListener(al);
} |
577b6140-69cc-4f23-92e1-9110f9824631 | public void removePiece() {
setIcon(null);
piece = null;
setBorderColor(Color.BLACK);
} |
52b99693-f1cd-43d9-bb2c-0c748849f7e4 | public void setPiece(Piece p) {
setIcon(p.getIcon());
piece = p;
super.setIcon(p.getIcon());
} |
b22d0fbe-eea7-4c2e-a1e9-41d8ee28a0c9 | public Piece getPiece() {
return piece;
} |
596a44e3-f2ca-4869-9e54-2443a814d15b | public boolean isBlocked() {
if (piece == null)
return false;
return true;
} |
2e8e8d57-adc1-4837-8dd7-4f2b9b8e8520 | public Location getPos() {
return location;
} |
2f857841-edcc-4bac-9a03-4c7e1042b0a6 | public void changeColor(Color color) {
super.setBackground(color);
} |
02b3dd02-eb2e-49f9-9985-c2636095fb55 | private void setBorderColor(Color color) {
Border line = new LineBorder(color);
Border margin = new EmptyBorder(1, 1, 1, 1);
Border compound = new CompoundBorder(line, margin);
super.setBorder(compound);
} |
1bdd2729-faeb-44da-a7a3-609e123e3568 | public Craft() {
ImageIcon ii = new ImageIcon(this.getClass().getResource(craft));
image = ii.getImage();
x = 40;
y = 60;
} |
72f228af-fc00-4e4f-b5d1-1c437a1f0d60 | public void move() {
x += dx;
y += dy;
} |
bde9fd00-a058-4ecd-8f17-93036fbabac6 | public int getX() {
return x;
} |
5e12d7a6-da16-4612-96e0-306f89c641af | public int getY() {
return y;
} |
da2694aa-0bfe-4b74-8197-8a6a73e91af1 | public Image getImage() {
return image;
} |
63c87751-241d-4ad5-8257-c600c98336fb | public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
dx = -2;
ii = new ImageIcon(this.getClass().getResource("craftBACK.png"));
image = ii.getImage();
}
if (key == KeyEvent.VK_RIGHT) {
dx = 2;
ii = new ImageIcon(this.getClass().getResource("craft.png"));
image = ii.getImage();
}
if (key == KeyEvent.VK_UP) {
dy = -2;
ii = new ImageIcon(this.getClass().getResource("craftUP.png"));
image = ii.getImage();
}
if (key == KeyEvent.VK_DOWN) {
dy = 2;
ii = new ImageIcon(this.getClass().getResource("craftDOWN.png"));
image = ii.getImage();
}
} |
65602847-c383-44b8-a483-18ba8c4714f7 | public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
dx = 0;
}
if (key == KeyEvent.VK_RIGHT) {
dx = 0;
}
if (key == KeyEvent.VK_UP) {
dy = 0;
}
if (key == KeyEvent.VK_DOWN) {
dy = 0;
}
} |
ffebfd45-c402-4b10-8ab7-bd8136743585 | public Board() {
addKeyListener(new TAdapter());
setFocusable(true);
setBackground(Color.BLACK);
setDoubleBuffered(true);
craft = new Craft();
timer = new Timer(5, this);
timer.start();
} |
3d8a96bf-8301-4c7f-881d-cb7a580328fa | public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D)g;
g2d.drawImage(craft.getImage(), craft.getX(), craft.getY(), this);
Toolkit.getDefaultToolkit().sync();
g.dispose();
} |
2e60fdf1-7685-4166-8df7-2bc3335ece03 | public void actionPerformed(ActionEvent e) {
craft.move();
repaint();
} |
18a29214-a868-4ceb-bcca-5578bfeb0c44 | public void keyReleased(KeyEvent e) {
craft.keyReleased(e);
} |
0f359003-e1db-46d1-83fb-bff6c422c024 | public void keyPressed(KeyEvent e) {
craft.keyPressed(e);
} |
e8743099-2cdc-4319-8e86-47fc59aa45ee | public Client(){
crObj = new Craft();
} |
fa7d4962-e0c2-4ce8-8767-460413497648 | public Client( Craft newcrObj){
crObj = newcrObj;
} |
515ac258-c3a7-431b-a845-ced28eed0b4f | public void run() {
// Craft crObj = null;
String serverName = "127.0.0.1";
int port = 6789;
int port1 = 6788;
Socket client = null, client1 = null;
System.out.println("Connecting to " + serverName + " on port " + port);
OutputStream outsetup = null, out1setup = null;
try {
client = new Socket(serverName, port);
client1 = new Socket(serverName, port1);
} catch (IOException e) {
System.out.println(e);
}
System.out.println("Connected");
Scanner test = new Scanner(System.in);
try {
outsetup = client.getOutputStream();
out1setup = client1.getOutputStream();
} catch(IOException e) {
System.out.println(e);
}
DataOutputStream out = new DataOutputStream(outsetup);
DataOutputStream out1 = new DataOutputStream(out1setup);
while(true) {
playerX = crObj.x;
playerY = crObj.y;
try{
Thread.sleep(10);
System.out.println(playerY);
out.writeInt(playerX);
out.flush();
out1.writeInt(playerY);
out1.flush();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//client.close();
//client1.close();
} |
af7ae31f-57ba-4495-8956-acaa445d58d4 | public RType() {
Board board =new Board();
add(board);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
setTitle("R - Type");
setResizable(false);
setVisible(true);
(new Thread(new Client(board.craft))).start();
} |
553be056-2bc1-4587-b323-88d97498becc | public static void main(String[] args) {
new RType();
} |
470eb002-a175-4068-9472-746528e23701 | public static void main(String[] args) throws Exception {
IocContainer container = new IocContainerBuilder().withPackageName("domain")
.withConfigFile("ioc-config.xml")
.build();
AppRunner runner = (AppRunner) container.getBeanById("anotherAppRunner");
runner.run();
} |
b2840b51-018b-4ee3-966b-a22be6ca4cbe | public void run() {
System.out.println("truck is running");
} |
8e1f0dad-4a66-4bcc-b784-6355bdd6e3f1 | @Inject public AppRunner(@Qualified(id="car")Vehicle car, @Qualified(id="multiwheel")Vehicle multiWheel) {
this.car = car;
this.multiWheel = multiWheel;
} |
fc224e2e-c855-47b2-9770-52f8ea9b6cc0 | @Inject @Qualified(id="jeep")
public void setJeep(Vehicle jeep) {
this.jeep = jeep;
} |
f919d762-9aea-4da8-a18f-8660873143d5 | public void run() {
car.run();
truck.run();
jeep.run();
multiWheel.run();
} |
153b3d78-6433-4dd1-8375-c7a7477013da | public void setTruck(Vehicle truck) {
this.truck = truck;
} |
3b1f69b6-ce53-4d35-a7b2-39fa8dfb65e2 | public void run() {
System.out.println("car is running");
} |
fb4f1536-8efb-473a-b9d7-09c8d5ea7d6b | public void run(); |
6186656f-671b-44af-9432-d0cfd1729553 | public MultiWheelVehicle(int numberOfWheel) {
this.numberOfWheel = numberOfWheel;
} |
fd4d7e26-2e03-478d-a113-f33261946b20 | @Override
public void run() {
System.out.println("multiWheelVehicle is running with " + numberOfWheel + " wheels");
} |
b087ff9d-af1e-4326-88b2-d02fee36963a | public void run() {
System.out.println("jeep is running");
} |
3148e5b5-5565-4bf0-95bf-79a0ced86343 | private Messages() {
} |
9f41ac6e-5c85-4b82-a3c1-c019e57d7d91 | public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
} |
fbd4774d-575f-41db-a851-fab68c15135a | public void createConnection() {
try {
Class.forName(Messages.getString("Following.DERBY_DRIVER")).newInstance(); //$NON-NLS-1$
// Get a connection
conn = DriverManager.getConnection(dbURL);
} catch (Exception except) {
except.printStackTrace();
}
} |
3cbdf36b-d1f2-4ab5-81dc-a8230e2972ed | public void insertRecords(String userId, String follows) {
createConnection();
try {
stmt = conn.createStatement();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("insert into FollowsTable values ('");
stringBuilder.append(userId);
stringBuilder.append("','");
stringBuilder.append(follows);
stringBuilder.append("')");
stmt.execute(stringBuilder.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
stmt.close();
} catch (SQLException sqlExcept) {
sqlExcept.printStackTrace();
}
close();
} |
19e0aaf0-fbde-4e74-bb60-3fe2ca8e1148 | public List<String> selectRecords(String sql) {
createConnection();
ArrayList<String> followsList = new ArrayList<String>();
try {
stmt = conn.createStatement();
ResultSet results = stmt.executeQuery(sql);
while (results.next()) {
followsList.add(results.getString(1));
}
results.close();
stmt.close();
} catch (SQLException sqlExcept) {
sqlExcept.printStackTrace();
}
close();
return followsList;
} |
5c80f319-2dcb-4cb8-a9f4-8b9275e39633 | public void close() {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
DriverManager.getConnection(dbURL + ";shutdown=true"); //$NON-NLS-1$
conn.close();
}
} catch (SQLException sqlExcept) {
}
} |
3e5a702f-3cb3-45fe-83c6-822be49e6b54 | public static void printToConsole(String msg) {
// TODO Auto-generated method stub
System.out.println(msg);
} |
f2834538-f8b4-4281-a690-28f1eabda247 | public static void main(String[] args) {
// TODO Auto-generated method stub
Following followingObj = new Following();
printToConsole(Messages.getString("Following.USER_PROMPT")); //$NON-NLS-1$
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String user_input_string;
try {
user_input_string = r.readLine();
if (user_input_string != null && !user_input_string.equals("")) { //$NON-NLS-1$
String username = user_input_string.substring(0,
user_input_string.indexOf(" ")); //$NON-NLS-1$
String userToFollow = user_input_string
.substring(
user_input_string.lastIndexOf(" ") + 1, user_input_string.length()); //$NON-NLS-1$
followingObj.insertRecords(username, userToFollow);
List<String> followingUsersList = (List<String>) followingObj
.selectRecords(Messages.getString("Following.SELECT") + username + "'"); //$NON-NLS-1$ //$NON-NLS-2$
if (!followingUsersList.isEmpty()) {
if (!followingUsersList.contains(username)) {
followingUsersList.add(username);
}
if (!followingUsersList.contains(userToFollow)) {
followingUsersList.add(userToFollow);
}
}
String[] queueNames = followingUsersList
.toArray(new String[] {});
new Reading(queueNames).start();
// String [] readPosts ={username,userToFollow};
// new Reading(readPosts).start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
System.err.println(e.getMessage());
e.printStackTrace();
}
} |
5819339a-9160-462d-b1e6-761c2b2080e0 | @SuppressWarnings("unchecked")
public void browseMessages(String[] mConsumerQueueNames) {
Connection connection = null;
Queue q = null;
Enumeration<MapMessage> messageEnumeration = null;
MapMessage mapMessage = null;
Session session = null;
MapMessageListener mapMsgListener = new MapMessageListener();
try {
for (int index = 0; index < mConsumerQueueNames.length; ++index) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("jms/");
stringBuilder.append(mConsumerQueueNames[index]);
stringBuilder.append("Queue");
String qJNDI = stringBuilder.toString();
try {
InitialContext ctx = new InitialContext();
q = (Queue) ctx.lookup(qJNDI);
ConnectionFactory cf = (ConnectionFactory) ctx
.lookup("jms/ConnectionFactory");
connection = cf.createConnection();
session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
QueueBrowser browser = session.createBrowser(q);
messageEnumeration = browser.getEnumeration();
if (messageEnumeration != null) {
if (!messageEnumeration.hasMoreElements()) {
System.out.println("There are no messages "
+ "in the queue.");
} else {
while (messageEnumeration.hasMoreElements()) {
mapMessage = (MapMessage) messageEnumeration
.nextElement();
mapMsgListener.onMessage(mapMessage);
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
session.close();
connection.close();
} catch (JMSException e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println(e.getMessage());
}
}
}
} |
c00b4372-d3fb-4ee7-8e9e-019abf71b677 | public static void main(String[] args) {
// TODO Auto-generated method stub
Following followingObj = new Following();
Wall wallObj = new Wall();
System.out.println(USER_WALL_PROMPT);
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String user_input_string;
try {
user_input_string = r.readLine();
if (user_input_string != null && !user_input_string.equals("")) {
String username = user_input_string.substring(0,
user_input_string.indexOf(" "));
StringBuilder stringBuilder
= new StringBuilder();
stringBuilder
.append("select distinct follows from FollowsTable where userId='");
stringBuilder
.append(username);
stringBuilder
.append("'");
@SuppressWarnings("unchecked")
ArrayList<String> followingUsersList = (ArrayList<String>) followingObj
.selectRecords(stringBuilder
.toString());
if (!followingUsersList.isEmpty()) {
if (!followingUsersList.contains(username)) {
followingUsersList.add(username);
}
String[] usersToFollow = followingUsersList
.toArray(new String[] {});
wallObj.browseMessages(usersToFollow);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
System.err.println(e.getMessage());
e.printStackTrace();
}
} |
f4ec8818-a4f9-41d3-8279-ca3cbed4d032 | private long timeElapsedSincePost(long timePostedInMilliseconds) {
long currentTime = System.currentTimeMillis();
long timeElapsed = (currentTime - timePostedInMilliseconds) / 60000;
return timeElapsed;
} |
e3fddd1f-fb11-4e06-b103-dd592e57628b | @Override
public void onMessage(Message message) {
// TODO Auto-generated method stub
if (message instanceof MapMessage) {
MapMessage mapMessage = (MapMessage) message;
try {
long msgReceivedTime = mapMessage.getJMSTimestamp();
long timeElapsed = timeElapsedSincePost(msgReceivedTime);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("> ");
stringBuilder.append(mapMessage.getString("UserName"));
stringBuilder.append("\n");
stringBuilder.append(mapMessage.getString("UserTweet"));
stringBuilder.append("(");
stringBuilder.append(timeElapsed);
stringBuilder.append(" minutes ago)");
stringBuilder.append("\n");
String messageOutput = stringBuilder.toString();
System.out.println(messageOutput);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println(e.getMessage());
}
} else {
System.out.println("Invalid Msg Received");
}
} |
e2b18119-445c-4dc6-b29c-60c978daba80 | public Reading(String[] consumerQueueNames) {
mConsumerQueueNames = consumerQueueNames;
} |
2f2a0c3f-12ac-4af9-9fd2-13b874acf635 | public void start() {
Thread thread = new Thread(new Runnable() {
public void run() {
Reading.this.run();
}
});
thread.setName("Topic Dispatcher");
thread.start();
} |
3305192c-6308-4484-8ef3-96fd5fa1f904 | public void run() {
Reading.this.run();
} |
80276be4-d22a-46f5-95a6-d3aa88003091 | private void run() {
Queue q = null;
Connection connection = null;
for (int index = 0; index < mConsumerQueueNames.length; ++index) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("jms/");
stringBuilder.append(mConsumerQueueNames[index]);
stringBuilder.append("Queue");
String queueJNDI = stringBuilder.toString();
try {
InitialContext ctx = new InitialContext();
q = (Queue) ctx.lookup(queueJNDI);
ConnectionFactory cf = (ConnectionFactory) ctx
.lookup("jms/ConnectionFactory");
connection = cf.createConnection();
Session session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(q);
// consumer.setMessageListener(new TextMessageListener());
consumer.setMessageListener(new MapMessageListener());
connection.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
198b477f-0dd0-47f9-934b-41d5d0b9d38a | public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
//
System.out.println(USER_PROMPT);
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String user_input_string;
user_input_string = r.readLine();
if (user_input_string != null && !user_input_string.equals("")) {
if (user_input_string.equalsIgnoreCase("Bob")) {
String[] queueNames = { user_input_string.trim(), "Alice" };
new Reading(queueNames).start();
} else {
String[] queueNames = { user_input_string.trim() };
new Reading(queueNames).start();
}
}
} |
61896e44-69f5-4378-8d26-fd9040d25ca3 | public static void postMessage(String userName, String userMessage)
throws Exception {
Connection connection = null;
try {
Context ctx = new InitialContext();
String topicJndi = "jms/" + userName + "Queue";
Queue queue = (Queue) ctx.lookup(topicJndi);
ConnectionFactory cf = (ConnectionFactory) ctx
.lookup("jms/ConnectionFactory");
connection = cf.createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
MapMessage message = session.createMapMessage();
message.setString("UserName", userName);
message.setString("UserTweet", userMessage);
message.setLong("Timestamp", System.currentTimeMillis());
// create a blank output separator
System.out.println("");
MessageProducer messageProducer = session.createProducer(queue);
messageProducer.send(message);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(e);
e.printStackTrace();
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (JMSException e) {
// TODO Auto-generated catch block
System.out.println(e);
e.printStackTrace();
}
// The System.exit(0) code below is a workaround for a bug GlassFish
// JMS server
System.exit(0);
}
} |
b72a2959-c618-46f5-a29e-d7d131a8fc71 | public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
System.out.println(USER_PROMPT);
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String user_input_string;
user_input_string = r.readLine();
if (user_input_string != null && !user_input_string.equals("")) {
String usertweet = user_input_string.substring(
user_input_string.indexOf("->") + 2,
user_input_string.length());
String username = user_input_string.substring(0,
user_input_string.indexOf("->"));
postMessage(username, usertweet);
}
} |
a9ee576f-6edf-48ac-8929-4546d15b5504 | public void Noisemaker(){} |
2648c70d-18ee-4031-8d4e-893da5fda32b | public int [][] saltandpepper(int[][] inital, int n){
int height = inital.length;
int width = inital[0].length;
for (int i=0; i<height; i++){
for(int j=0; j<width;j++){
int random = (int) Math.floor(Math.random() * n);
if (random == 1){
if(inital[i][j]>=128){
inital[i][j]=0;
}
else{
inital[i][j]=255;
}
}
}
}
return inital;
} |
dd0f6010-58dd-48af-b650-516acf617019 | public Array() {
for(int i = 0; i < histo.length; i++) {
histo[i] = 0;
}
} |
702542f8-cfe1-4f37-8650-12e471d9e558 | public void arrayadd(int i){
histo[i]++;
} |
8f641ae9-31c4-4cb3-92bf-5daac7fd2d5a | public int getvalue(int i){
return histo[i];
} |
c362a9b7-d046-44d5-86ef-2650e2739cf3 | public void setvalue(int i,int j){
histo[i]=j;
} |
a62a18d2-9b55-45db-9423-f3b9c0b9cd4c | public void printval(int i){
System.out.print(histo[i]);
} |
b7392172-1be7-4bc7-9931-f87b85bf585c | public void printall (){
for(int i =0;i<256;i++){
System.out.println(histo[i]);
}
} |
5acac044-433c-469d-90d2-a2672314c841 | public Tuple(X x, Y y){
this.x=x;
this.y=y;
} |
95a6a773-18b7-4bb4-9f07-51c4f7651df6 | public void Algorithms(){
} |
7f23e99a-b023-447d-bce8-c69c7ffe9de0 | int operation(int a, int b); |
b6f245a9-9596-4462-a5f2-ef23ab5f62c9 | public int[][] Histoequalize (Array Histo, int[][] image){
int height = image.length;
int width = image[0].length;
int[][] newimage = new int[height][width];
Array cdfarray = calcCDF(Histo);
Array newhisto = new Array();
for (int i =0; i<256;i++){
newhisto.setvalue(i,cdfarray.getvalue(i)*255/(height*width));
}
for (int i=0;i<height;i++){
for(int j=0;j<width;j++){
newimage[i][j]=newhisto.getvalue(image[i][j]);
}
}
newhisto.printall();
return newimage;
} |
ae8dd7ad-dd5d-405f-8e7a-0b03f72e98a1 | public Array calcCDF (Array histo){
Array cdf = new Array();
cdf.setvalue(0, histo.getvalue(0));
for (int i=1;i<256;i++){
cdf.setvalue(i,histo.getvalue(i)+cdf.getvalue(i-1));
}
return cdf;
} |
a05c830a-5513-4e6f-81dc-4f170a625ed0 | public int[][] gausssmoothbad (int[][] image){
int height = image.length;
int width = image[0].length;
int[][] newimage = new int[height][width];
for (int i=2;i<width-2;i++){
for (int j = 2; j<height-2;j++){
int sumtwo = 2*(image[j-2][i-2]+image[j+2][i-2]+image[j-2][i+2]+image[j+2][i+2]);
int sumfour = 4*(image[j-2][i-1]+image[j-1][i-2]+image[j-2][i+1]+image[j-1][i+1]
+image[j-1][i+2]+image[j+1][i+2]+image[j+1][i+2]+image[j+2][i+1]+image[j+2][i-1]+image[j+1][i-2]);
int sumfive = 5*(image[j-2][i]+image[j][i+2]+image[j+2][i]+image[j][i-2]);
int sumtwelve = 12*(image[j-1][i]+image[j][i-1]+image[j+1][i]+image[j][i+1]);
int sumnine = 9*(image[j-1][i-1]+image[j-1][i+1]+image[j+1][i-1]+image[j+1][i+1]);
int sumfifteen = 15*image[j][i];
newimage[j][i]= (int) Math.floor((sumtwo+sumfour+sumfive+sumtwelve+sumnine+sumfifteen)/159);
}
}
for(int i=0;i<height;i++){
newimage[i][0] = image[i][0];
newimage[i][1] = image[i][1];
newimage[i][height-2] = image[i][height-2];
newimage[i][height-1] = image[i][height-1];
}
for(int i=0;i<width;i++){
newimage[0][i] = image[0][i];
newimage[1][i] = image[1][i];
newimage[width-2][i] = image[width-2][i];
newimage[width-1][i] = image[width-1][i];
}
return newimage;
} |
319df221-1e66-4ad5-ad49-ff4ffc2ce790 | public int[][] twodconvolution (int[][] img, int[][] kernal){
int aheight = img.length;
int awidth = img[0].length;
int bheight = kernal.length;
int bwidth = kernal[0].length;
int kcenterx = (int) Math.floor(bwidth/2);
int kcentery = (int) Math.floor(bheight/2);
for (int i=0;i<awidth;i++){
for(int j=0; j<aheight;j++){
int val = 0;
for(int k=0;k<bwidth;k++){
for (int l=0;l<bheight;l++){
if((j-(l-kcentery))>=0 && (i-(k-kcenterx))>=0){
val = val + kernal[k][j]*img[j-(l-kcentery)][i-(k-kcenterx)];
}
}
}
}
}
int[][] result = new int[aheight][awidth];
return result;
} |
84f26cfa-3f6b-4496-a0ab-aaba4c06e224 | public Object[] getImage(File string){
Array histo = new Array();
try{
BufferedImage image = ImageIO.read(string);
byte[] pixels = ((DataBufferByte)image.getRaster().getDataBuffer()).getData();
int width = image.getWidth();
int height = image.getHeight();
boolean hasAlpha = image.getAlphaRaster() != null;
int[][] result = new int[height][width];
final int pixelLength = 3;
for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel += pixelLength) {
int argb = 0;
argb += -16777216; // 255 alpha
int blue = ((int) pixels[pixel] & 0xff); // blue
int green = (((int) pixels[pixel + 1] & 0xff) << 8)>>8 ; // green
int red = (((int) pixels[pixel + 2] & 0xff) << 16)>> 16 ; // red
int newcolor = (int) Math.floor(0.216*red + 0.7152*green + 0.0722*blue);
histo.arrayadd(newcolor);
result[row][col] = newcolor;
col++;
if (col == width) {
col = 0;
row++;
}
}
return new Object[]{result,histo};
}
catch (IOException e){
e.printStackTrace();
}
return null;
} |
88dfaf2f-bf30-4b6f-aa26-50d829a65e11 | public static int[][] threetoone (int[][] result){
for(int i =0;i<result.length;i++){
for(int j=0;j<result[0].length;j++){
result[i][j]=result[i][j]& 0xff;
}
}
return result;
} |
91385728-e227-49a0-a23c-375613d6541b | public static void pixeltoimage (int[][] result,String filename) throws IOException{
int height = result.length;
int width = result[0].length;
int NUM_BANDS = 3;
int[] array1d = new int[width * height * NUM_BANDS];
result=threetoone(result);
for (int k = 0; k < width; k++){
for (int j = 0; j < height; j++) {
for (int band = 0; band < NUM_BANDS; band++)
array1d[((j * width) + k)*NUM_BANDS + band] = result[j][k];
}
}
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
WritableRaster raster = (WritableRaster) bi.getData();
raster.setPixels(0,0,width,height,array1d);
bi.setData(raster);
ImageIO.write(bi, "jpg",new File("C:\\Users\\Brandon\\workspace\\imageprocessing\\"+filename+".jpg"));
} |
7255d5fe-07f6-4339-8d18-f206aba50c0c | public static void main(String[] args) {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, "Please put SQLite JDBC driver (sqlitejdbc-v056.jar file) in same folder with this program (or add it to classpath).");
return;
}
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File file) {
if(file==null) return false;
boolean result = false;
String fileName = file.getName();
int indexOfDot = fileName.indexOf(".");
if(indexOfDot>-1) {
String extension = fileName.substring(indexOfDot);
if(".sqlite".equalsIgnoreCase(extension)) result = true;
}
return result;
}
@Override
public String getDescription() {
return "SQLite DB files";
}
});
int openDialogResult = fileChooser.showOpenDialog(null);
if(JFileChooser.APPROVE_OPTION == openDialogResult) {
File file = fileChooser.getSelectedFile();
if(file!=null && file.exists()) {
new Main().launch(file);
}
}
} |
e20606c7-7319-46d6-bec2-0b941ce4c5e5 | @Override
public boolean accept(File file) {
if(file==null) return false;
boolean result = false;
String fileName = file.getName();
int indexOfDot = fileName.indexOf(".");
if(indexOfDot>-1) {
String extension = fileName.substring(indexOfDot);
if(".sqlite".equalsIgnoreCase(extension)) result = true;
}
return result;
} |
c024be10-ba99-4742-9e3b-c8495685f29b | @Override
public String getDescription() {
return "SQLite DB files";
} |
dbef1931-e7d3-4503-82a0-d5a273490005 | private void launch(File file) {
try {
connection = SQLiteUtil.openSQLiteDBFile(file);
Map<String, Map<String, String>> dbMetaData = SQLiteUtil.listTablesFieldsWithTypes(connection);
final MainWindow mainWindow = new MainWindow(dbMetaData);
SwingUtil.resizeWindowToBestFit(mainWindow, 20);
SwingUtil.moveWindowToScreenCenter(mainWindow);
mainWindow.setVisible(true);
final Connection connectionParam = connection;
mainWindow.addDisposeListener(new Runnable() {
public void run() {
try {
connectionParam.close();
} catch(Exception e) {
e.printStackTrace();
}
}
});
mainWindow.addExportButtonListener(new ActionListener() {
public void actionPerformed(ActionEvent actEvent) {
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setMultiSelectionEnabled(false);
jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if(JFileChooser.APPROVE_OPTION == jFileChooser.showOpenDialog(mainWindow)) {
List<NodeWrapper> nodes = mainWindow.getSelectedFields();
List<String> fieldsTabelsNames = new ArrayList<String>(nodes.size());
for(NodeWrapper node : nodes) {
String fieldFromTable = node.getId()+" from "+node.getFieldTableName();
fieldsTabelsNames.add(fieldFromTable);
}
final ProgressDialog progressDialog = new ProgressDialog(mainWindow);
ExportWorker exportWorker = new ExportWorker(connection, fieldsTabelsNames, jFileChooser.getSelectedFile(),
new Runnable() {
public void run() {
progressDialog.pack();
SwingUtil.moveWindowToScreenCenter(progressDialog);
progressDialog.setVisible(true);
}
},
progressDialog.createProgressCallback(),
progressDialog.createFinishCallback()
);
progressDialog.setExportWorker(exportWorker);
new Thread(exportWorker).start();
}
}
});
} catch(Exception e) {
try {
if(connection!=null) connection.close();
} catch(Exception ccex) {}
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Exception "+e.getClass().getName()+" occurred: "+e.getMessage());
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.