@Test public void userDefinedMapTypeShouldBePopulated() throws Exception { CustomMap customMap = enhancedRandom.nextObject(CustomMap.class); assertThat(customMap).isNotNull(); assertThat(customMap.getName()).isNotNull(); }
/** * Reproduce method that generates a new <code>Chrome</code> object from the two given ones. * * @param x First <code>Chrome</code> object * @param y Second <code>Chrome</code> object * @return The <code>Chrome</code> object which was created from <code>x</code> and <code>y</code> */ public Chrome reproduce(Chrome x, Chrome y) { Random r = new Random(); CustomMap childGenes = new CustomMap(); // Randomly choose the intersection point int intersectionPoint = r.nextInt(x.getSize()); for (int i = 0; i < intersectionPoint; i++) { childGenes.addKey(x.getMapKey(i)); childGenes.addValue(x.getMapValue(i)); } for (int i = intersectionPoint; i < x.getSize(); i++) { childGenes.addKey(y.getMapKey(i)); childGenes.addValue(y.getMapValue(i)); } return new Chrome(childGenes, mRooms, mInstructors, mSlots); }
@Override public CustomMap deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { CustomMap result = new CustomMap(); result.put("x", jp.getText()); return result; }
/** Simple test to ensure that @JsonDeserialize.using is recognized */ public void testMapWithDeserializer() throws IOException { ObjectMapper mapper = new ObjectMapper(); CustomMap result = mapper.readValue(quote("xyz"), CustomMap.class); assertEquals(1, result.size()); assertEquals("xyz", result.get("x")); }
LargeMap(Rover r, LandingModule m, Position centre, int zoomLevel) { super(); setTitle("Map"); setSize(500, 500); SpringLayout springLayout = new SpringLayout(); this.getContentPane().setLayout(springLayout); JButton btnGoto = new JButton("Go To"); module = m; btnGoto.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { GoToDialog dialog = new GoToDialog(null); GoToDialogResult result = dialog.show(map_2.getPosition().getLat(), map_2.getPosition().getLon()); if (result.success) { switch (result.selectedOption) { case GOTO_ROVER: map_2.setDisplayPositionByLatLon( rover.currentPosition.getLat(), rover.currentPosition.getLon(), map_2.getZoom()); break; case GOTO_MODULE: map_2.setDisplayPositionByLatLon( module.currentPosition.getLat(), module.currentPosition.getLon(), map_2.getZoom()); break; case GOTO_LATLONG: map_2.setDisplayPositionByLatLon( result.enteredPosition.getLat(), result.enteredPosition.getLon(), map_2.getZoom()); break; } } } }); map_2 = new CustomMap(r); lblPosition = new JLabel(""); map_2.setDisplayPositionByLatLon(centre.getLat(), centre.getLon(), zoomLevel); map_2.addMouseMotionListener( new MouseMotionListener() { @Override public void mouseMoved(MouseEvent arg0) { int xCoord = arg0.getX(); int yCoord = arg0.getY(); lastMousePosition = new Position(map_2.getPosition(xCoord, yCoord)); if (relativeDatumPoint == null) { lblPosition.setText( String.format( "Lat: %.5f, Long: %.5f", lastMousePosition.getLat(), lastMousePosition.getLon())); } else { lblPosition.setText( String.format( "Lat: %.5f, Long: %.5f, Rel: %.1fm, %.1f", lastMousePosition.getLat(), lastMousePosition.getLon(), relativeDatumPoint.getDistanceTo(lastMousePosition), relativeDatumPoint.getBearingTo(lastMousePosition))); } } @Override public void mouseDragged(MouseEvent arg0) { // Not used } }); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addKeyEventDispatcher( new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_S) { if (lastMousePosition != null) { relativeDatumPoint = lastMousePosition; lblPosition.setText( String.format( "Lat: %.5f, Long: %.5f, Rel: %.1fm, %.1f", lastMousePosition.getLat(), lastMousePosition.getLon(), relativeDatumPoint.getDistanceTo(lastMousePosition), relativeDatumPoint.getBearingTo(lastMousePosition))); } } return true; } }); springLayout.putConstraint( SpringLayout.NORTH, btnGoto, 10, SpringLayout.NORTH, this.getContentPane()); springLayout.putConstraint( SpringLayout.WEST, btnGoto, 10, SpringLayout.WEST, this.getContentPane()); getContentPane().add(btnGoto); springLayout.putConstraint(SpringLayout.NORTH, lblPosition, 0, SpringLayout.NORTH, btnGoto); springLayout.putConstraint(SpringLayout.WEST, lblPosition, 5, SpringLayout.EAST, btnGoto); getContentPane().add(lblPosition); springLayout.putConstraint(SpringLayout.NORTH, map_2, 10, SpringLayout.SOUTH, btnGoto); springLayout.putConstraint( SpringLayout.WEST, map_2, 0, SpringLayout.WEST, this.getContentPane()); springLayout.putConstraint( SpringLayout.EAST, map_2, 0, SpringLayout.EAST, this.getContentPane()); springLayout.putConstraint( SpringLayout.SOUTH, map_2, 0, SpringLayout.SOUTH, this.getContentPane()); getContentPane().add(map_2); setVisible(true); this.rover = r; module.attachListener(map_2); rover.attachListener(map_2); }