id
stringlengths
36
36
text
stringlengths
1
1.25M
71666e56-c257-45f6-8131-18cb87f716b4
protected Operator() {};
40c7f9bf-1efb-4d54-bbf6-73743b81c54a
public void add(ArithmeticExpression exp){ operands.add(exp); }
f38f70a4-2a64-429b-adca-8f42abbde271
public ArithmeticExpressionIterator(ArithmeticExpression e) { this.e = e; chars = new Stack<ArithmeticExpression>(); chars.push(e); build(e); }
66775687-d1d2-4e9c-b5ee-59742e01e75b
private void build(ArithmeticExpression exp) { if (exp instanceof Operator) { Operator op = (Operator)exp; for (ArithmeticExpression ex : op.operands) { chars.push(ex); build(ex); } } }
4c6e6886-aa37-49a5-93b7-6cbf5df1070c
@Override public boolean hasNext() { return (chars.isEmpty()) ? false : true; }
673292f5-b0ba-407b-b3b5-e92e56c610ab
@Override public ArithmeticExpression next() { if (hasNext()) { ArithmeticExpression exp = chars.pop(); return exp; } else { throw new StackOverflowError(); } }
3df49b8d-5352-40a8-9a38-e99fd063528c
@Override public void remove() { throw new UnsupportedOperationException(); }
122254a6-8483-48d7-939c-1075566b188e
public Station getNearestStation(Point point);
2f5cc66a-bbc8-41c0-843b-c7a145d14f29
public TrafficRobotController(TrafficRobot robot, StationHandler stationHandler) { this.robot = robot; this.stationHandler = stationHandler; }
3a401bc5-de9f-4e60-ad99-0e9fd3a77037
public void setRunning(boolean running) { this.running = running; }
eb782b31-7e83-442f-a50f-a44e1472bba7
public void run() { logger.info("Starting thread for traffic robot " + robot.getRobotId()); running = true; try { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); Connection connection = connectionFactory.createConnection(); connection.start(); connection.setExceptionListener(this); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination points = session.createQueue(TrafficJamMessageQueues.POINTS_MESSAGE_QUEUE + robot.getRobotId()); Destination trafficInfo = session.createTopic(TrafficJamMessageQueues.TRAFFIC_INFO_MESSAGE_QUEUE); MessageConsumer consumer = session.createConsumer(points); MessageProducer producer = session.createProducer(trafficInfo); while (running) { logger.debug("Reading 10 messages"); List<PointsMessage> pointsMessages = new ArrayList<PointsMessage>(); for (int i = 1; i <= 10; i++) { Message m = consumer.receive(1); if (m != null) { if (m instanceof ObjectMessage) { ObjectMessage inMessage = (ObjectMessage) m; PointsMessage pointsMessage = (PointsMessage) inMessage.getObject(); logger.info("Received message: " + pointsMessage); pointsMessages.add(pointsMessage); } else { break; } } } for (PointsMessage pointsMessage : pointsMessages) { produceTrafficInfoMessage(session, producer, pointsMessage); } } consumer.close(); session.close(); connection.close(); } catch (Exception e) { e.printStackTrace(); } }
f9e24ee3-0c25-468b-9d98-dea4614f50b5
private void produceTrafficInfoMessage(Session session, MessageProducer producer, PointsMessage pointsMessage) throws JMSException { final Station nearestStation = stationHandler.getNearestStation(pointsMessage.getPointData().getPoint()); TrafficInfoMessage trafficInfoMessage = new TrafficInfoMessage(pointsMessage.getRobotId(), pointsMessage.getPointData().getTime(), getSpeed(), nearestStation, getTrafficCondition()); ObjectMessage outMessage = session.createObjectMessage(trafficInfoMessage); producer.send(outMessage); logger.info("Sent message: " + trafficInfoMessage); }
dcadc432-24ee-4557-8cc0-b0dfe1e1bfc9
private int getSpeed() { final Double v = Math.random() * 50; return v.intValue(); }
e1c76d5e-2117-44a4-b3e5-0959800a5ac7
private TrafficCondition getTrafficCondition() { final double v = Math.random() * 3; if (v < 1) { return TrafficCondition.LIGHT; } else { if (v < 2) { return TrafficCondition.MODERATE; } else { return TrafficCondition.HEAVY; } } }
d10da2a0-b1eb-46fb-ac84-7d61d92bafeb
public void onException(JMSException e) { System.out.println("JMS Exception occured. Shutting down client."); }
9f8b64db-9b23-4012-88c8-696f6a4a36f9
public void setRunning(boolean running) { this.running = running; }
4884ef7f-248b-4430-ab0a-180f487d6942
@Override public void run() { logger.info("Starting thread for traffic info consumer"); running = true; try { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); Connection connection = connectionFactory.createConnection(); connection.start(); connection.setExceptionListener(this); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination trafficInfo = session.createTopic(TrafficJamMessageQueues.TRAFFIC_INFO_MESSAGE_QUEUE); MessageConsumer consumer = session.createConsumer(trafficInfo); while (running) { Message m = consumer.receive(1); if (m != null) { if (m instanceof ObjectMessage) { ObjectMessage inMessage = (ObjectMessage) m; TrafficInfoMessage trafficInfoMessage = (TrafficInfoMessage) inMessage.getObject(); logger.info("Received message: " + trafficInfoMessage); } else { break; } } } consumer.close(); session.close(); connection.close(); } catch (Exception e) { e.printStackTrace(); } }
72ac8fb5-8c36-4953-9aa5-c5a060d807c3
public void onException(JMSException e) { System.out.println("JMS Exception occured. Shutting down client."); }
e419ef58-1949-4bc1-b549-8b131f1ee5e2
public static void main(String[] args) { BrokerService broker = new BrokerService(); try { broker.addConnector("tcp://localhost:61616"); broker.setBrokerName("localhost"); broker.start(); } catch (Exception e) { e.printStackTrace(); System.exit(999); } StationHandler stationHandler = new StationHandlerImpl(); DateTime currentDate = new DateTime(); DateTime stopTime = currentDate; if (currentDate.getHourOfDay() > 8 && currentDate.getMinuteOfHour() > 10) { stopTime = stopTime.plusDays(1); } stopTime = stopTime.withHourOfDay(8); stopTime = stopTime.withMinuteOfHour(10); stopTime = stopTime.withSecondOfMinute(0); logger.info(stopTime.toString()); List<TrafficRobot> robots = new ArrayList<TrafficRobot>(); final TrafficRobot robot1 = new TrafficRobot(5937); robots.add(robot1); final TrafficRobot robot2 = new TrafficRobot(6043); robots.add(robot2); PointDispatcher dispatcher = new PointDispatcher(robots); Thread dispatcherThread = new Thread(dispatcher, "dispatcher"); dispatcherThread.start(); TrafficRobotController trafficRobotController1 = new TrafficRobotController(robot1, stationHandler); Thread trafficInfoThread1 = new Thread(trafficRobotController1, "robot" + robot1.getRobotId()); trafficInfoThread1.start(); TrafficRobotController trafficRobotController2 = new TrafficRobotController(robot2, stationHandler); Thread trafficInfoThread2 = new Thread(trafficRobotController2, "robot" + robot2.getRobotId()); trafficInfoThread2.start(); // traffic info messages consumed more than once TrafficInfoConsumerImpl trafficInfoConsumer1 = new TrafficInfoConsumerImpl(); Thread trafficInfoConsumerThread1 = new Thread(trafficInfoConsumer1, "trafficConsumer1"); trafficInfoConsumerThread1.start(); TrafficInfoConsumerImpl trafficInfoConsumer2 = new TrafficInfoConsumerImpl(); Thread trafficInfoConsumerThread2 = new Thread(trafficInfoConsumer2, "trafficConsumer2"); trafficInfoConsumerThread2.start(); while (true) { if (new DateTime().isAfter(stopTime)) { trafficRobotController1.setRunning(false); trafficRobotController2.setRunning(false); trafficInfoConsumer1.setRunning(false); trafficInfoConsumer2.setRunning(false); dispatcher.setRunning(false); break; } else { try { logger.info("Waiting for 8.10"); Thread.sleep(360000); } catch (InterruptedException e) { e.printStackTrace(); } } } try { broker.stop(); } catch (Exception e) { e.printStackTrace(); } System.exit(0); }
8537c306-2cef-4c89-90bd-4126195b29b5
public StationHandlerImpl() { stations = new ArrayList<Station>(); InputStream in = this.getClass().getResourceAsStream("/tube.csv"); try { BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line = br.readLine(); while (line != null) { processLine(line); line = br.readLine(); } br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); throw new RuntimeException(e); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
754e6567-8401-4f3f-902b-04c0535b7e37
private void processLine(String line) { String[] split = line.replaceAll("\"", "").split(","); String stationName = split[0]; double latitude = new Double(split[1]); double longitude = new Double(split[2]); stations.add(new Station(stationName, latitude, longitude)); logger.debug("Adding station "+stationName); }
2e8685da-ea26-4c5b-bc4f-9a2c0e693950
@Override public synchronized Station getNearestStation(Point point) { logger.debug("getNearestStation to " + point); double minDistance = Integer.MAX_VALUE; Station minStation = null; for (Station station : stations) { double currentDistance = Point.getDistance(station.getPoint(), point); if (currentDistance < minDistance) { minDistance = currentDistance; minStation = station; } } logger.debug("Nearest Station is " + minStation); return minStation; }
d0cb7198-53c8-4708-9b4f-99ba293d0006
public PointDispatcher(List<TrafficRobot> robots) { this.robots = robots; }
faa71200-d4a5-443f-b20c-6ae591421f60
public void run() { logger.info("Starting dispatcher thread"); pointsMessages = new ArrayList<PointsMessage>(); robotQueues = new HashMap<Integer, MessageProducer>(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); try { Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); for (TrafficRobot robot : robots) { final Destination destination = session.createQueue(TrafficJamMessageQueues.POINTS_MESSAGE_QUEUE + robot.getRobotId()); MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.PERSISTENT); robotQueues.put(robot.getRobotId(), producer); } dispatchMessages(session); session.close(); } catch (JMSException e) { e.printStackTrace(); } }
94b05a4f-9189-4a7d-bc6c-517ae0c63807
public void setRunning(boolean running) { this.running = running; }
1d337b23-ed78-4512-b126-d3eb45cf60bb
private void dispatchMessages(Session session) throws JMSException { for (TrafficRobot robot : robots) { InputStream in = this.getClass().getResourceAsStream("/"+robot.getRobotId() + ".csv"); try { BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line = br.readLine(); while (line != null) { processLine(line, robot); line = br.readLine(); } br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } for (PointsMessage pointsMessage : pointsMessages) { ObjectMessage message = session.createObjectMessage(pointsMessage); robotQueues.get(pointsMessage.getRobotId()).send(message); logger.info("Sent message: " + pointsMessage); } }
af887508-3a98-4256-9613-6940b3397bb1
private void processLine(String line, TrafficRobot robot) { logger.debug("processLine " + line + "for robot " + robot.getRobotId()); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String[] split = line.replaceAll("\"", "").split(","); int driverId = new Integer(split[0]); double latitude = new Double(split[1]); double longitude = new Double(split[2]); DateTime date; try { date = new DateTime(df.parse(split[3]).getTime()); PointsMessage pointsMessage = new PointsMessage(robot.getRobotId(), new PointData(driverId, latitude, longitude, date)); pointsMessages.add(pointsMessage); } catch (ParseException e) { e.printStackTrace(); } }
4ea89388-731c-4f3e-8579-900eafb4d264
public Station(final String name, final double latitude, final double longitude) { this.name = name; this.point = new Point(latitude, longitude); }
406728e8-c667-4aad-b1c7-fdbf8d34b66d
public String getName() { return name; }
34c0714b-822b-4d6b-a804-edc45009b9d0
@Override public String toString() { return "Station{" + "name='" + name + '\'' + ", point=" + point + "} " + super.toString(); }
a6520f36-2f93-480f-a2f9-c9516b236911
public Point getPoint() { return point; }
f0902371-078d-4d29-9953-60601172a19c
public TrafficRobot(int robotId) { this.robotId = robotId; }
4c534885-7da5-4c28-8493-2075dc887462
public int getRobotId() { return robotId; }
0c069be0-6a09-490b-8f07-374ae33f827d
public Point(final double latitude, final double longitude) { this.latitude = latitude; this.longitude = longitude; }
8a344a44-5b98-483e-9e6a-ae062c3f161b
public double getLongitude() { return longitude; }
fad6c782-a09b-42a1-9dd5-dee057d8da6c
public double getLatitude() { return latitude; }
0bb6530b-7cc3-440d-910b-9298df6ab5d9
public static double getDistance(Point thisPoint, Point thatPoint) { double aDist = thisPoint.getLatitude() - thatPoint.getLatitude(); double bDist = thisPoint.getLongitude() - thatPoint.getLongitude(); return Math.sqrt((aDist * aDist) + (bDist * bDist)); }
3b7d82ca-9f2b-4a82-a14f-0441cd4e691c
@Override public String toString() { return "Point{" + "latitude=" + latitude + ", longitude=" + longitude + "} " + super.toString(); }
3839f903-ecf4-46ac-a023-d25fff34f4a7
public PointsMessage(int robotId, PointData pointData) { this.robotId = robotId; this.pointData = pointData; }
8b310672-9652-40a2-b98c-0d31151dc423
public PointData getPointData() { return pointData; }
a09d9743-2d2b-45c4-a43d-f21e366bb0b5
public int getRobotId() { return robotId; }
aead46e1-536f-44cb-b0db-cb4d2f9ff762
@Override public String toString() { return "PointsMessage{" + "robotId='" + robotId + '\'' + ", point=" + pointData + '}'; }
3ee501af-4c71-4bfb-b5ae-da8a9f810cf5
@Test public void testGetDistance() throws Exception { assertEquals(Math.sqrt(8d), Point.getDistance(new Point(1d, 1d), new Point(3d, 3d))); assertEquals(Math.sqrt(32d), Point.getDistance(new Point(-1d, -1d), new Point(3d, 3d))); assertEquals(Math.sqrt(32d), Point.getDistance(new Point(3d, 3d), new Point(-1d, -1d))); assertEquals(Math.sqrt(32d), Point.getDistance(new Point(3d, -1d), new Point(-1d, 3d))); }
70c4c7ec-fa37-4168-a1fc-31d408529065
public BundleEntityPK() { }
660c346d-3d87-4c0f-8ee5-de4f543f310d
public int getItemId() { return this.itemId; }
6b40fa36-dc74-4436-9e9c-09d96f511a4d
public void setItemId(int itemId) { this.itemId = itemId; }
c21d96ab-c219-44ee-a84a-f8a9980cba61
public java.util.Date getCheckedOutDate() { return this.checkedOutDate; }
a88f2aeb-abb3-4ad7-a296-6aeb60ef31b9
public void setCheckedOutDate(java.util.Date checkedOutDate) { this.checkedOutDate = checkedOutDate; }
1a7a0336-2946-4893-8022-57a044f721d8
public String getUsername() { return this.username; }
a248bade-7d3a-4f68-91d8-105119662f87
public void setUsername(String username) { this.username = username; }
def1aac1-5e70-4c4e-b144-2827e414d8dd
public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof BundleEntityPK)) { return false; } BundleEntityPK castOther = (BundleEntityPK)other; return (this.itemId == castOther.itemId) && this.checkedOutDate.equals(castOther.checkedOutDate) && this.username.equals(castOther.username); }
9cf04d98-3f37-4003-81a7-330910df5ab8
public int hashCode() { final int prime = 31; int hash = 17; hash = hash * prime + this.itemId; hash = hash * prime + this.checkedOutDate.hashCode(); hash = hash * prime + this.username.hashCode(); return hash; }
daee76dd-e8d3-47cd-8e63-c880bdd6960d
public UserEntity() { }
2e1fb520-eca5-4f84-a036-e15e712c72cd
public UserEntity(String username, String password, String email, String firstName, String lastName, String role){ this.username = username; //Hash the password first this.passwordHash = password; this.email = email; this.firstName = firstName; this.lastName = lastName; this.role = role; }
b6617377-3416-461f-93b5-7e70387412fe
public String getUsername() { return this.username; }
0f35506a-c925-4554-8c60-2c59ff3ddefb
public void setUsername(String username) { this.username = username; }
517f45b9-9733-489c-aec0-0530c14f82ad
public Date getCcExpiration() { return this.ccExpiration; }
1050a82c-a17d-41be-92a3-53e9782bc864
public void setCcExpiration(Date ccExpiration) { this.ccExpiration = ccExpiration; }
f8438f27-890a-4cea-89b1-d18f9f99c1d1
public String getCcName() { return this.ccName; }
52f04250-5528-4f8a-965d-bf7f31c62a52
public void setCcName(String ccName) { this.ccName = ccName; }
4e192258-0e44-4c44-886e-d287fec40092
public int getCcNumber() { return this.ccNumber; }
454bfd0b-50eb-445b-946e-b8dafc5d142b
public void setCcNumber(int ccNumber) { this.ccNumber = ccNumber; }
278629d8-cc91-4c17-b933-2a77a420313c
public int getCcSecurity() { return this.ccSecurity; }
f0b5f25d-0a81-4c65-a4cb-7672ef4dd5ea
public void setCcSecurity(int ccSecurity) { this.ccSecurity = ccSecurity; }
1029e3bc-6d11-4d8f-85a7-9e54b62396cb
public String getCity() { return this.city; }
2d06df2a-8357-40b7-b535-d2f9757c65c3
public void setCity(String city) { this.city = city; }
241386c9-20d6-4eb8-8756-9fe18a7c361e
public Date getDob() { return this.dob; }
323cf57c-5fc2-47ce-8696-3f12e982ad6b
public void setDob(Date dob) { this.dob = dob; }
0f521e3b-b222-49fa-8856-d4b31568b328
public String getEmail() { return this.email; }
bb7e0ac4-5414-4cc2-838e-8a4dc9b1c7d1
public void setEmail(String email) { this.email = email; }
1be497f7-7c0c-4410-83b2-54682bb20e41
public String getFirstName() { return this.firstName; }
905774f4-72be-4acb-a07b-3b02bf7ea60d
public void setFirstName(String firstName) { this.firstName = firstName; }
6cadb1c8-31b4-4893-a5b0-4b1665622aa6
public String getLastName() { return this.lastName; }
76a3a623-7b03-4f72-8dde-b8d7847c5a3c
public void setLastName(String lastName) { this.lastName = lastName; }
8fcc5f83-10c3-428e-9f14-7b901640e704
public String getMembershipPlan() { return this.membershipPlan; }
8cba0c52-7ca4-4061-8483-931032b4c371
public void setMembershipPlan(String membershipPlan) { this.membershipPlan = membershipPlan; }
d19f7028-12a1-46c3-8011-8efd33c0d324
public String getPasswordHash() { return this.passwordHash; }
53e3be77-83f0-439f-9a42-fe32aa5564b3
public void setPasswordHash(String password) { this.passwordHash = password; }
7b1d4de5-47b5-46b2-968f-0cd2b7dc6d6a
public String getProfileImage() { return this.profileImage; }
056f1892-d064-41ba-bcb4-f412f4ce3f5d
public void setProfileImage(String profileImage) { this.profileImage = profileImage; }
c2737737-cfe9-40ec-a052-7250726198be
public String getRole() { return this.role; }
be2d399d-abf5-4770-8814-18d11f2e3a95
public void setRole(String role) { this.role = role; }
bd759969-0d59-4800-a4a4-692286ed4549
public String getState() { return this.state; }
ca5c8ffc-fe52-49c1-8934-acdc633f9d15
public void setState(String state) { this.state = state; }
8f5ace88-93c3-46bc-b231-8fc4365444f6
public String getStreet() { return this.street; }
1fffc21a-5244-4ef6-8d6a-a4b38e13b826
public void setStreet(String street) { this.street = street; }
8a158f9c-2ffa-4225-bf2a-83be7ded9918
public String getStreetOpt() { return this.streetOpt; }
ea1f4688-a281-4729-b23a-0af15d131dab
public void setStreetOpt(String streetOpt) { this.streetOpt = streetOpt; }
a513ed9d-045a-4fe4-8772-c4ac89142b8d
public int getZipcode() { return this.zipcode; }
686d666e-7eac-4982-93ff-7a9f6f3e9e23
public void setZipcode(int zipcode) { this.zipcode = zipcode; }
9b12d2f5-3ff4-4fcd-90ed-4bf80eddd0fe
public Set<BundleEntity> getBundleEntities() { return this.bundleEntities; }
ada68be3-8294-4784-9500-842dcc6d0c1b
public void setBundleEntities(Set<BundleEntity> bundleEntities) { this.bundleEntities = bundleEntities; }
1330b060-d41b-4701-9911-bf919530a03c
public ItemEntity() { }
882aa6a7-f1f5-45bf-b744-8a5cdc557cf1
public ItemEntity(int itemId, String title, int releaseYear, String type, String platform, String genre, boolean isOut, int userRating, String esrbRating, int referenceNumber, String director, String trailerUrl, String synopsis, String imageUrl, String developer, String mpaaRating) { this.itemId = itemId; this.title = title; this.releaseYear = releaseYear; this.type = type; this.platform = platform; this.genre = genre; this.isOut = isOut; this.userRating = userRating; this.esrbRating = esrbRating; this.referenceNumber = referenceNumber; this.director = director; this.trailerUrl = trailerUrl; this.synopsis = synopsis; this.imageUrl = imageUrl; this.developer = developer; this.mpaaRating = mpaaRating; }
483989ea-ced2-4121-98da-7899175a5e86
public int getItemId() { return this.itemId; }
6ed3050d-6375-4135-99cb-1ffb9ec37f20
public void setItemId(int itemId) { this.itemId = itemId; }
d289981a-db24-444d-85b1-d979cc4e71b2
public String getDeveloper() { return this.developer; }
0774809f-db40-4cc5-9a32-bbabc30a70c8
public void setDeveloper(String developer) { this.developer = developer; }
01a6a403-5dcc-4296-a064-8c5ad2990f9f
public String getDirector() { return this.director; }
ca45b471-0515-416c-a335-d14eee2634fc
public void setDirector(String director) { this.director = director; }