repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l5/PDMDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.io.IOException; import java.util.List; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JSlider; import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.animation.animator.DoubleArrayValueAnimator; import org.openimaj.content.animation.animator.RandomLinearDoubleValueAnimator; import org.openimaj.content.animation.animator.ValueAnimator; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.asm.datasets.AMToolsSampleDataset; import org.openimaj.image.model.asm.datasets.ShapeModelDataset; import org.openimaj.math.geometry.line.Line2d; import org.openimaj.math.geometry.point.Point2d; import org.openimaj.math.geometry.point.PointList; import org.openimaj.math.geometry.point.PointListConnections; import org.openimaj.math.geometry.shape.PointDistributionModel; import org.openimaj.math.geometry.transforms.TransformUtilities; import org.openimaj.video.AnimatedVideo; import org.openimaj.video.VideoDisplay; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
} }); p.add(new JLabel("animate:")); p.add(cb); final JSeparator vh = new JSeparator(SwingConstants.HORIZONTAL); sliderPanel.add(vh); sliderPanel.add(p); final JSeparator vs = new JSeparator(SwingConstants.VERTICAL); base.add(vs); base.add(sliderPanel); return base; } public static DoubleArrayValueAnimator makeAnimator(int duration, double[] maxs, double[] initial) { final RandomLinearDoubleValueAnimator[] animators = new RandomLinearDoubleValueAnimator[maxs.length]; for (int i = 0; i < maxs.length; i++) animators[i] = new RandomLinearDoubleValueAnimator((-maxs[i]), maxs[i], duration, initial[i]); return new DoubleArrayValueAnimator(animators); } @Override public void close() { display.close(); } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l5/PDMDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.io.IOException; import java.util.List; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JSlider; import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.animation.animator.DoubleArrayValueAnimator; import org.openimaj.content.animation.animator.RandomLinearDoubleValueAnimator; import org.openimaj.content.animation.animator.ValueAnimator; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.asm.datasets.AMToolsSampleDataset; import org.openimaj.image.model.asm.datasets.ShapeModelDataset; import org.openimaj.math.geometry.line.Line2d; import org.openimaj.math.geometry.point.Point2d; import org.openimaj.math.geometry.point.PointList; import org.openimaj.math.geometry.point.PointListConnections; import org.openimaj.math.geometry.shape.PointDistributionModel; import org.openimaj.math.geometry.transforms.TransformUtilities; import org.openimaj.video.AnimatedVideo; import org.openimaj.video.VideoDisplay; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; } }); p.add(new JLabel("animate:")); p.add(cb); final JSeparator vh = new JSeparator(SwingConstants.HORIZONTAL); sliderPanel.add(vh); sliderPanel.add(p); final JSeparator vs = new JSeparator(SwingConstants.VERTICAL); base.add(vs); base.add(sliderPanel); return base; } public static DoubleArrayValueAnimator makeAnimator(int duration, double[] maxs, double[] initial) { final RandomLinearDoubleValueAnimator[] animators = new RandomLinearDoubleValueAnimator[maxs.length]; for (int i = 0; i < maxs.length; i++) animators[i] = new RandomLinearDoubleValueAnimator((-maxs[i]), maxs[i], duration, initial[i]); return new DoubleArrayValueAnimator(animators); } @Override public void close() { display.close(); } public static void main(String[] args) throws IOException {
new SlideshowApplication(new PDMDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/MainMenu.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; import javax.swing.BoxLayout; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.JTabbedPane; import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import org.openimaj.util.processes.JavaProcess; import org.openimaj.util.processes.ProcessException; import org.reflections.Reflections; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture;
*/ public MainMenu() { final List<LectureObject> lectures = getLectures(); this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); tabs = new JTabbedPane(); final List<JButton> runBtns = new ArrayList<JButton>(); for (final LectureObject l : lectures) { final Component lp = createLecturePanel(l, runBtns); tabs.addTab(l.lecture.title(), lp); } tabs.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { final int idx = tabs.getSelectedIndex(); final JRootPane root = MainMenu.this.getRootPane(); if (root != null && idx >= 0) root.setDefaultButton(runBtns.get(idx)); } }); add(tabs); final JPanel info = new JPanel(new GridLayout(0, 1)); info.setPreferredSize(new Dimension(800, 30)); info.setSize(info.getPreferredSize()); info.setMaximumSize(info.getPreferredSize());
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/MainMenu.java import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; import javax.swing.BoxLayout; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.JTabbedPane; import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import org.openimaj.util.processes.JavaProcess; import org.openimaj.util.processes.ProcessException; import org.reflections.Reflections; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture; */ public MainMenu() { final List<LectureObject> lectures = getLectures(); this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); tabs = new JTabbedPane(); final List<JButton> runBtns = new ArrayList<JButton>(); for (final LectureObject l : lectures) { final Component lp = createLecturePanel(l, runBtns); tabs.addTab(l.lecture.title(), lp); } tabs.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { final int idx = tabs.getSelectedIndex(); final JRootPane root = MainMenu.this.getRootPane(); if (root != null && idx >= 0) root.setDefaultButton(runBtns.get(idx)); } }); add(tabs); final JPanel info = new JPanel(new GridLayout(0, 1)); info.setPreferredSize(new Dimension(800, 30)); info.setSize(info.getPreferredSize()); info.setMaximumSize(info.getPreferredSize());
final JLabel link = Utils.linkify("http://comp3204.ecs.soton.ac.uk", "http://comp3204.ecs.soton.ac.uk",
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l8/Lecture8.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture;
package uk.ac.soton.ecs.comp3204.l8; @Lecture(title = "L8: Consistent matching", handoutsURL = "http://jonhare.github.io/COMP3204/handouts/pdf/L8-consistency.pdf", slidesURL = "http://jonhare.github.io/COMP3204/lectures/pdf/L8-consistency.pdf") @JvmArgs(vmArguments = "-Xmx1G") public class Lecture8 { public static void main(String[] args) throws IOException { final List<Slide> slides = new ArrayList<Slide>(); for (int i = 1; i <= 33; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i)))); slides.add(new LineRANSACDemo()); for (int i = 34; i <= 36; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i)))); slides.add(new SIFTMatchingDemo()); for (int i = 37; i <= 38; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i)))); slides.add(new SFMDemo()); for (int i = 39; i <= 40; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i)))); slides.add(new SpectrogramDemo()); for (int i = 41; i <= 57; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i))));
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l8/Lecture8.java import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture; package uk.ac.soton.ecs.comp3204.l8; @Lecture(title = "L8: Consistent matching", handoutsURL = "http://jonhare.github.io/COMP3204/handouts/pdf/L8-consistency.pdf", slidesURL = "http://jonhare.github.io/COMP3204/lectures/pdf/L8-consistency.pdf") @JvmArgs(vmArguments = "-Xmx1G") public class Lecture8 { public static void main(String[] args) throws IOException { final List<Slide> slides = new ArrayList<Slide>(); for (int i = 1; i <= 33; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i)))); slides.add(new LineRANSACDemo()); for (int i = 34; i <= 36; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i)))); slides.add(new SIFTMatchingDemo()); for (int i = 37; i <= 38; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i)))); slides.add(new SFMDemo()); for (int i = 39; i <= 40; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i)))); slides.add(new SpectrogramDemo()); for (int i = 41; i <= 57; i++) slides.add(new PictureSlide(Lecture8.class.getResource(String.format("l8.%03d.jpg", i))));
new SlideshowApplication(slides, 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l5/PDMDatasetDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.RGBColour; import org.openimaj.image.model.asm.datasets.AMToolsSampleDataset; import org.openimaj.image.model.asm.datasets.ShapeModelDataset; import org.openimaj.image.processing.resize.ResizeProcessor; import org.openimaj.math.geometry.line.Line2d; import org.openimaj.math.geometry.point.PointList; import org.openimaj.util.pair.IndependentPair; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
inner.setPreferredSize(new Dimension(imWidth * 5, height - 3)); inner.setLayout(new GridLayout(0, 5)); final ShapeModelDataset<MBFImage> dataset = AMToolsSampleDataset.load(ImageUtilities.MBFIMAGE_READER); final ResizeProcessor rp = new ResizeProcessor(imWidth); for (final IndependentPair<PointList, MBFImage> p : dataset) { final MBFImage image = p.getSecondObject(); image.drawPoints(p.getFirstObject(), RGBColour.WHITE, 10); for (final Line2d line : p.getFirstObject().getLines(dataset.getConnections())) { image.drawLine(line, 5, RGBColour.WHITE); } image.processInplace(rp); final ImageComponent ic = new ImageComponent(); ic.setShowPixelColours(false); ic.setShowXYPosition(false); ic.setImage(ImageUtilities.createBufferedImageForDisplay(image)); inner.add(ic); } base.add(inner); return base; } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l5/PDMDatasetDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.RGBColour; import org.openimaj.image.model.asm.datasets.AMToolsSampleDataset; import org.openimaj.image.model.asm.datasets.ShapeModelDataset; import org.openimaj.image.processing.resize.ResizeProcessor; import org.openimaj.math.geometry.line.Line2d; import org.openimaj.math.geometry.point.PointList; import org.openimaj.util.pair.IndependentPair; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; inner.setPreferredSize(new Dimension(imWidth * 5, height - 3)); inner.setLayout(new GridLayout(0, 5)); final ShapeModelDataset<MBFImage> dataset = AMToolsSampleDataset.load(ImageUtilities.MBFIMAGE_READER); final ResizeProcessor rp = new ResizeProcessor(imWidth); for (final IndependentPair<PointList, MBFImage> p : dataset) { final MBFImage image = p.getSecondObject(); image.drawPoints(p.getFirstObject(), RGBColour.WHITE, 10); for (final Line2d line : p.getFirstObject().getLines(dataset.getConnections())) { image.drawLine(line, 5, RGBColour.WHITE); } image.processInplace(rp); final ImageComponent ic = new ImageComponent(); ic.setShowPixelColours(false); ic.setShowXYPosition(false); ic.setImage(ImageUtilities.createBufferedImageForDisplay(image)); inner.add(ic); } base.add(inner); return base; } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
new SlideshowApplication(new PDMDatasetDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l11/Lecture11.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.content.slideshow.VideoSlide; import org.openimaj.video.VideoDisplay.EndAction; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture;
package uk.ac.soton.ecs.comp3204.l11; @Lecture(title = "L11: Towards 3D vision", slidesURL = "http://jonhare.github.io/COMP3204/lectures/pdf/L11-towards3d.pdf", handoutsURL = "") @JvmArgs(vmArguments = "-Xmx1G") public class Lecture11 { public static void main(String[] args) throws IOException { final List<Slide> slides = new ArrayList<Slide>(); for (int i = 1; i <= 19; i++) slides.add(new PictureSlide(Lecture11.class.getResource(String.format("l11.%03d.jpg", i)))); slides.add(new CalibrationDemo()); for (int i = 20; i <= 28; i++) slides.add(new PictureSlide(Lecture11.class.getResource(String.format("l11.%03d.jpg", i))));
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l11/Lecture11.java import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.content.slideshow.VideoSlide; import org.openimaj.video.VideoDisplay.EndAction; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture; package uk.ac.soton.ecs.comp3204.l11; @Lecture(title = "L11: Towards 3D vision", slidesURL = "http://jonhare.github.io/COMP3204/lectures/pdf/L11-towards3d.pdf", handoutsURL = "") @JvmArgs(vmArguments = "-Xmx1G") public class Lecture11 { public static void main(String[] args) throws IOException { final List<Slide> slides = new ArrayList<Slide>(); for (int i = 1; i <= 19; i++) slides.add(new PictureSlide(Lecture11.class.getResource(String.format("l11.%03d.jpg", i)))); slides.add(new CalibrationDemo()); for (int i = 20; i <= 28; i++) slides.add(new PictureSlide(Lecture11.class.getResource(String.format("l11.%03d.jpg", i))));
slides.add(new VideoSlide(Lecture11.class.getResource("sanmarco.avi"), Utils.BACKGROUND_IMAGE_URL,
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l3/EigenFaceApproximationDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FaceDatasetDemo.java // public static class FaceDatasetProvider { // static File tmpFile; // static { // try { // tmpFile = File.createTempFile("faces", ".zip"); // FileUtils.copyURLToFile(FaceDatasetDemo.class.getResource("att_faces.zip"), tmpFile); // tmpFile.deleteOnExit(); // } catch (final Exception e) { // e.printStackTrace(); // } // } // // public static VFSGroupDataset<FImage> getDataset() throws FileSystemException { // return new VFSGroupDataset<FImage>("zip:" + tmpFile.toURI(), ImageUtilities.FIMAGE_READER); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.io.InputStream; import javax.swing.BoxLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.data.dataset.VFSGroupDataset; import org.openimaj.experiment.dataset.util.DatasetAdaptors; import org.openimaj.feature.DoubleFV; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.EigenImages; import org.openimaj.io.IOUtils; import uk.ac.soton.ecs.comp3204.l3.FaceDatasetDemo.FaceDatasetProvider; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
package uk.ac.soton.ecs.comp3204.l3; /** * Demonstrate the effect of low-dimensional approximation. * * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) * */ @Demonstration(title = "Eigenface approximation demo ") public class EigenFaceApproximationDemo implements Slide { private static final int NUM_IMAGES = 30; private static final Font FONT = Font.decode("Monaco-28"); private EigenImages eigen; private FImage[] faces = new FImage[NUM_IMAGES]; private FImage[] images = new FImage[NUM_IMAGES]; private BufferedImage[] bimages = new BufferedImage[NUM_IMAGES]; private ImageComponent[] components = new ImageComponent[NUM_IMAGES]; @Override public Component getComponent(int width, int height) throws IOException { // select random faces
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FaceDatasetDemo.java // public static class FaceDatasetProvider { // static File tmpFile; // static { // try { // tmpFile = File.createTempFile("faces", ".zip"); // FileUtils.copyURLToFile(FaceDatasetDemo.class.getResource("att_faces.zip"), tmpFile); // tmpFile.deleteOnExit(); // } catch (final Exception e) { // e.printStackTrace(); // } // } // // public static VFSGroupDataset<FImage> getDataset() throws FileSystemException { // return new VFSGroupDataset<FImage>("zip:" + tmpFile.toURI(), ImageUtilities.FIMAGE_READER); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/EigenFaceApproximationDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.io.InputStream; import javax.swing.BoxLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.data.dataset.VFSGroupDataset; import org.openimaj.experiment.dataset.util.DatasetAdaptors; import org.openimaj.feature.DoubleFV; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.EigenImages; import org.openimaj.io.IOUtils; import uk.ac.soton.ecs.comp3204.l3.FaceDatasetDemo.FaceDatasetProvider; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; package uk.ac.soton.ecs.comp3204.l3; /** * Demonstrate the effect of low-dimensional approximation. * * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) * */ @Demonstration(title = "Eigenface approximation demo ") public class EigenFaceApproximationDemo implements Slide { private static final int NUM_IMAGES = 30; private static final Font FONT = Font.decode("Monaco-28"); private EigenImages eigen; private FImage[] faces = new FImage[NUM_IMAGES]; private FImage[] images = new FImage[NUM_IMAGES]; private BufferedImage[] bimages = new BufferedImage[NUM_IMAGES]; private ImageComponent[] components = new ImageComponent[NUM_IMAGES]; @Override public Component getComponent(int width, int height) throws IOException { // select random faces
final VFSGroupDataset<FImage> dataset = FaceDatasetProvider.getDataset();
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l3/EigenFaceApproximationDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FaceDatasetDemo.java // public static class FaceDatasetProvider { // static File tmpFile; // static { // try { // tmpFile = File.createTempFile("faces", ".zip"); // FileUtils.copyURLToFile(FaceDatasetDemo.class.getResource("att_faces.zip"), tmpFile); // tmpFile.deleteOnExit(); // } catch (final Exception e) { // e.printStackTrace(); // } // } // // public static VFSGroupDataset<FImage> getDataset() throws FileSystemException { // return new VFSGroupDataset<FImage>("zip:" + tmpFile.toURI(), ImageUtilities.FIMAGE_READER); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.io.InputStream; import javax.swing.BoxLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.data.dataset.VFSGroupDataset; import org.openimaj.experiment.dataset.util.DatasetAdaptors; import org.openimaj.feature.DoubleFV; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.EigenImages; import org.openimaj.io.IOUtils; import uk.ac.soton.ecs.comp3204.l3.FaceDatasetDemo.FaceDatasetProvider; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
images[i].drawImage(faces[i], 0, 0); images[i].drawImage(recon, faces[i].width, 0); } } private void update() { for (int i = 0; i < components.length; i++) { components[i].setImage(bimages[i] = ImageUtilities.createBufferedImageForDisplay(images[i], bimages[i])); } } private void createImageComponents(JPanel base) { for (int i = 0; i < components.length; i++) { final ImageComponent ic = new ImageComponent(true, false); ic.setAllowPanning(false); ic.setAllowZoom(false); ic.setShowPixelColours(false); ic.setShowXYPosition(false); ic.setImage(bimages[i] = ImageUtilities.createBufferedImageForDisplay(images[i], bimages[i])); base.add(ic); components[i] = ic; } } @Override public void close() { // do nothing } public static void main(String[] args) throws Exception {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FaceDatasetDemo.java // public static class FaceDatasetProvider { // static File tmpFile; // static { // try { // tmpFile = File.createTempFile("faces", ".zip"); // FileUtils.copyURLToFile(FaceDatasetDemo.class.getResource("att_faces.zip"), tmpFile); // tmpFile.deleteOnExit(); // } catch (final Exception e) { // e.printStackTrace(); // } // } // // public static VFSGroupDataset<FImage> getDataset() throws FileSystemException { // return new VFSGroupDataset<FImage>("zip:" + tmpFile.toURI(), ImageUtilities.FIMAGE_READER); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/EigenFaceApproximationDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.io.InputStream; import javax.swing.BoxLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.data.dataset.VFSGroupDataset; import org.openimaj.experiment.dataset.util.DatasetAdaptors; import org.openimaj.feature.DoubleFV; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.EigenImages; import org.openimaj.io.IOUtils; import uk.ac.soton.ecs.comp3204.l3.FaceDatasetDemo.FaceDatasetProvider; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; images[i].drawImage(faces[i], 0, 0); images[i].drawImage(recon, faces[i].width, 0); } } private void update() { for (int i = 0; i < components.length; i++) { components[i].setImage(bimages[i] = ImageUtilities.createBufferedImageForDisplay(images[i], bimages[i])); } } private void createImageComponents(JPanel base) { for (int i = 0; i < components.length; i++) { final ImageComponent ic = new ImageComponent(true, false); ic.setAllowPanning(false); ic.setAllowZoom(false); ic.setShowPixelColours(false); ic.setShowXYPosition(false); ic.setImage(bimages[i] = ImageUtilities.createBufferedImageForDisplay(images[i], bimages[i])); base.add(ic); components[i] = ic; } } @Override public void close() { // do nothing } public static void main(String[] args) throws Exception {
new SlideshowApplication(new EigenFaceApproximationDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l6/StickyFeaturesDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l1/SimpleCameraDemo.java // @Demonstration(title = "Simple Camera Demo") // public class SimpleCameraDemo implements Slide { // protected VideoCaptureComponent vc; // // @Override // public JPanel getComponent(int width, int height) throws IOException { // // the main panel // final JPanel base = new JPanel(); // base.setOpaque(false); // base.setPreferredSize(new Dimension(width, height)); // base.setLayout(new GridBagLayout()); // vc = new VideoCaptureComponent(640, 480); // base.add(vc); // // return base; // } // // @Override // public void close() { // vc.close(); // } // // public static void main(String[] args) throws IOException { // new SlideshowApplication(new SimpleCameraDemo(), 1024, 768, Utils.BACKGROUND_IMAGE); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.FImage; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.RGBColour; import org.openimaj.video.VideoDisplay; import org.openimaj.video.VideoDisplayListener; import org.openimaj.video.tracking.klt.Feature; import org.openimaj.video.tracking.klt.FeatureList; import org.openimaj.video.tracking.klt.KLTTracker; import org.openimaj.video.tracking.klt.TrackingContext; import uk.ac.soton.ecs.comp3204.l1.SimpleCameraDemo; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
public JPanel getComponent(int width, int height) throws IOException { final JPanel f = super.getComponent(width, height); this.vc.getDisplay().addVideoListener(this); return f; } @Override public void afterUpdate(VideoDisplay<MBFImage> display) { // do nothing } @Override public void beforeUpdate(MBFImage frame) { final FImage currentFrame = frame.flatten(); if (firstframe) { tracker.selectGoodFeatures(currentFrame); firstframe = false; } else { tracker.trackFeatures(prevFrame, currentFrame); tracker.replaceLostFeatures(currentFrame); } this.prevFrame = currentFrame.clone(); for (final Feature f : tracker.getFeatureList()) { if (f.val >= 0) { frame.drawPoint(f, RGBColour.GREEN, 5); } } } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l1/SimpleCameraDemo.java // @Demonstration(title = "Simple Camera Demo") // public class SimpleCameraDemo implements Slide { // protected VideoCaptureComponent vc; // // @Override // public JPanel getComponent(int width, int height) throws IOException { // // the main panel // final JPanel base = new JPanel(); // base.setOpaque(false); // base.setPreferredSize(new Dimension(width, height)); // base.setLayout(new GridBagLayout()); // vc = new VideoCaptureComponent(640, 480); // base.add(vc); // // return base; // } // // @Override // public void close() { // vc.close(); // } // // public static void main(String[] args) throws IOException { // new SlideshowApplication(new SimpleCameraDemo(), 1024, 768, Utils.BACKGROUND_IMAGE); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l6/StickyFeaturesDemo.java import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.FImage; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.RGBColour; import org.openimaj.video.VideoDisplay; import org.openimaj.video.VideoDisplayListener; import org.openimaj.video.tracking.klt.Feature; import org.openimaj.video.tracking.klt.FeatureList; import org.openimaj.video.tracking.klt.KLTTracker; import org.openimaj.video.tracking.klt.TrackingContext; import uk.ac.soton.ecs.comp3204.l1.SimpleCameraDemo; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; public JPanel getComponent(int width, int height) throws IOException { final JPanel f = super.getComponent(width, height); this.vc.getDisplay().addVideoListener(this); return f; } @Override public void afterUpdate(VideoDisplay<MBFImage> display) { // do nothing } @Override public void beforeUpdate(MBFImage frame) { final FImage currentFrame = frame.flatten(); if (firstframe) { tracker.selectGoodFeatures(currentFrame); firstframe = false; } else { tracker.trackFeatures(prevFrame, currentFrame); tracker.replaceLostFeatures(currentFrame); } this.prevFrame = currentFrame.clone(); for (final Feature f : tracker.getFeatureList()) { if (f.val >= 0) { frame.drawPoint(f, RGBColour.GREEN, 5); } } } public static void main(String[] args) throws IOException {
new SlideshowApplication(new StickyFeaturesDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l6/HarrisResponseDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l1/SimpleCameraDemo.java // @Demonstration(title = "Simple Camera Demo") // public class SimpleCameraDemo implements Slide { // protected VideoCaptureComponent vc; // // @Override // public JPanel getComponent(int width, int height) throws IOException { // // the main panel // final JPanel base = new JPanel(); // base.setOpaque(false); // base.setPreferredSize(new Dimension(width, height)); // base.setLayout(new GridBagLayout()); // vc = new VideoCaptureComponent(640, 480); // base.add(vc); // // return base; // } // // @Override // public void close() { // vc.close(); // } // // public static void main(String[] args) throws IOException { // new SlideshowApplication(new SimpleCameraDemo(), 1024, 768, Utils.BACKGROUND_IMAGE); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.io.IOException; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.ColourMap; import org.openimaj.image.feature.local.interest.HarrisIPD; import org.openimaj.video.VideoDisplay; import org.openimaj.video.VideoDisplayListener; import uk.ac.soton.ecs.comp3204.l1.SimpleCameraDemo; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
final GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy = 1; c.add(controls, gbc); return c; } @Override public void afterUpdate(VideoDisplay<MBFImage> display) { // do nothing } @Override public void beforeUpdate(MBFImage frame) { harris.setDetectionScale(0); harris.setImageBlurred(true); harris.setIntegrationScale(computeScale()); harris.findInterestPoints(frame.flatten()); frame.internalAssign(ColourMap.Jet.apply(harris.createInterestPointMap().normalise())); } private float computeScale() { final int size = (Integer) windowSizeSpinner.getValue(); return (size - 1f) / 8f; } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l1/SimpleCameraDemo.java // @Demonstration(title = "Simple Camera Demo") // public class SimpleCameraDemo implements Slide { // protected VideoCaptureComponent vc; // // @Override // public JPanel getComponent(int width, int height) throws IOException { // // the main panel // final JPanel base = new JPanel(); // base.setOpaque(false); // base.setPreferredSize(new Dimension(width, height)); // base.setLayout(new GridBagLayout()); // vc = new VideoCaptureComponent(640, 480); // base.add(vc); // // return base; // } // // @Override // public void close() { // vc.close(); // } // // public static void main(String[] args) throws IOException { // new SlideshowApplication(new SimpleCameraDemo(), 1024, 768, Utils.BACKGROUND_IMAGE); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l6/HarrisResponseDemo.java import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.io.IOException; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.ColourMap; import org.openimaj.image.feature.local.interest.HarrisIPD; import org.openimaj.video.VideoDisplay; import org.openimaj.video.VideoDisplayListener; import uk.ac.soton.ecs.comp3204.l1.SimpleCameraDemo; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; final GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy = 1; c.add(controls, gbc); return c; } @Override public void afterUpdate(VideoDisplay<MBFImage> display) { // do nothing } @Override public void beforeUpdate(MBFImage frame) { harris.setDetectionScale(0); harris.setImageBlurred(true); harris.setIntegrationScale(computeScale()); harris.findInterestPoints(frame.flatten()); frame.internalAssign(ColourMap.Jet.apply(harris.createInterestPointMap().normalise())); } private float computeScale() { final int size = (Integer) windowSizeSpinner.getValue(); return (size - 1f) / 8f; } public static void main(String[] args) throws IOException {
new SlideshowApplication(new HarrisResponseDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l3/CovarianceDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.Random; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JSlider; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.ColourSpace; import org.openimaj.image.colour.RGBColour; import org.openimaj.image.renderer.RenderHints; import org.openimaj.math.geometry.point.Point2dImpl; import org.openimaj.math.geometry.shape.Ellipse; import org.openimaj.math.geometry.shape.EllipseUtilities; import org.openimaj.math.geometry.transforms.TransformUtilities; import org.openimaj.math.statistics.distribution.CachingMultivariateGaussian; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; import Jama.Matrix;
if (drawEllipse) image.createRenderer(RenderHints.ANTI_ALIASED).drawShape(e, 3, RGBColour.RED); } this.imageComp.setImage(bimg = ImageUtilities.createBufferedImageForDisplay(image, bimg)); } protected void setYY() { covariance.set(1, 1, yySlider.getValue() / 100d); updateImage(); } protected void setXY() { covariance.set(1, 0, xySlider.getValue() / 100d); covariance.set(0, 1, xySlider.getValue() / 100d); updateImage(); } protected void setXX() { covariance.set(0, 0, xxSlider.getValue() / 100d); updateImage(); } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/CovarianceDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.Random; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JSlider; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.ColourSpace; import org.openimaj.image.colour.RGBColour; import org.openimaj.image.renderer.RenderHints; import org.openimaj.math.geometry.point.Point2dImpl; import org.openimaj.math.geometry.shape.Ellipse; import org.openimaj.math.geometry.shape.EllipseUtilities; import org.openimaj.math.geometry.transforms.TransformUtilities; import org.openimaj.math.statistics.distribution.CachingMultivariateGaussian; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; import Jama.Matrix; if (drawEllipse) image.createRenderer(RenderHints.ANTI_ALIASED).drawShape(e, 3, RGBColour.RED); } this.imageComp.setImage(bimg = ImageUtilities.createBufferedImageForDisplay(image, bimg)); } protected void setYY() { covariance.set(1, 1, yySlider.getValue() / 100d); updateImage(); } protected void setXY() { covariance.set(1, 0, xySlider.getValue() / 100d); covariance.set(0, 1, xySlider.getValue() / 100d); updateImage(); } protected void setXX() { covariance.set(0, 0, xxSlider.getValue() / 100d); updateImage(); } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
new SlideshowApplication(new CovarianceDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l4/FHSegmentationDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.List; import javax.swing.JButton; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.pixel.PixelSet; import org.openimaj.image.segmentation.FelzenszwalbHuttenlocherSegmenter; import org.openimaj.image.segmentation.SegmentationUtilities; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
segmentBtn.setEnabled(false); new Thread(new Runnable() { @Override public void run() { ic.setImage(bimg = ImageUtilities.createBufferedImageForDisplay( segmentImage(oimage), bimg)); segmentBtn.setEnabled(true); } }).start(); } }); return base; } protected MBFImage segmentImage(MBFImage oimage) { final FelzenszwalbHuttenlocherSegmenter<MBFImage> seg = new FelzenszwalbHuttenlocherSegmenter<MBFImage>(); final List<? extends PixelSet> result = seg.segment(oimage); return SegmentationUtilities.renderSegments(oimage.getWidth(), oimage.getHeight(), result); } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l4/FHSegmentationDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.List; import javax.swing.JButton; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.pixel.PixelSet; import org.openimaj.image.segmentation.FelzenszwalbHuttenlocherSegmenter; import org.openimaj.image.segmentation.SegmentationUtilities; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; segmentBtn.setEnabled(false); new Thread(new Runnable() { @Override public void run() { ic.setImage(bimg = ImageUtilities.createBufferedImageForDisplay( segmentImage(oimage), bimg)); segmentBtn.setEnabled(true); } }).start(); } }); return base; } protected MBFImage segmentImage(MBFImage oimage) { final FelzenszwalbHuttenlocherSegmenter<MBFImage> seg = new FelzenszwalbHuttenlocherSegmenter<MBFImage>(); final List<? extends PixelSet> result = seg.segment(oimage); return SegmentationUtilities.renderSegments(oimage.getWidth(), oimage.getHeight(), result); } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
new SlideshowApplication(new FHSegmentationDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l5/Lecture5.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture;
for (int i = 20; i <= 39; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new RAGDemo()); for (int i = 40; i <= 43; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new PDMDatasetDemo()); slides.add(new PDMDatasetVideoDemo()); for (int i = 44; i <= 45; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new AlignmentDemo()); for (int i = 46; i <= 48; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new PDMDemo()); for (int i = 49; i <= 50; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new CLMDemo()); slides.add(new PuppeteerDemo()); for (int i = 51; i <= 52; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i))));
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l5/Lecture5.java import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture; for (int i = 20; i <= 39; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new RAGDemo()); for (int i = 40; i <= 43; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new PDMDatasetDemo()); slides.add(new PDMDatasetVideoDemo()); for (int i = 44; i <= 45; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new AlignmentDemo()); for (int i = 46; i <= 48; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new PDMDemo()); for (int i = 49; i <= 50; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i)))); slides.add(new CLMDemo()); slides.add(new PuppeteerDemo()); for (int i = 51; i <= 52; i++) slides.add(new PictureSlide(Lecture5.class.getResource(String.format("l5.%03d.jpg", i))));
new SlideshowApplication(slides, 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l8/LineRANSACDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.SwingConstants; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.ColourSpace; import org.openimaj.image.colour.RGBColour; import org.openimaj.math.geometry.point.Point2dImpl; import org.openimaj.math.model.LeastSquaresLinearModel; import org.openimaj.util.pair.Pair; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
updateImage(); } return inliers; } private Point2dImpl computeModelStep(Pair<Point2dImpl> p) { final float m = (p.firstObject().y - p.secondObject().y) / (p.firstObject().x - p.secondObject().x); final float c = p.firstObject().y - (m * p.firstObject().x); final Point2dImpl p1 = new Point2dImpl(0, c); final Point2dImpl p2 = new Point2dImpl(image.getWidth(), m * image.getWidth() + c); image.drawLine(p1, p2, RGBColour.BLUE); updateImage(); return new Point2dImpl(m, c); } private Pair<Point2dImpl> randomSelectStep(boolean b) { final Point2dImpl pt1 = points.get((int) (Math.random() * points.size())); final Point2dImpl pt2 = points.get((int) (Math.random() * points.size())); image.drawPoint(pt1, RGBColour.BLUE, 10); image.drawPoint(pt2, RGBColour.BLUE, 10); updateImage(); return new Pair<Point2dImpl>(pt1, pt2); } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l8/LineRANSACDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.SwingConstants; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.ColourSpace; import org.openimaj.image.colour.RGBColour; import org.openimaj.math.geometry.point.Point2dImpl; import org.openimaj.math.model.LeastSquaresLinearModel; import org.openimaj.util.pair.Pair; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; updateImage(); } return inliers; } private Point2dImpl computeModelStep(Pair<Point2dImpl> p) { final float m = (p.firstObject().y - p.secondObject().y) / (p.firstObject().x - p.secondObject().x); final float c = p.firstObject().y - (m * p.firstObject().x); final Point2dImpl p1 = new Point2dImpl(0, c); final Point2dImpl p2 = new Point2dImpl(image.getWidth(), m * image.getWidth() + c); image.drawLine(p1, p2, RGBColour.BLUE); updateImage(); return new Point2dImpl(m, c); } private Pair<Point2dImpl> randomSelectStep(boolean b) { final Point2dImpl pt1 = points.get((int) (Math.random() * points.size())); final Point2dImpl pt2 = points.get((int) (Math.random() * points.size())); image.drawPoint(pt1, RGBColour.BLUE, 10); image.drawPoint(pt2, RGBColour.BLUE, 10); updateImage(); return new Pair<Point2dImpl>(pt1, pt2); } public static void main(String[] args) throws IOException {
new SlideshowApplication(new LineRANSACDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l3/Lecture3.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture;
slides.add(new PCADemo()); for (int i = 35; i <= 41; i++) slides.add(new PictureSlide(Lecture3.class.getResource(String.format("l3.%03d.jpg", i)))); slides.add(new FaceDatasetDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.042.jpg"))); slides.add(new MeanFaceDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.043.jpg"))); slides.add(new MeanCenteredFacesDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.044.jpg"))); slides.add(new FacePrincipleComponentsDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.045.jpg"))); slides.add(new EigenFaceApproximationDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.046.jpg"))); slides.add(new EigenFaceReconstructionDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.047.jpg")));
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/Lecture3.java import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture; slides.add(new PCADemo()); for (int i = 35; i <= 41; i++) slides.add(new PictureSlide(Lecture3.class.getResource(String.format("l3.%03d.jpg", i)))); slides.add(new FaceDatasetDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.042.jpg"))); slides.add(new MeanFaceDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.043.jpg"))); slides.add(new MeanCenteredFacesDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.044.jpg"))); slides.add(new FacePrincipleComponentsDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.045.jpg"))); slides.add(new EigenFaceApproximationDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.046.jpg"))); slides.add(new EigenFaceReconstructionDemo()); slides.add(new PictureSlide(Lecture3.class.getResource("l3.047.jpg")));
new SlideshowApplication(slides, 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FacePrincipleComponentsDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FaceDatasetDemo.java // public static class FaceDatasetProvider { // static File tmpFile; // static { // try { // tmpFile = File.createTempFile("faces", ".zip"); // FileUtils.copyURLToFile(FaceDatasetDemo.class.getResource("att_faces.zip"), tmpFile); // tmpFile.deleteOnExit(); // } catch (final Exception e) { // e.printStackTrace(); // } // } // // public static VFSGroupDataset<FImage> getDataset() throws FileSystemException { // return new VFSGroupDataset<FImage>("zip:" + tmpFile.toURI(), ImageUtilities.FIMAGE_READER); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagLayout; import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.data.dataset.VFSGroupDataset; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.EigenImages; import uk.ac.soton.ecs.comp3204.l3.FaceDatasetDemo.FaceDatasetProvider; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
package uk.ac.soton.ecs.comp3204.l3; /** * Visualise the first principle components of a face image * * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) * */ @Demonstration(title = "Face image principal components") public class FacePrincipleComponentsDemo implements Slide { @Override public Component getComponent(int width, int height) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FaceDatasetDemo.java // public static class FaceDatasetProvider { // static File tmpFile; // static { // try { // tmpFile = File.createTempFile("faces", ".zip"); // FileUtils.copyURLToFile(FaceDatasetDemo.class.getResource("att_faces.zip"), tmpFile); // tmpFile.deleteOnExit(); // } catch (final Exception e) { // e.printStackTrace(); // } // } // // public static VFSGroupDataset<FImage> getDataset() throws FileSystemException { // return new VFSGroupDataset<FImage>("zip:" + tmpFile.toURI(), ImageUtilities.FIMAGE_READER); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FacePrincipleComponentsDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagLayout; import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.data.dataset.VFSGroupDataset; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.EigenImages; import uk.ac.soton.ecs.comp3204.l3.FaceDatasetDemo.FaceDatasetProvider; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; package uk.ac.soton.ecs.comp3204.l3; /** * Visualise the first principle components of a face image * * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) * */ @Demonstration(title = "Face image principal components") public class FacePrincipleComponentsDemo implements Slide { @Override public Component getComponent(int width, int height) throws IOException {
final VFSGroupDataset<FImage> dataset = FaceDatasetProvider.getDataset();
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FacePrincipleComponentsDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FaceDatasetDemo.java // public static class FaceDatasetProvider { // static File tmpFile; // static { // try { // tmpFile = File.createTempFile("faces", ".zip"); // FileUtils.copyURLToFile(FaceDatasetDemo.class.getResource("att_faces.zip"), tmpFile); // tmpFile.deleteOnExit(); // } catch (final Exception e) { // e.printStackTrace(); // } // } // // public static VFSGroupDataset<FImage> getDataset() throws FileSystemException { // return new VFSGroupDataset<FImage>("zip:" + tmpFile.toURI(), ImageUtilities.FIMAGE_READER); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagLayout; import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.data.dataset.VFSGroupDataset; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.EigenImages; import uk.ac.soton.ecs.comp3204.l3.FaceDatasetDemo.FaceDatasetProvider; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
outer.setOpaque(false); outer.setPreferredSize(new Dimension(width, height)); outer.setLayout(new GridBagLayout()); final JPanel base = new JPanel(); base.setOpaque(false); base.setPreferredSize(new Dimension(width, height - 50)); base.setLayout(new FlowLayout()); for (int i = 0; i < 60; i++) { final FImage img = eigen.visualisePC(i); final ImageComponent ic = new ImageComponent(true, false); ic.setAllowPanning(false); ic.setAllowZoom(false); ic.setShowPixelColours(false); ic.setShowXYPosition(false); ic.setImage(ImageUtilities.createBufferedImageForDisplay(img)); base.add(ic); } outer.add(base); return outer; } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FaceDatasetDemo.java // public static class FaceDatasetProvider { // static File tmpFile; // static { // try { // tmpFile = File.createTempFile("faces", ".zip"); // FileUtils.copyURLToFile(FaceDatasetDemo.class.getResource("att_faces.zip"), tmpFile); // tmpFile.deleteOnExit(); // } catch (final Exception e) { // e.printStackTrace(); // } // } // // public static VFSGroupDataset<FImage> getDataset() throws FileSystemException { // return new VFSGroupDataset<FImage>("zip:" + tmpFile.toURI(), ImageUtilities.FIMAGE_READER); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l3/FacePrincipleComponentsDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagLayout; import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.data.dataset.VFSGroupDataset; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.model.EigenImages; import uk.ac.soton.ecs.comp3204.l3.FaceDatasetDemo.FaceDatasetProvider; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; outer.setOpaque(false); outer.setPreferredSize(new Dimension(width, height)); outer.setLayout(new GridBagLayout()); final JPanel base = new JPanel(); base.setOpaque(false); base.setPreferredSize(new Dimension(width, height - 50)); base.setLayout(new FlowLayout()); for (int i = 0; i < 60; i++) { final FImage img = eigen.visualisePC(i); final ImageComponent ic = new ImageComponent(true, false); ic.setAllowPanning(false); ic.setAllowZoom(false); ic.setShowPixelColours(false); ic.setShowXYPosition(false); ic.setImage(ImageUtilities.createBufferedImageForDisplay(img)); base.add(ic); } outer.add(base); return outer; } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
new SlideshowApplication(new FacePrincipleComponentsDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l2/Lecture2.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.AudioVideoSlide; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.video.VideoDisplay.EndAction; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture;
package uk.ac.soton.ecs.comp3204.l2; @Lecture(title = "L2: Machine Learning for Pattern Recognition", handoutsURL = "http://jonhare.github.io/COMP3204/handouts/pdf/L2-machine-learning.pdf", slidesURL = "http://jonhare.github.io/COMP3204/lectures/pdf/L2-machine-learning.pdf") @JvmArgs(vmArguments = "-Xmx1G") public class Lecture2 { public static void main(String[] args) throws IOException { final List<Slide> slides = new ArrayList<Slide>(); slides.add(new PictureSlide(Lecture2.class.getResource("l2.001.jpg"))); slides.add(new AudioVideoSlide(Lecture2.class.getResource("pepper.m4v"), EndAction.PAUSE_AT_END)); for (int i = 3; i <= 10; i++) slides.add(new PictureSlide(Lecture2.class.getResource(String.format("l2.%03d.jpg", i)))); slides.add(new SimpleMeanColourFeatureDemo()); for (int i = 11; i <= 23; i++) slides.add(new PictureSlide(Lecture2.class.getResource(String.format("l2.%03d.jpg", i)))); slides.add(new LinearClassifierDemo()); for (int i = 24; i <= 29; i++) slides.add(new PictureSlide(Lecture2.class.getResource(String.format("l2.%03d.jpg", i)))); slides.add(new KNNDemo()); for (int i = 30; i <= 35; i++) slides.add(new PictureSlide(Lecture2.class.getResource(String.format("l2.%03d.jpg", i)))); slides.add(new KMeansDemo()); slides.add(new PictureSlide(Lecture2.class.getResource("l2.036.jpg")));
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l2/Lecture2.java import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.AudioVideoSlide; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.video.VideoDisplay.EndAction; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture; package uk.ac.soton.ecs.comp3204.l2; @Lecture(title = "L2: Machine Learning for Pattern Recognition", handoutsURL = "http://jonhare.github.io/COMP3204/handouts/pdf/L2-machine-learning.pdf", slidesURL = "http://jonhare.github.io/COMP3204/lectures/pdf/L2-machine-learning.pdf") @JvmArgs(vmArguments = "-Xmx1G") public class Lecture2 { public static void main(String[] args) throws IOException { final List<Slide> slides = new ArrayList<Slide>(); slides.add(new PictureSlide(Lecture2.class.getResource("l2.001.jpg"))); slides.add(new AudioVideoSlide(Lecture2.class.getResource("pepper.m4v"), EndAction.PAUSE_AT_END)); for (int i = 3; i <= 10; i++) slides.add(new PictureSlide(Lecture2.class.getResource(String.format("l2.%03d.jpg", i)))); slides.add(new SimpleMeanColourFeatureDemo()); for (int i = 11; i <= 23; i++) slides.add(new PictureSlide(Lecture2.class.getResource(String.format("l2.%03d.jpg", i)))); slides.add(new LinearClassifierDemo()); for (int i = 24; i <= 29; i++) slides.add(new PictureSlide(Lecture2.class.getResource(String.format("l2.%03d.jpg", i)))); slides.add(new KNNDemo()); for (int i = 30; i <= 35; i++) slides.add(new PictureSlide(Lecture2.class.getResource(String.format("l2.%03d.jpg", i)))); slides.add(new KMeansDemo()); slides.add(new PictureSlide(Lecture2.class.getResource("l2.036.jpg")));
new SlideshowApplication(slides, 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l6/DoGPointsDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l1/SimpleCameraDemo.java // @Demonstration(title = "Simple Camera Demo") // public class SimpleCameraDemo implements Slide { // protected VideoCaptureComponent vc; // // @Override // public JPanel getComponent(int width, int height) throws IOException { // // the main panel // final JPanel base = new JPanel(); // base.setOpaque(false); // base.setPreferredSize(new Dimension(width, height)); // base.setLayout(new GridBagLayout()); // vc = new VideoCaptureComponent(640, 480); // base.add(vc); // // return base; // } // // @Override // public void close() { // vc.close(); // } // // public static void main(String[] args) throws IOException { // new SlideshowApplication(new SimpleCameraDemo(), 1024, 768, Utils.BACKGROUND_IMAGE); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Font; import java.io.IOException; import java.util.List; import javax.swing.JPanel; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.RGBColour; import org.openimaj.image.feature.local.engine.DoGSIFTEngine; import org.openimaj.image.feature.local.keypoints.Keypoint; import org.openimaj.math.geometry.shape.Circle; import org.openimaj.video.VideoDisplay; import org.openimaj.video.VideoDisplayListener; import uk.ac.soton.ecs.comp3204.l1.SimpleCameraDemo; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
package uk.ac.soton.ecs.comp3204.l6; @Demonstration(title = "Difference-of-Gaussian blob detection") public class DoGPointsDemo extends SimpleCameraDemo implements VideoDisplayListener<MBFImage> { static Font FONT = Font.decode("Monaco-32"); DoGSIFTEngine engine = new DoGSIFTEngine(); @Override public JPanel getComponent(int width, int height) throws IOException { final JPanel c = super.getComponent(width, height); engine.getOptions().setDoubleInitialImage(false); this.vc.getDisplay().addVideoListener(this); return c; } @Override public void afterUpdate(VideoDisplay<MBFImage> display) { // do nothing } @Override public void beforeUpdate(MBFImage frame) { final List<Keypoint> features = engine.findFeatures(frame.flatten()); for (final Keypoint k : features) { frame.drawShape(new Circle(k.x, k.y, 4 * k.scale), RGBColour.RED); } } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l1/SimpleCameraDemo.java // @Demonstration(title = "Simple Camera Demo") // public class SimpleCameraDemo implements Slide { // protected VideoCaptureComponent vc; // // @Override // public JPanel getComponent(int width, int height) throws IOException { // // the main panel // final JPanel base = new JPanel(); // base.setOpaque(false); // base.setPreferredSize(new Dimension(width, height)); // base.setLayout(new GridBagLayout()); // vc = new VideoCaptureComponent(640, 480); // base.add(vc); // // return base; // } // // @Override // public void close() { // vc.close(); // } // // public static void main(String[] args) throws IOException { // new SlideshowApplication(new SimpleCameraDemo(), 1024, 768, Utils.BACKGROUND_IMAGE); // } // } // // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l6/DoGPointsDemo.java import java.awt.Font; import java.io.IOException; import java.util.List; import javax.swing.JPanel; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.RGBColour; import org.openimaj.image.feature.local.engine.DoGSIFTEngine; import org.openimaj.image.feature.local.keypoints.Keypoint; import org.openimaj.math.geometry.shape.Circle; import org.openimaj.video.VideoDisplay; import org.openimaj.video.VideoDisplayListener; import uk.ac.soton.ecs.comp3204.l1.SimpleCameraDemo; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; package uk.ac.soton.ecs.comp3204.l6; @Demonstration(title = "Difference-of-Gaussian blob detection") public class DoGPointsDemo extends SimpleCameraDemo implements VideoDisplayListener<MBFImage> { static Font FONT = Font.decode("Monaco-32"); DoGSIFTEngine engine = new DoGSIFTEngine(); @Override public JPanel getComponent(int width, int height) throws IOException { final JPanel c = super.getComponent(width, height); engine.getOptions().setDoubleInitialImage(false); this.vc.getDisplay().addVideoListener(this); return c; } @Override public void afterUpdate(VideoDisplay<MBFImage> display) { // do nothing } @Override public void beforeUpdate(MBFImage frame) { final List<Keypoint> features = engine.findFeatures(frame.flatten()); for (final Keypoint k : features) { frame.drawShape(new Circle(k.x, k.y, 4 * k.scale), RGBColour.RED); } } public static void main(String[] args) throws IOException {
new SlideshowApplication(new DoGPointsDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l10/Lecture10.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture;
package uk.ac.soton.ecs.comp3204.l10; @Lecture( title = "L10: Image Classification and Auto Annotation", handoutsURL = "http://jonhare.github.io/COMP3204/handouts/pdf/L10-classification.pdf", slidesURL = "http://jonhare.github.io/COMP3204/lectures/pdf/L10-classification.pdf") @JvmArgs(vmArguments = "-Xmx1G") public class Lecture10 { public static void main(String[] args) throws IOException { final List<Slide> slides = new ArrayList<Slide>(); for (int i = 1; i <= 3; i++) slides.add(new PictureSlide(Lecture10.class.getResource(String.format("l10.%03d.jpg", i)))); slides.add(new TomatoLinearClassifierDemo()); slides.add(new PictureSlide(Lecture10.class.getResource(String.format("l10.%03d.jpg", 4))));
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l10/Lecture10.java import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.openimaj.content.slideshow.PictureSlide; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.JvmArgs; import uk.ac.soton.ecs.comp3204.utils.annotations.Lecture; package uk.ac.soton.ecs.comp3204.l10; @Lecture( title = "L10: Image Classification and Auto Annotation", handoutsURL = "http://jonhare.github.io/COMP3204/handouts/pdf/L10-classification.pdf", slidesURL = "http://jonhare.github.io/COMP3204/lectures/pdf/L10-classification.pdf") @JvmArgs(vmArguments = "-Xmx1G") public class Lecture10 { public static void main(String[] args) throws IOException { final List<Slide> slides = new ArrayList<Slide>(); for (int i = 1; i <= 3; i++) slides.add(new PictureSlide(Lecture10.class.getResource(String.format("l10.%03d.jpg", i)))); slides.add(new TomatoLinearClassifierDemo()); slides.add(new PictureSlide(Lecture10.class.getResource(String.format("l10.%03d.jpg", 4))));
slides.add(new TomatoKNNClassifierDemo(Utils.BACKGROUND_IMAGE));
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l5/PDMDatasetVideoDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagLayout; import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.RGBColour; import org.openimaj.image.model.asm.datasets.AMToolsSampleDataset; import org.openimaj.image.model.asm.datasets.ShapeModelDataset; import org.openimaj.math.geometry.line.Line2d; import org.openimaj.math.geometry.point.PointList; import org.openimaj.util.pair.IndependentPair; import org.openimaj.video.ArrayBackedVideo; import org.openimaj.video.VideoDisplay; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
package uk.ac.soton.ecs.comp3204.l5; @Demonstration(title = "Dataset for building a shape model (video)") public class PDMDatasetVideoDemo implements Slide { private VideoDisplay<MBFImage> display; @Override public Component getComponent(int width, int height) throws IOException { // the main panel final JPanel base = new JPanel(); base.setOpaque(false); base.setPreferredSize(new Dimension(width, height)); base.setLayout(new GridBagLayout()); final ShapeModelDataset<MBFImage> dataset = AMToolsSampleDataset.load(ImageUtilities.MBFIMAGE_READER); final MBFImage[] frames = new MBFImage[dataset.size()]; int i = 0; for (final IndependentPair<PointList, MBFImage> p : dataset) { final MBFImage image = p.getSecondObject(); image.drawPoints(p.getFirstObject(), RGBColour.WHITE, 5); for (final Line2d line : p.getFirstObject().getLines(dataset.getConnections())) { image.drawLine(line, 3, RGBColour.WHITE); } frames[i++] = image; } final ArrayBackedVideo<MBFImage> vc = new ArrayBackedVideo<MBFImage>(frames, 5, true); display = VideoDisplay.createVideoDisplay(vc, base); return base; } @Override public void close() { display.close(); } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l5/PDMDatasetVideoDemo.java import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagLayout; import java.io.IOException; import javax.swing.JPanel; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.ImageUtilities; import org.openimaj.image.MBFImage; import org.openimaj.image.colour.RGBColour; import org.openimaj.image.model.asm.datasets.AMToolsSampleDataset; import org.openimaj.image.model.asm.datasets.ShapeModelDataset; import org.openimaj.math.geometry.line.Line2d; import org.openimaj.math.geometry.point.PointList; import org.openimaj.util.pair.IndependentPair; import org.openimaj.video.ArrayBackedVideo; import org.openimaj.video.VideoDisplay; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; package uk.ac.soton.ecs.comp3204.l5; @Demonstration(title = "Dataset for building a shape model (video)") public class PDMDatasetVideoDemo implements Slide { private VideoDisplay<MBFImage> display; @Override public Component getComponent(int width, int height) throws IOException { // the main panel final JPanel base = new JPanel(); base.setOpaque(false); base.setPreferredSize(new Dimension(width, height)); base.setLayout(new GridBagLayout()); final ShapeModelDataset<MBFImage> dataset = AMToolsSampleDataset.load(ImageUtilities.MBFIMAGE_READER); final MBFImage[] frames = new MBFImage[dataset.size()]; int i = 0; for (final IndependentPair<PointList, MBFImage> p : dataset) { final MBFImage image = p.getSecondObject(); image.drawPoints(p.getFirstObject(), RGBColour.WHITE, 5); for (final Line2d line : p.getFirstObject().getLines(dataset.getConnections())) { image.drawLine(line, 3, RGBColour.WHITE); } frames[i++] = image; } final ArrayBackedVideo<MBFImage> vc = new ArrayBackedVideo<MBFImage>(frames, 5, true); display = VideoDisplay.createVideoDisplay(vc, base); return base; } @Override public void close() { display.close(); } public static void main(String[] args) throws IOException {
new SlideshowApplication(new PDMDatasetVideoDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
jonhare/COMP3204
app/src/main/java/uk/ac/soton/ecs/comp3204/l4/AdaptiveThresholdDemo.java
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // }
import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagLayout; import java.awt.image.BufferedImage; import java.io.IOException; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.processing.threshold.AdaptiveLocalThresholdMean; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration;
@Override public void stateChanged(ChangeEvent e) { if (cb.isSelected()) { final int size = sizeSlider.getValue(); final float offset = (float) (offsetSlider.getValue() / 1000.0); ic.setImage(bimg = ImageUtilities .createBufferedImageForDisplay(threshold(oimage, size, offset), bimg)); } else { ic.setImage(bimg = ImageUtilities.createBufferedImageForDisplay(oimage, bimg)); } } }); base.add(container); outer.add(base); return outer; } private FImage threshold(FImage oimage, int size, float offset) { return oimage.process(new AdaptiveLocalThresholdMean(size, offset)); } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
// Path: app/src/main/java/uk/ac/soton/ecs/comp3204/utils/Utils.java // public class Utils { // public static URL BACKGROUND_IMAGE_URL = Utils.class.getResource("/uk/ac/soton/ecs/comp3204/background.png"); // public static BufferedImage BACKGROUND_IMAGE = null; // static { // try { // BACKGROUND_IMAGE = ImageIO.read(BACKGROUND_IMAGE_URL); // } catch (final IOException e) { // } // } // // private Utils() { // } // // public static JLabel linkify(final String text, String URL, String toolTip) // { // URI temp = null; // try // { // temp = new URI(URL); // } catch (final Exception e) // { // e.printStackTrace(); // } // final URI uri = temp; // final JLabel link = new JLabel(); // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // if (!toolTip.equals("")) // link.setToolTipText(toolTip); // link.setCursor(new Cursor(Cursor.HAND_CURSOR)); // link.addMouseListener(new MouseListener() // { // @Override // public void mouseExited(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); // } // // @Override // public void mouseEntered(MouseEvent arg0) // { // link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); // } // // @Override // public void mouseClicked(MouseEvent arg0) // { // if (Desktop.isDesktopSupported()) // { // try // { // Desktop.getDesktop().browse(uri); // } // catch (final Exception e) // { // e.printStackTrace(); // } // } // else // { // final JOptionPane pane = new JOptionPane("Could not open link."); // final JDialog dialog = pane.createDialog(new JFrame(), ""); // dialog.setVisible(true); // } // } // // @Override // public void mousePressed(MouseEvent e) // { // } // // @Override // public void mouseReleased(MouseEvent e) // { // } // }); // return link; // } // } // Path: app/src/main/java/uk/ac/soton/ecs/comp3204/l4/AdaptiveThresholdDemo.java import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagLayout; import java.awt.image.BufferedImage; import java.io.IOException; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openimaj.content.slideshow.Slide; import org.openimaj.content.slideshow.SlideshowApplication; import org.openimaj.image.DisplayUtilities.ImageComponent; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.processing.threshold.AdaptiveLocalThresholdMean; import uk.ac.soton.ecs.comp3204.utils.Utils; import uk.ac.soton.ecs.comp3204.utils.annotations.Demonstration; @Override public void stateChanged(ChangeEvent e) { if (cb.isSelected()) { final int size = sizeSlider.getValue(); final float offset = (float) (offsetSlider.getValue() / 1000.0); ic.setImage(bimg = ImageUtilities .createBufferedImageForDisplay(threshold(oimage, size, offset), bimg)); } else { ic.setImage(bimg = ImageUtilities.createBufferedImageForDisplay(oimage, bimg)); } } }); base.add(container); outer.add(base); return outer; } private FImage threshold(FImage oimage, int size, float offset) { return oimage.process(new AdaptiveLocalThresholdMean(size, offset)); } @Override public void close() { // do nothing } public static void main(String[] args) throws IOException {
new SlideshowApplication(new AdaptiveThresholdDemo(), 1024, 768, Utils.BACKGROUND_IMAGE);
wotateam/wota
src/wota/gameobjects/BaseAntObject.java
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.utility.Vector;
/** * */ package wota.gameobjects; /** * Base class for living (AntObject) and dead (AntCorpseObject) Ants. */ public abstract class BaseAntObject extends GameObject { public final int id; public final Caste caste; public final GameWorld.Player player;
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/BaseAntObject.java import wota.utility.Vector; /** * */ package wota.gameobjects; /** * Base class for living (AntObject) and dead (AntCorpseObject) Ants. */ public abstract class BaseAntObject extends GameObject { public final int id; public final Caste caste; public final GameWorld.Player player;
public BaseAntObject(Vector position, Caste caste, int id,
wotateam/wota
src/wota/ai/dichterunddenker/HillAI.java
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; import wota.utility.SeededRandomizer;
/** * */ package wota.ai.dichterunddenker; /* * */ @AIInformation(creator = "Simon", name = "JohannWolfgangvonGoethe") public class HillAI extends wota.gameobjects.HillAI { public int counter=0; public boolean endgame=false; /* * your Queen is not able to move but can * communicate and create new ants. * * You can create new ants with createAnt(caste, antAIClass) * e.g. if you want a gatherer and the AI * you want use is called SuperGathererAI createAnt(Caste.Gatherer, SuperGathererAI.class) * */ @Override public void tick() throws Exception { counter++; if(counter==500){ endgame=true; counter=0; } talk(random.nextInt(360)); /* * try to create an Ant using the TemplateAI in every tick * if you don't have enough food to create the ant your call * will be ignored */ if(endgame==false){ if(random.nextInt(10)<9){
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // Path: src/wota/ai/dichterunddenker/HillAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; import wota.utility.SeededRandomizer; /** * */ package wota.ai.dichterunddenker; /* * */ @AIInformation(creator = "Simon", name = "JohannWolfgangvonGoethe") public class HillAI extends wota.gameobjects.HillAI { public int counter=0; public boolean endgame=false; /* * your Queen is not able to move but can * communicate and create new ants. * * You can create new ants with createAnt(caste, antAIClass) * e.g. if you want a gatherer and the AI * you want use is called SuperGathererAI createAnt(Caste.Gatherer, SuperGathererAI.class) * */ @Override public void tick() throws Exception { counter++; if(counter==500){ endgame=true; counter=0; } talk(random.nextInt(360)); /* * try to create an Ant using the TemplateAI in every tick * if you don't have enough food to create the ant your call * will be ignored */ if(endgame==false){ if(random.nextInt(10)<9){
createAnt(Caste.Gatherer, FamilieMann.class);
wotateam/wota
src/wota/ai/pwahs05/TalkingAntAI.java
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // }
import java.util.LinkedList; import java.util.List; import wota.gameobjects.*; import wota.utility.SeededRandomizer;
&& indices[nr_hill] < hills.get(nr_hill).size() - HillAI.SHOUT_LAST_NOSUGAR){ indices[nr_hill] = hills.get(nr_hill).size() - HillAI.SHOUT_LAST_NOSUGAR; } talk(nr_hill+HillAI.HILL_OFFSET, hills.get(nr_hill).get(indices[nr_hill])); } public void first_cry(){ if (time == 1){ //was just born, figure out time and directions: //find time: if (audibleHillMessage != null){ if (audibleHillMessage.content < 0) { initialTime = audibleHillMessage.content - HillAI.initTime; } } if (initialTime==1) { //in the beginning, figure out direction: int count = 0; int total = 0; for (Ant a: visibleFriends()) { if (a.caste.compareTo(self.caste) == 0) { total++; if (a.id < self.id) count++; } } dir = (360*(count - (count % 2) * HillAI.STARTER_PAIRING))/(total+1); }else{//later, just go some random direction:
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // Path: src/wota/ai/pwahs05/TalkingAntAI.java import java.util.LinkedList; import java.util.List; import wota.gameobjects.*; import wota.utility.SeededRandomizer; && indices[nr_hill] < hills.get(nr_hill).size() - HillAI.SHOUT_LAST_NOSUGAR){ indices[nr_hill] = hills.get(nr_hill).size() - HillAI.SHOUT_LAST_NOSUGAR; } talk(nr_hill+HillAI.HILL_OFFSET, hills.get(nr_hill).get(indices[nr_hill])); } public void first_cry(){ if (time == 1){ //was just born, figure out time and directions: //find time: if (audibleHillMessage != null){ if (audibleHillMessage.content < 0) { initialTime = audibleHillMessage.content - HillAI.initTime; } } if (initialTime==1) { //in the beginning, figure out direction: int count = 0; int total = 0; for (Ant a: visibleFriends()) { if (a.caste.compareTo(self.caste) == 0) { total++; if (a.id < self.id) count++; } } dir = (360*(count - (count % 2) * HillAI.STARTER_PAIRING))/(total+1); }else{//later, just go some random direction:
dir = SeededRandomizer.nextDouble()*360;
wotateam/wota
src/wota/ai/pwahs05/SugarAI.java
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.ListIterator; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.Vector;
if (hills.get(HillAI.SUGAR_IND).size() > 0) { Snapshot target = find_optimal_sugar_hill(null); if (target != null) { target_sugar = target; moveToward(target); } } } else { //see sugar: Sugar sugar = closest(visibleSugar); target_sugar = sugar; moveToward(sugar); think_about_picking_up(sugar); } } } public boolean just_looking(){ return false; //return (self.id % 2 != 0 && initialTime + time <= HillAI.BACKWARD); } @Override public void nosugar(Snapshot sugar){ if (sugar.hasSameOriginal(target_sugar)) { target_sugar = null; } }
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs05/SugarAI.java import java.util.ListIterator; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.Vector; if (hills.get(HillAI.SUGAR_IND).size() > 0) { Snapshot target = find_optimal_sugar_hill(null); if (target != null) { target_sugar = target; moveToward(target); } } } else { //see sugar: Sugar sugar = closest(visibleSugar); target_sugar = sugar; moveToward(sugar); think_about_picking_up(sugar); } } } public boolean just_looking(){ return false; //return (self.id % 2 != 0 && initialTime + time <= HillAI.BACKWARD); } @Override public void nosugar(Snapshot sugar){ if (sugar.hasSameOriginal(target_sugar)) { target_sugar = null; } }
public Vector shift_aside(Vector pos){
wotateam/wota
src/wota/ai/pwahs03/SugarAI.java
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; import java.util.List; import java.util.LinkedList;
HillAI.add_if_not_contained(hills.get(HillAI.NOSUGAR_IND), target); HillAI.delete(hills.get(HillAI.SUGAR_IND), target); HillAI.delete(hills.get(HillAI.FULLSUGAR_IND), target); } } } } else { //see sugar: Sugar sugar = closest(visibleSugar); moveToward(sugar); // otherwise move to the first element in the List of visible sugar think_about_picking_up(sugar); if (!HillAI.contained(hills.get(HillAI.FULLSUGAR_IND), sugar)){ HillAI.add_if_not_contained(hills.get(HillAI.SUGAR_IND), sugar); } } } } public void think_about_picking_up(Sugar sugar){ int count = 0; for(Ant a: visibleFriends()){ if (a.caste == Caste.Gatherer){ if (a.id < self.id) count++; } } if (count < HillAI.QUEUELENGTH) { pickUpSugar(sugar); } else{ if (count < sugar.amount / (Caste.Gatherer.MAX_SUGAR_CARRY)){
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs03/SugarAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; import java.util.List; import java.util.LinkedList; HillAI.add_if_not_contained(hills.get(HillAI.NOSUGAR_IND), target); HillAI.delete(hills.get(HillAI.SUGAR_IND), target); HillAI.delete(hills.get(HillAI.FULLSUGAR_IND), target); } } } } else { //see sugar: Sugar sugar = closest(visibleSugar); moveToward(sugar); // otherwise move to the first element in the List of visible sugar think_about_picking_up(sugar); if (!HillAI.contained(hills.get(HillAI.FULLSUGAR_IND), sugar)){ HillAI.add_if_not_contained(hills.get(HillAI.SUGAR_IND), sugar); } } } } public void think_about_picking_up(Sugar sugar){ int count = 0; for(Ant a: visibleFriends()){ if (a.caste == Caste.Gatherer){ if (a.id < self.id) count++; } } if (count < HillAI.QUEUELENGTH) { pickUpSugar(sugar); } else{ if (count < sugar.amount / (Caste.Gatherer.MAX_SUGAR_CARRY)){
Vector pos = sugar.position;
wotateam/wota
src/wota/ai/pwahs03/SugarAI.java
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; import java.util.List; import java.util.LinkedList;
public double walking_distance(Snapshot sugarhill){ double d = vectorBetween(self, sugarhill).length() * self.caste.SPEED; d += vectorBetween(sugarhill, hills.get(HillAI.HILL_IND).getFirst()).length() * self.caste.SPEED_WHILE_CARRYING_SUGAR; return d; } public void first_cry(){ if (time == 1){ //was just born, figure out time and directions: //find time: if (audibleHillMessage != null) { if (audibleHillMessage.content < 0) { initialTime = audibleHillMessage.content - HillAI.initTime; } } if (initialTime < 5) { //in the beginning, figure out direction: int count = 0; int total = 0; for(Ant a: visibleFriends()){ if (a.caste == Caste.Gatherer){ total++; if (a.id < self.id) count++; } } dir = (360*count)/(total+1); moveInDirection(dir); }else{//later, just go some random direction:
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs03/SugarAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; import java.util.List; import java.util.LinkedList; public double walking_distance(Snapshot sugarhill){ double d = vectorBetween(self, sugarhill).length() * self.caste.SPEED; d += vectorBetween(sugarhill, hills.get(HillAI.HILL_IND).getFirst()).length() * self.caste.SPEED_WHILE_CARRYING_SUGAR; return d; } public void first_cry(){ if (time == 1){ //was just born, figure out time and directions: //find time: if (audibleHillMessage != null) { if (audibleHillMessage.content < 0) { initialTime = audibleHillMessage.content - HillAI.initTime; } } if (initialTime < 5) { //in the beginning, figure out direction: int count = 0; int total = 0; for(Ant a: visibleFriends()){ if (a.caste == Caste.Gatherer){ total++; if (a.id < self.id) count++; } } dir = (360*count)/(total+1); moveInDirection(dir); }else{//later, just go some random direction:
dir = SeededRandomizer.nextDouble()*360;
wotateam/wota
src/wota/gameobjects/SugarObject.java
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.LinkedList; import java.util.List; import wota.utility.SeededRandomizer; import wota.utility.Vector;
package wota.gameobjects; /** * A sugar source. * * Sugar can be picked up by first come first serve principle. * */ public class SugarObject extends GameObject { private int amount; private Sugar sugar; private List<AntObject> pickUpCandidates = new LinkedList<AntObject>(); private int ticksUntilNextPickUp = 0;
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/SugarObject.java import java.util.LinkedList; import java.util.List; import wota.utility.SeededRandomizer; import wota.utility.Vector; package wota.gameobjects; /** * A sugar source. * * Sugar can be picked up by first come first serve principle. * */ public class SugarObject extends GameObject { private int amount; private Sugar sugar; private List<AntObject> pickUpCandidates = new LinkedList<AntObject>(); private int ticksUntilNextPickUp = 0;
public SugarObject(Vector position, Parameters parameters) {
wotateam/wota
src/wota/gameobjects/SugarObject.java
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.LinkedList; import java.util.List; import wota.utility.SeededRandomizer; import wota.utility.Vector;
package wota.gameobjects; /** * A sugar source. * * Sugar can be picked up by first come first serve principle. * */ public class SugarObject extends GameObject { private int amount; private Sugar sugar; private List<AntObject> pickUpCandidates = new LinkedList<AntObject>(); private int ticksUntilNextPickUp = 0; public SugarObject(Vector position, Parameters parameters) { super(position, parameters); amount = parameters.INITIAL_SUGAR_IN_SOURCE; } public void createSugar() { this.sugar = new Sugar(this); } public Sugar getSugar() { return sugar; } public int getAmount() { return amount; } public void tick() { if (ticksUntilNextPickUp == 0) { if (!pickUpCandidates.isEmpty()) {
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/SugarObject.java import java.util.LinkedList; import java.util.List; import wota.utility.SeededRandomizer; import wota.utility.Vector; package wota.gameobjects; /** * A sugar source. * * Sugar can be picked up by first come first serve principle. * */ public class SugarObject extends GameObject { private int amount; private Sugar sugar; private List<AntObject> pickUpCandidates = new LinkedList<AntObject>(); private int ticksUntilNextPickUp = 0; public SugarObject(Vector position, Parameters parameters) { super(position, parameters); amount = parameters.INITIAL_SUGAR_IN_SOURCE; } public void createSugar() { this.sugar = new Sugar(this); } public Sugar getSugar() { return sugar; } public int getAmount() { return amount; } public void tick() { if (ticksUntilNextPickUp == 0) { if (!pickUpCandidates.isEmpty()) {
final int winningIndex = SeededRandomizer.nextInt(pickUpCandidates.size());
wotateam/wota
src/wota/ai/pwahs03/ScoutAI.java
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; import java.util.List; import java.util.LinkedList;
public void have_a_look_around(){ for(Hill hill: visibleHills){ HillAI.add_if_not_contained(hills.get(HillAI.HILL_IND),hill); } } public void handle_sugar(){ moveInDirection(dir); //dont have sugar: if (visibleSugar.size() > 0){ Sugar sugar = closest(visibleSugar); if (!HillAI.contained(hills.get(HillAI.FULLSUGAR_IND), sugar)){ HillAI.add_if_not_contained(hills.get(HillAI.SUGAR_IND), sugar); } } } public void think_about_picking_up(Sugar sugar){ int count = 0; for(Ant a: visibleFriends()){ if (a.caste == Caste.Gatherer){ if (a.id < self.id) count++; } } if (count < HillAI.QUEUELENGTH) { pickUpSugar(sugar); } else{ if (count < sugar.amount / (Caste.Gatherer.MAX_SUGAR_CARRY)){
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs03/ScoutAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; import java.util.List; import java.util.LinkedList; public void have_a_look_around(){ for(Hill hill: visibleHills){ HillAI.add_if_not_contained(hills.get(HillAI.HILL_IND),hill); } } public void handle_sugar(){ moveInDirection(dir); //dont have sugar: if (visibleSugar.size() > 0){ Sugar sugar = closest(visibleSugar); if (!HillAI.contained(hills.get(HillAI.FULLSUGAR_IND), sugar)){ HillAI.add_if_not_contained(hills.get(HillAI.SUGAR_IND), sugar); } } } public void think_about_picking_up(Sugar sugar){ int count = 0; for(Ant a: visibleFriends()){ if (a.caste == Caste.Gatherer){ if (a.id < self.id) count++; } } if (count < HillAI.QUEUELENGTH) { pickUpSugar(sugar); } else{ if (count < sugar.amount / (Caste.Gatherer.MAX_SUGAR_CARRY)){
Vector pos = sugar.position;
wotateam/wota
src/wota/ai/pwahs11/ScoutAI.java
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.LinkedList; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.Vector;
package wota.ai.pwahs11; @AIInformation(creator = "pwahs", name = "pwahs11") public class ScoutAI extends TalkingAntAI {
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs11/ScoutAI.java import java.util.LinkedList; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.Vector; package wota.ai.pwahs11; @AIInformation(creator = "pwahs", name = "pwahs11") public class ScoutAI extends TalkingAntAI {
Vector last_position = null;
wotateam/wota
src/wota/gameobjects/SpacePartitioning.java
// Path: src/wota/utility/Modulo.java // public class Modulo { // public static int mod(int x, int m) { // int r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // // public static double mod(double x, double m) { // double r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.Iterator; import java.util.LinkedList; import java.util.List; import wota.utility.Modulo; import wota.utility.Vector;
Cell cell = cells[i][j]; update(cell, i, j, Cell.antObjectsField); } } } public void discardAntMessages() { for (int i = 1; i < numberOfHorizontalCells + 1; i++) { for (int j = 1; j < numberOfVerticalCells + 1; j++) { Cell cell = cells[i][j]; cell.antMessages.clear(); } } } public void discardHillMessages() { for (int i = 1; i < numberOfHorizontalCells + 1; i++) { for (int j = 1; j < numberOfVerticalCells + 1; j++) { Cell cell = cells[i][j]; cell.hillMessages.clear(); } } } private <T extends GameObject> void update(Cell cell, int i, int j, GameObjectListField<T> field) { List<T> listOfTs = field.get(cell); Iterator<T> iterator = listOfTs.iterator(); while (iterator.hasNext()) { T t = iterator.next();
// Path: src/wota/utility/Modulo.java // public class Modulo { // public static int mod(int x, int m) { // int r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // // public static double mod(double x, double m) { // double r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/SpacePartitioning.java import java.util.Iterator; import java.util.LinkedList; import java.util.List; import wota.utility.Modulo; import wota.utility.Vector; Cell cell = cells[i][j]; update(cell, i, j, Cell.antObjectsField); } } } public void discardAntMessages() { for (int i = 1; i < numberOfHorizontalCells + 1; i++) { for (int j = 1; j < numberOfVerticalCells + 1; j++) { Cell cell = cells[i][j]; cell.antMessages.clear(); } } } public void discardHillMessages() { for (int i = 1; i < numberOfHorizontalCells + 1; i++) { for (int j = 1; j < numberOfVerticalCells + 1; j++) { Cell cell = cells[i][j]; cell.hillMessages.clear(); } } } private <T extends GameObject> void update(Cell cell, int i, int j, GameObjectListField<T> field) { List<T> listOfTs = field.get(cell); Iterator<T> iterator = listOfTs.iterator(); while (iterator.hasNext()) { T t = iterator.next();
Vector p = t.getPosition();
wotateam/wota
src/wota/gameobjects/SpacePartitioning.java
// Path: src/wota/utility/Modulo.java // public class Modulo { // public static int mod(int x, int m) { // int r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // // public static double mod(double x, double m) { // double r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.Iterator; import java.util.LinkedList; import java.util.List; import wota.utility.Modulo; import wota.utility.Vector;
} return listOfTsInsideCircle; } public List<AntObject> antObjectsInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.antObjectsField); } public List<AntCorpseObject> antCorpseObjectsInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.antCorpseObjectsField); } public List<HillObject> hillObjectsInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.hillObjectsField); } public List<SugarObject> sugarObjectsInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.sugarObjectsField); } public List<AntMessage> antMessagesInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.antMessagesField); } public List<HillMessage> hillMessagesInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.hillMessagesField); } public final int coordinatesToCellXIndex(Vector p) {
// Path: src/wota/utility/Modulo.java // public class Modulo { // public static int mod(int x, int m) { // int r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // // public static double mod(double x, double m) { // double r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/SpacePartitioning.java import java.util.Iterator; import java.util.LinkedList; import java.util.List; import wota.utility.Modulo; import wota.utility.Vector; } return listOfTsInsideCircle; } public List<AntObject> antObjectsInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.antObjectsField); } public List<AntCorpseObject> antCorpseObjectsInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.antCorpseObjectsField); } public List<HillObject> hillObjectsInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.hillObjectsField); } public List<SugarObject> sugarObjectsInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.sugarObjectsField); } public List<AntMessage> antMessagesInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.antMessagesField); } public List<HillMessage> hillMessagesInsideCircle(double radius, Vector center) { return TsInsideCircle(radius, center, Cell.hillMessagesField); } public final int coordinatesToCellXIndex(Vector p) {
return Modulo.mod((int) Math.round(Math.floor(p.x/cellWidth)), numberOfHorizontalCells) + 1;
wotateam/wota
src/wota/ai/pwahs11/GuardAI.java
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.Vector;
WAITING_FOR_ORDERS, GUARDING, WAYLAYING } GuardAIStatus status = GuardAIStatus.WAITING_FOR_ORDERS; @Override public void tick() throws Exception { super.tick(); do_stuff(); } private void do_stuff() { switch(status) { case GUARDING: if (target_sugar == null) { int index = hills[HillAI.SUGAR_IND].size(); if (index > 0) { target_sugar = hills[HillAI.SUGAR_IND].get(self.id % index).s; } } if (hills[HillAI.HILL_IND].size() > 1) { status = GuardAIStatus.WAYLAYING; do_stuff(); break; } move_there_while_attacking(target_sugar==null ? null : target_sugar.getPosition()); break; case WAYLAYING:
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs11/GuardAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.Vector; WAITING_FOR_ORDERS, GUARDING, WAYLAYING } GuardAIStatus status = GuardAIStatus.WAITING_FOR_ORDERS; @Override public void tick() throws Exception { super.tick(); do_stuff(); } private void do_stuff() { switch(status) { case GUARDING: if (target_sugar == null) { int index = hills[HillAI.SUGAR_IND].size(); if (index > 0) { target_sugar = hills[HillAI.SUGAR_IND].get(self.id % index).s; } } if (hills[HillAI.HILL_IND].size() > 1) { status = GuardAIStatus.WAYLAYING; do_stuff(); break; } move_there_while_attacking(target_sugar==null ? null : target_sugar.getPosition()); break; case WAYLAYING:
Vector target = null;
wotateam/wota
src/wota/gameobjects/Message.java
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.utility.Vector;
/** * */ package wota.gameobjects; /** * Base class for Messages. * Does not contain a sender since this is specified in * derived classes AntMessage or HillMessage. */ public abstract class Message extends GameObject { /** information carried by the message */ public final int content; /** Snapshot is one is transfered as message content * If this is an Ant/Sugar/Hill the corresponding field * contentAnt/Sugar/Hill will be set so you don't have to * typecast. */ public final Snapshot contentSnapshot; /** Ant if one is tranfered as message content */ public final Ant contentAnt; /** Sugar if one is tranfered as message content */ public final Sugar contentSugar; /** Hill if one is tranfered as message content */ public final Hill contentHill;
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/Message.java import wota.utility.Vector; /** * */ package wota.gameobjects; /** * Base class for Messages. * Does not contain a sender since this is specified in * derived classes AntMessage or HillMessage. */ public abstract class Message extends GameObject { /** information carried by the message */ public final int content; /** Snapshot is one is transfered as message content * If this is an Ant/Sugar/Hill the corresponding field * contentAnt/Sugar/Hill will be set so you don't have to * typecast. */ public final Snapshot contentSnapshot; /** Ant if one is tranfered as message content */ public final Ant contentAnt; /** Sugar if one is tranfered as message content */ public final Sugar contentSugar; /** Hill if one is tranfered as message content */ public final Hill contentHill;
public Message(Vector position, int content, Snapshot snapshot, Parameters parameters) {
wotateam/wota
src/wota/gameobjects/AntAI.java
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.LinkedList; import java.util.List; import wota.utility.Vector;
package wota.gameobjects; /** * Basisclass for antais by the user. * Contains several lists describing the objects which are visible to the ant. */ public abstract class AntAI extends AI{ // Note [Visibility] /* * Everything which is intended to be used by the AI writer should be protected * and come first in this file, to aid someone reading through this file to learn * how the game works. * Everything else should not be protected, and not public if possible. * Hopefully, this will make generating documentation for AI writers easier. */ /** Sugar which is seen by self */ public List<Sugar> visibleSugar; /** Hills which are seen by self */ public List<Hill> visibleHills; /** HillMessage which is heard in this tick (null if non existant) */ public HillMessage audibleHillMessage; /** Reference to Ant itself. Use to acces information like health: self.health */ protected Ant self; // user AI may have changed this value! Use antObject instead. //------------------------------------------------------------------------------- // MOVEMENT //------------------------------------------------------------------------------- /** Move in certain direction with maximum distance * @param direction measured in degrees (0 = East, 90 = North, 180 = West, 270 = South) */ protected void moveInDirection(double direction) { moveInDirection(direction, parameters.SIZE_X/2); } /** Move in direction with specified distance * @param direction measured in degrees (0 = East, 90 = North, 180 = West, 270 = South) * @param distance distance to move in one tick */ protected void moveInDirection(double direction, double distance) {
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/AntAI.java import java.util.LinkedList; import java.util.List; import wota.utility.Vector; package wota.gameobjects; /** * Basisclass for antais by the user. * Contains several lists describing the objects which are visible to the ant. */ public abstract class AntAI extends AI{ // Note [Visibility] /* * Everything which is intended to be used by the AI writer should be protected * and come first in this file, to aid someone reading through this file to learn * how the game works. * Everything else should not be protected, and not public if possible. * Hopefully, this will make generating documentation for AI writers easier. */ /** Sugar which is seen by self */ public List<Sugar> visibleSugar; /** Hills which are seen by self */ public List<Hill> visibleHills; /** HillMessage which is heard in this tick (null if non existant) */ public HillMessage audibleHillMessage; /** Reference to Ant itself. Use to acces information like health: self.health */ protected Ant self; // user AI may have changed this value! Use antObject instead. //------------------------------------------------------------------------------- // MOVEMENT //------------------------------------------------------------------------------- /** Move in certain direction with maximum distance * @param direction measured in degrees (0 = East, 90 = North, 180 = West, 270 = South) */ protected void moveInDirection(double direction) { moveInDirection(direction, parameters.SIZE_X/2); } /** Move in direction with specified distance * @param direction measured in degrees (0 = East, 90 = North, 180 = West, 270 = South) * @param distance distance to move in one tick */ protected void moveInDirection(double direction, double distance) {
action.movement = Vector.fromPolar(distance, direction);
wotateam/wota
src/wota/ai/bonnmath/MyHillAI.java
// Path: src/wota/utility/Modulo.java // public class Modulo { // public static int mod(int x, int m) { // int r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // // public static double mod(double x, double m) { // double r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.LinkedList; import wota.utility.Modulo; import wota.utility.Vector;
package wota.ai.bonnmath; public abstract class MyHillAI extends wota.gameobjects.HillAI { public int vecttoint(Vector position){ return (int)(Math.round(parameters.SIZE_Y)*Math.round(position.x+parameters.SIZE_X/2)+Math.round(position.y+parameters.SIZE_Y/2)); } public Vector torus(Vector v){ while(v.x<-parameters.SIZE_X/2){ v.x+=parameters.SIZE_X; } while(v.x>parameters.SIZE_X/2){ v.x-=parameters.SIZE_X; } while(v.y<-parameters.SIZE_Y/2){ v.y+=parameters.SIZE_Y; } while(v.y>parameters.SIZE_Y/2){ v.y-=parameters.SIZE_Y; } return v; } public Vector inttovect(int n){ Vector position=new Vector(0,0); position.x= n/Math.round(parameters.SIZE_Y)-parameters.SIZE_X/2;
// Path: src/wota/utility/Modulo.java // public class Modulo { // public static int mod(int x, int m) { // int r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // // public static double mod(double x, double m) { // double r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/bonnmath/MyHillAI.java import java.util.LinkedList; import wota.utility.Modulo; import wota.utility.Vector; package wota.ai.bonnmath; public abstract class MyHillAI extends wota.gameobjects.HillAI { public int vecttoint(Vector position){ return (int)(Math.round(parameters.SIZE_Y)*Math.round(position.x+parameters.SIZE_X/2)+Math.round(position.y+parameters.SIZE_Y/2)); } public Vector torus(Vector v){ while(v.x<-parameters.SIZE_X/2){ v.x+=parameters.SIZE_X; } while(v.x>parameters.SIZE_X/2){ v.x-=parameters.SIZE_X; } while(v.y<-parameters.SIZE_Y/2){ v.y+=parameters.SIZE_Y; } while(v.y>parameters.SIZE_Y/2){ v.y-=parameters.SIZE_Y; } return v; } public Vector inttovect(int n){ Vector position=new Vector(0,0); position.x= n/Math.round(parameters.SIZE_Y)-parameters.SIZE_X/2;
position.y= Modulo.mod(n,(int)(Math.round(parameters.SIZE_Y)))-parameters.SIZE_Y/2;
wotateam/wota
src/wota/gamemaster/StatisticsLogger.java
// Path: src/wota/gameobjects/GameWorld.java // public class Player { // private final List<AntObject> antObjects = new LinkedList<AntObject>(); // private final List<AntCorpseObject> antCorpseObjects = new LinkedList<AntCorpseObject>(); // private final HillObject hillObject; // // public final String name; // public final String creator; // // private final int id; // // public int id() { // return id; // } // // // TODO make this private and change addPlayer // public Player(Vector position, Class<? extends HillAI> hillAIClass) { // hillObject = new HillObject(position, this, hillAIClass, parameters); // spacePartitioning.addHillObject(getHillObject()); // // name = AILoader.getAIName(hillAIClass); // creator = AILoader.getAICreator(hillAIClass); // // id = nextPlayerId; // nextPlayerId++; // } // // @Override // public String toString() { // return "AI " + (id +1) + " " + name + " written by " + creator; // } // // public synchronized void addAntObject(AntObject antObject) { // getAntObjects().add(antObject); // spacePartitioning.addAntObject(antObject); // } // // /** // * removes antObject from the antObjects list // * @param antObject antObject to remove // */ // public synchronized void removeAntObject(AntObject antObject) { // getAntObjects().remove(antObject); // } // // /** // * @param caste // * @return number of ants of given caste // * @throws NullPointerException if antObjects is null // */ // public synchronized int numAnts(Caste caste) throws NullPointerException{ // int num = 0; // for (AntObject antObject : getAntObjects()) { // if (antObject.caste == caste) { // num++; // } // } // return num; // } // // /** // * @return antObjects // */ // public synchronized List<AntObject> getAntObjects() { // return antObjects; // } // // /** // * @return the antCorpseObjects // */ // public List<AntCorpseObject> getAntCorpseObjects() { // return antCorpseObjects; // } // // /** // * @return the hillObject // */ // public HillObject getHillObject() { // return hillObject; // } // // }
import java.util.List; import wota.gameobjects.*; import wota.gameobjects.GameWorld.Player;
/** * */ package wota.gamemaster; /** * Simple logger which simply counts events */ public class StatisticsLogger implements Logger{ private int createdAnts[]; private int diedAnts[]; private int collectedFood[];
// Path: src/wota/gameobjects/GameWorld.java // public class Player { // private final List<AntObject> antObjects = new LinkedList<AntObject>(); // private final List<AntCorpseObject> antCorpseObjects = new LinkedList<AntCorpseObject>(); // private final HillObject hillObject; // // public final String name; // public final String creator; // // private final int id; // // public int id() { // return id; // } // // // TODO make this private and change addPlayer // public Player(Vector position, Class<? extends HillAI> hillAIClass) { // hillObject = new HillObject(position, this, hillAIClass, parameters); // spacePartitioning.addHillObject(getHillObject()); // // name = AILoader.getAIName(hillAIClass); // creator = AILoader.getAICreator(hillAIClass); // // id = nextPlayerId; // nextPlayerId++; // } // // @Override // public String toString() { // return "AI " + (id +1) + " " + name + " written by " + creator; // } // // public synchronized void addAntObject(AntObject antObject) { // getAntObjects().add(antObject); // spacePartitioning.addAntObject(antObject); // } // // /** // * removes antObject from the antObjects list // * @param antObject antObject to remove // */ // public synchronized void removeAntObject(AntObject antObject) { // getAntObjects().remove(antObject); // } // // /** // * @param caste // * @return number of ants of given caste // * @throws NullPointerException if antObjects is null // */ // public synchronized int numAnts(Caste caste) throws NullPointerException{ // int num = 0; // for (AntObject antObject : getAntObjects()) { // if (antObject.caste == caste) { // num++; // } // } // return num; // } // // /** // * @return antObjects // */ // public synchronized List<AntObject> getAntObjects() { // return antObjects; // } // // /** // * @return the antCorpseObjects // */ // public List<AntCorpseObject> getAntCorpseObjects() { // return antCorpseObjects; // } // // /** // * @return the hillObject // */ // public HillObject getHillObject() { // return hillObject; // } // // } // Path: src/wota/gamemaster/StatisticsLogger.java import java.util.List; import wota.gameobjects.*; import wota.gameobjects.GameWorld.Player; /** * */ package wota.gamemaster; /** * Simple logger which simply counts events */ public class StatisticsLogger implements Logger{ private int createdAnts[]; private int diedAnts[]; private int collectedFood[];
public StatisticsLogger(List<Player> players) {
wotateam/wota
src/wota/gamemaster/AILoader.java
// Path: src/wota/gameobjects/HillAI.java // public abstract class HillAI extends AI { // // see Note [Visibility] in AntAI // // /** Reference to Hill itself */ // protected Hill self; // user AI may have changed this value! Use antObject instead. // // protected void createAnt(Caste caste, Class<? extends AntAI> antAIClass) { // AntOrder antOrder = new AntOrder(caste, antAIClass); // antOrders.add(antOrder); // } // // /* // * Pascal: The constructor must not have any parameters or // * newInstance() will not work. // */ // public HillAI() { // antOrders = new LinkedList<AntOrder>(); // } // // /** Send message of type int */ // protected void talk(int content) { // talk(content, null); // } // // /** Send message of combined int with Snaphshot (Ant, Hill, Sugar, ...) */ // protected void talk(int content, Snapshot snapshot) { // message = new HillMessage(self.getPosition(), self, content, snapshot, parameters); // } // // // ------------------------------------------------------------------------ // // End of methods and fields relevant to AI writers. // // ------------------------------------------------------------------------ // // // /** List of Ants which should be born next tick */ // private List<AntOrder> antOrders; // private HillMessage message; // // /** HillObject includes all information of this Hill */ // private HillObject hillObject; // // /** CAUTION! This will delete the message object in HillAI */ // HillMessage popMessage() { // HillMessage returnMessage = message; // message = null; // return returnMessage; // } // // /** // * DON'T USE THIS METHOD IF YOU ARE PROGRAMMING THE AI ! // */ // void setHill(Hill hill) { // self = hill; // } // // /** CAUTION! THIS METHOD DELETES THE AntOrders */ // List<AntOrder> popAntOrders() { // List<AntOrder> returnAntOrders = antOrders; // antOrders = new LinkedList<AntOrder>(); // return returnAntOrders; // } // // void setHillObject(HillObject hillObject) { // this.hillObject = hillObject; // setPosition ( hillObject.getPosition() ); // } // // HillObject getHillObject(){ // return hillObject; // } // }
import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import wota.gameobjects.HillAI;
package wota.gamemaster; /** * Handles dynamic loading of player AIs. * */ public class AILoader { private String searchpath; private final String AI_PACKAGE = "wota.ai";
// Path: src/wota/gameobjects/HillAI.java // public abstract class HillAI extends AI { // // see Note [Visibility] in AntAI // // /** Reference to Hill itself */ // protected Hill self; // user AI may have changed this value! Use antObject instead. // // protected void createAnt(Caste caste, Class<? extends AntAI> antAIClass) { // AntOrder antOrder = new AntOrder(caste, antAIClass); // antOrders.add(antOrder); // } // // /* // * Pascal: The constructor must not have any parameters or // * newInstance() will not work. // */ // public HillAI() { // antOrders = new LinkedList<AntOrder>(); // } // // /** Send message of type int */ // protected void talk(int content) { // talk(content, null); // } // // /** Send message of combined int with Snaphshot (Ant, Hill, Sugar, ...) */ // protected void talk(int content, Snapshot snapshot) { // message = new HillMessage(self.getPosition(), self, content, snapshot, parameters); // } // // // ------------------------------------------------------------------------ // // End of methods and fields relevant to AI writers. // // ------------------------------------------------------------------------ // // // /** List of Ants which should be born next tick */ // private List<AntOrder> antOrders; // private HillMessage message; // // /** HillObject includes all information of this Hill */ // private HillObject hillObject; // // /** CAUTION! This will delete the message object in HillAI */ // HillMessage popMessage() { // HillMessage returnMessage = message; // message = null; // return returnMessage; // } // // /** // * DON'T USE THIS METHOD IF YOU ARE PROGRAMMING THE AI ! // */ // void setHill(Hill hill) { // self = hill; // } // // /** CAUTION! THIS METHOD DELETES THE AntOrders */ // List<AntOrder> popAntOrders() { // List<AntOrder> returnAntOrders = antOrders; // antOrders = new LinkedList<AntOrder>(); // return returnAntOrders; // } // // void setHillObject(HillObject hillObject) { // this.hillObject = hillObject; // setPosition ( hillObject.getPosition() ); // } // // HillObject getHillObject(){ // return hillObject; // } // } // Path: src/wota/gamemaster/AILoader.java import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import wota.gameobjects.HillAI; package wota.gamemaster; /** * Handles dynamic loading of player AIs. * */ public class AILoader { private String searchpath; private final String AI_PACKAGE = "wota.ai";
private final String HILL_AI_CLASS_NAME = "HillAI";
wotateam/wota
src/wota/ai/pwahs03/SoldierAI.java
// Path: src/wota/ai/pwahs03/HillAI.java // enum SwatStatus{ // GUARDING, // PATROLLING, // ATTACKING // }; // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.ai.pwahs03.HillAI.SwatStatus; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; import java.util.List; import java.util.LinkedList;
first_cry(); listen(); give_orders(); if (target!=null) move(); attack(); } public void fightertick() throws Exception { //System.out.printf("Fighter here, id = %d, time = 00%d, leaderid = %d\n",self.id, time+initialTime, (leader!=null?leader.id:-1)); first_cry(); listen(); get_orders(); if (target!=null) move(); attack(); check_promotion(); } public void move(){
// Path: src/wota/ai/pwahs03/HillAI.java // enum SwatStatus{ // GUARDING, // PATROLLING, // ATTACKING // }; // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs03/SoldierAI.java import wota.ai.pwahs03.HillAI.SwatStatus; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; import java.util.List; import java.util.LinkedList; first_cry(); listen(); give_orders(); if (target!=null) move(); attack(); } public void fightertick() throws Exception { //System.out.printf("Fighter here, id = %d, time = 00%d, leaderid = %d\n",self.id, time+initialTime, (leader!=null?leader.id:-1)); first_cry(); listen(); get_orders(); if (target!=null) move(); attack(); check_promotion(); } public void move(){
Vector pos = target.getPosition();
wotateam/wota
src/wota/ai/template/HillAI.java
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.Caste;
/** * */ package wota.ai.template; /** * Give your information about this HillAI here. */ @AIInformation(creator = "Anonymous", name = "Anonymous's AI") public class HillAI extends wota.gameobjects.HillAI { /* * your Hill is not able to move but can * communicate and create new ants. * * You can create new ants with createAnt(caste, antAIClass) * e.g. if you want a gatherer and the AI * you want use is called SuperGathererAI createAnt(Caste.Gatherer, SuperGathererAI.class) * */ @Override public void tick() throws Exception { /* * try to create an Ant using the TemplateAI in every tick * if you don't have enough food to create the ant your call * will be ignored */
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // Path: src/wota/ai/template/HillAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; /** * */ package wota.ai.template; /** * Give your information about this HillAI here. */ @AIInformation(creator = "Anonymous", name = "Anonymous's AI") public class HillAI extends wota.gameobjects.HillAI { /* * your Hill is not able to move but can * communicate and create new ants. * * You can create new ants with createAnt(caste, antAIClass) * e.g. if you want a gatherer and the AI * you want use is called SuperGathererAI createAnt(Caste.Gatherer, SuperGathererAI.class) * */ @Override public void tick() throws Exception { /* * try to create an Ant using the TemplateAI in every tick * if you don't have enough food to create the ant your call * will be ignored */
createAnt(Caste.Gatherer, TemplateAI.class);
wotateam/wota
src/wota/ai/clonewarriors/HillAI.java
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; import wota.utility.SeededRandomizer;
package wota.ai.clonewarriors; /** * Consists of gatherers and warriors. Gatherers randomly look for sugar and * don't communicate at all. Warriors randomly look for enemies and start an * joint attack on the enemy hills at a certain tick, when order 66 is called ;-) */ @AIInformation(creator = "Elrond1337", name = "Clone Warriors") public class HillAI extends wota.gameobjects.HillAI { int num_tick = 0; @Override public void tick() { num_tick++; int antsToProduce = (int) (self.food / parameters.ANT_COST); for (int i=0; i<antsToProduce; i++) { if (random.nextInt(5) <= 3) {
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // Path: src/wota/ai/clonewarriors/HillAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; import wota.utility.SeededRandomizer; package wota.ai.clonewarriors; /** * Consists of gatherers and warriors. Gatherers randomly look for sugar and * don't communicate at all. Warriors randomly look for enemies and start an * joint attack on the enemy hills at a certain tick, when order 66 is called ;-) */ @AIInformation(creator = "Elrond1337", name = "Clone Warriors") public class HillAI extends wota.gameobjects.HillAI { int num_tick = 0; @Override public void tick() { num_tick++; int antsToProduce = (int) (self.food / parameters.ANT_COST); for (int i=0; i<antsToProduce; i++) { if (random.nextInt(5) <= 3) {
createAnt(Caste.Gatherer, GathererAI.class);
wotateam/wota
src/wota/graphics/PlayerColors.java
// Path: src/wota/utility/Modulo.java // public class Modulo { // public static int mod(int x, int m) { // int r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // // public static double mod(double x, double m) { // double r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // }
import java.awt.Color; import wota.utility.Modulo;
package wota.graphics; /** * Helper class to generate Colors of Players. */ public class PlayerColors { private static final Color[] playerColors = { Color.RED, Color.BLUE, Color.GREEN, Color.CYAN, Color.PINK, Color.MAGENTA, Color.ORANGE, Color.YELLOW }; public static Color get(int i) { if (i < playerColors.length) { return playerColors[i]; } else {
// Path: src/wota/utility/Modulo.java // public class Modulo { // public static int mod(int x, int m) { // int r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // // public static double mod(double x, double m) { // double r = x % m; // if (r < 0) { // return r + m; // } else { // return r; // } // } // } // Path: src/wota/graphics/PlayerColors.java import java.awt.Color; import wota.utility.Modulo; package wota.graphics; /** * Helper class to generate Colors of Players. */ public class PlayerColors { private static final Color[] playerColors = { Color.RED, Color.BLUE, Color.GREEN, Color.CYAN, Color.PINK, Color.MAGENTA, Color.ORANGE, Color.YELLOW }; public static Color get(int i) { if (i < playerColors.length) { return playerColors[i]; } else {
return new Color(Modulo.mod(115*i, 256), Modulo.mod(73*i, 256), Modulo.mod(192*i, 256));
wotateam/wota
src/wota/ai/loadingpleasewait/ScoutAILPW.java
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // }
import wota.gameobjects.Caste; import wota.utility.SeededRandomizer;
package wota.ai.loadingpleasewait; /** * This ant finds sugar. */ public class ScoutAILPW extends AntAILPW { private boolean foundSugar; private boolean checkSugar; @Override public void tick(){ if (getRandomDirection() == -1) {
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // Path: src/wota/ai/loadingpleasewait/ScoutAILPW.java import wota.gameobjects.Caste; import wota.utility.SeededRandomizer; package wota.ai.loadingpleasewait; /** * This ant finds sugar. */ public class ScoutAILPW extends AntAILPW { private boolean foundSugar; private boolean checkSugar; @Override public void tick(){ if (getRandomDirection() == -1) {
setRandomDirection((int) (SeededRandomizer.nextDouble() * 360));
wotateam/wota
src/wota/ai/loadingpleasewait/ScoutAILPW.java
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // }
import wota.gameobjects.Caste; import wota.utility.SeededRandomizer;
package wota.ai.loadingpleasewait; /** * This ant finds sugar. */ public class ScoutAILPW extends AntAILPW { private boolean foundSugar; private boolean checkSugar; @Override public void tick(){ if (getRandomDirection() == -1) { setRandomDirection((int) (SeededRandomizer.nextDouble() * 360)); checkSugar = SeededRandomizer.nextDouble() < 0.4; } if(closest(visibleSugar) != null) setTarget(closest(visibleSugar)); if(canPickUpSugar()) foundSugar = true; //if ant is at the hill go back out again
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // Path: src/wota/ai/loadingpleasewait/ScoutAILPW.java import wota.gameobjects.Caste; import wota.utility.SeededRandomizer; package wota.ai.loadingpleasewait; /** * This ant finds sugar. */ public class ScoutAILPW extends AntAILPW { private boolean foundSugar; private boolean checkSugar; @Override public void tick(){ if (getRandomDirection() == -1) { setRandomDirection((int) (SeededRandomizer.nextDouble() * 360)); checkSugar = SeededRandomizer.nextDouble() < 0.4; } if(closest(visibleSugar) != null) setTarget(closest(visibleSugar)); if(canPickUpSugar()) foundSugar = true; //if ant is at the hill go back out again
if(vectorToHome().length() < Caste.Hill.HEARING_RANGE - 10)
wotateam/wota
src/wota/gameobjects/AntObject.java
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.List; import wota.utility.Vector;
package wota.gameobjects; /** * Internal Reprensantion of Ants. * In contrast to Ant it contains all information and is always up to date. */ public class AntObject extends BaseAntObject{ private static int idCounter = 0; private Ant ant; protected final AntAI antAi; protected double health; private double lastMovementDirection = 0; /** amount of sugar carried now */ private int sugarCarry = 0; private Action action; private boolean isAttacking = false; private AntObject attackTarget = null;
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/AntObject.java import java.util.List; import wota.utility.Vector; package wota.gameobjects; /** * Internal Reprensantion of Ants. * In contrast to Ant it contains all information and is always up to date. */ public class AntObject extends BaseAntObject{ private static int idCounter = 0; private Ant ant; protected final AntAI antAi; protected double health; private double lastMovementDirection = 0; /** amount of sugar carried now */ private int sugarCarry = 0; private Action action; private boolean isAttacking = false; private AntObject attackTarget = null;
public AntObject(Vector position, Caste caste, Class<? extends AntAI> antAIClass,
wotateam/wota
src/wota/ai/bvb/HillAI.java
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.Caste;
package wota.ai.bvb; @AIInformation(creator = "David und Simon", name = "BVB") public class HillAI extends wota.gameobjects.HillAI { int j=0; int n=1; @Override public void tick() throws Exception { for(int i=0;i<1;i++){
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // Path: src/wota/ai/bvb/HillAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; package wota.ai.bvb; @AIInformation(creator = "David und Simon", name = "BVB") public class HillAI extends wota.gameobjects.HillAI { int j=0; int n=1; @Override public void tick() throws Exception { for(int i=0;i<1;i++){
createAnt(Caste.Soldier,Mao.class);
wotateam/wota
src/wota/gameobjects/HillObject.java
// Path: src/wota/gameobjects/Hill.java // public class Hill implements Snapshot{ // /** the amount of available food */ // public final double food; // public HillObject hillObject; // public final Vector position; // public final int playerID; // // Hill(HillObject hillObject) { // this.hillObject = hillObject; // this.playerID = hillObject.getPlayer().id(); // this.food = hillObject.getStoredFood(); // this.position = hillObject.getPosition(); // } // // public Vector getPosition() { // return position; // } // // /* (non-Javadoc) // * @see wota.gameobjects.Snapshot#hasSameOriginal(wota.gameobjects.Snapshot) // */ // @Override // public boolean hasSameOriginal(Snapshot other) { // if (other == null) { // return false; // } // if (other instanceof Hill) { // return ((Hill) other).hillObject.equals(this.hillObject); // } // else { // return false; // } // } // // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.LinkedList; import java.util.List; import wota.gameobjects.Hill; import wota.utility.Vector;
package wota.gameobjects; public class HillObject extends GameObject { private Hill hill; protected final HillAI hillAI; private GameWorld.Player player; private double storedFood; final Caste caste; private List<AntOrder> antOrders = new LinkedList<AntOrder>(); private HillMessage message;
// Path: src/wota/gameobjects/Hill.java // public class Hill implements Snapshot{ // /** the amount of available food */ // public final double food; // public HillObject hillObject; // public final Vector position; // public final int playerID; // // Hill(HillObject hillObject) { // this.hillObject = hillObject; // this.playerID = hillObject.getPlayer().id(); // this.food = hillObject.getStoredFood(); // this.position = hillObject.getPosition(); // } // // public Vector getPosition() { // return position; // } // // /* (non-Javadoc) // * @see wota.gameobjects.Snapshot#hasSameOriginal(wota.gameobjects.Snapshot) // */ // @Override // public boolean hasSameOriginal(Snapshot other) { // if (other == null) { // return false; // } // if (other instanceof Hill) { // return ((Hill) other).hillObject.equals(this.hillObject); // } // else { // return false; // } // } // // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/HillObject.java import java.util.LinkedList; import java.util.List; import wota.gameobjects.Hill; import wota.utility.Vector; package wota.gameobjects; public class HillObject extends GameObject { private Hill hill; protected final HillAI hillAI; private GameWorld.Player player; private double storedFood; final Caste caste; private List<AntOrder> antOrders = new LinkedList<AntOrder>(); private HillMessage message;
public HillObject(Vector position, GameWorld.Player player, Class<? extends HillAI> hillAIClass,
wotateam/wota
src/wota/ai/pwahs05/SoldierAI.java
// Path: src/wota/ai/pwahs05/HillAI.java // enum SwatStatus{ // WAITING, // GUARDING, // PATROLLING, // ATTACKING, // ARRIVING, // ROAMING // }; // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.ai.pwahs05.HillAI.SwatStatus; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector;
/** * */ package wota.ai.pwahs05; /* <-- change this to wota.ai.YOUR_AI_NAME * make sure your file is in the folder /de/wota/ai/YOUR_AI_NAME * and has the }else{ assignment = SwatStatus.ATTACKING; } same name as the class (change TemplateAI to * the name of your choice) */ /** * Put a description of you AI here. */ // Here, you may use spaces, etc., unlike in the package path wota.ai.YOUR_AI_NAME: @AIInformation(creator = "Anonymous", name = "Anonymous's AI") public class SoldierAI extends TalkingAntAI { Snapshot target = null; Snapshot hilltarget = null; boolean leading = false; boolean shouted = false; Ant leader = null;
// Path: src/wota/ai/pwahs05/HillAI.java // enum SwatStatus{ // WAITING, // GUARDING, // PATROLLING, // ATTACKING, // ARRIVING, // ROAMING // }; // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs05/SoldierAI.java import wota.ai.pwahs05.HillAI.SwatStatus; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; /** * */ package wota.ai.pwahs05; /* <-- change this to wota.ai.YOUR_AI_NAME * make sure your file is in the folder /de/wota/ai/YOUR_AI_NAME * and has the }else{ assignment = SwatStatus.ATTACKING; } same name as the class (change TemplateAI to * the name of your choice) */ /** * Put a description of you AI here. */ // Here, you may use spaces, etc., unlike in the package path wota.ai.YOUR_AI_NAME: @AIInformation(creator = "Anonymous", name = "Anonymous's AI") public class SoldierAI extends TalkingAntAI { Snapshot target = null; Snapshot hilltarget = null; boolean leading = false; boolean shouted = false; Ant leader = null;
SwatStatus assignment = SwatStatus.ROAMING;
wotateam/wota
src/wota/ai/pwahs05/SoldierAI.java
// Path: src/wota/ai/pwahs05/HillAI.java // enum SwatStatus{ // WAITING, // GUARDING, // PATROLLING, // ATTACKING, // ARRIVING, // ROAMING // }; // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.ai.pwahs05.HillAI.SwatStatus; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector;
shout(); give_orders(); if (target!=null) move(); attack(); } public void fightertick() throws Exception { //System.out.printf("Fighter here, id = %d, time = 00%d, leaderid = %d\n",self.id, time+initialTime, (leader!=null?leader.id:-1)); first_cry(); if (time == 1) target = visibleHills.get(0); listen(); shout(); get_orders(); if (target!=null) move(); attack(); check_promotion(); }
// Path: src/wota/ai/pwahs05/HillAI.java // enum SwatStatus{ // WAITING, // GUARDING, // PATROLLING, // ATTACKING, // ARRIVING, // ROAMING // }; // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs05/SoldierAI.java import wota.ai.pwahs05.HillAI.SwatStatus; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; shout(); give_orders(); if (target!=null) move(); attack(); } public void fightertick() throws Exception { //System.out.printf("Fighter here, id = %d, time = 00%d, leaderid = %d\n",self.id, time+initialTime, (leader!=null?leader.id:-1)); first_cry(); if (time == 1) target = visibleHills.get(0); listen(); shout(); get_orders(); if (target!=null) move(); attack(); check_promotion(); }
public Vector shift_aside(Vector pos){
wotateam/wota
src/wota/ai/pwahs05/SoldierAI.java
// Path: src/wota/ai/pwahs05/HillAI.java // enum SwatStatus{ // WAITING, // GUARDING, // PATROLLING, // ATTACKING, // ARRIVING, // ROAMING // }; // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.ai.pwahs05.HillAI.SwatStatus; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector;
} } }else{ if (vectorBetween(self, target).length() < self.caste.SIGHT_RANGE) { if (smallerSoldierNearby()) { if (visibleEnemies().size()==0){ target_sugar(); } else { moveToward(getWeakest(visibleEnemies())); attack(getWeakestReachable(visibleEnemies())); } } else { assignment = SwatStatus.GUARDING; hilltarget = target; } } } break; case WAITING: //check if we should switch: System.out.printf("id=%d, WAITING\n", self.id); boolean hear_leader = false; if (time > 2){ for(AntMessage m: audibleAntMessages){ if ((m.content == HillAI.NEW_LEADER /*|| m.content == QueenAI.NEW_TARGET*/) && m.sender.id!=self.id) { hear_leader = true; break; } } if (hear_leader){
// Path: src/wota/ai/pwahs05/HillAI.java // enum SwatStatus{ // WAITING, // GUARDING, // PATROLLING, // ATTACKING, // ARRIVING, // ROAMING // }; // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // // Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs05/SoldierAI.java import wota.ai.pwahs05.HillAI.SwatStatus; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.SeededRandomizer; import wota.utility.Vector; } } }else{ if (vectorBetween(self, target).length() < self.caste.SIGHT_RANGE) { if (smallerSoldierNearby()) { if (visibleEnemies().size()==0){ target_sugar(); } else { moveToward(getWeakest(visibleEnemies())); attack(getWeakestReachable(visibleEnemies())); } } else { assignment = SwatStatus.GUARDING; hilltarget = target; } } } break; case WAITING: //check if we should switch: System.out.printf("id=%d, WAITING\n", self.id); boolean hear_leader = false; if (time > 2){ for(AntMessage m: audibleAntMessages){ if ((m.content == HillAI.NEW_LEADER /*|| m.content == QueenAI.NEW_TARGET*/) && m.sender.id!=self.id) { hear_leader = true; break; } } if (hear_leader){
if (SeededRandomizer.nextDouble()<HillAI.SUGAR_PROB){
wotateam/wota
src/wota/ai/pwahs11/SugarAI.java
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import java.util.ListIterator; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.Vector;
/** * */ package wota.ai.pwahs11; /* <-- change this to wota.ai.YOUR_AI_NAME * make sure your file is in the folder /de/wota/ai/YOUR_AI_NAME * and has the same name as the class (change TemplateAI to * the name of your choice) */ /** * Put a description of you AI here. */ @AIInformation(creator = "Anonymous", name = "Anonymous's AI") public class SugarAI extends TalkingAntAI { double last_health = -1; Snapshot target_sugar = null; Snapshot avoid = null; boolean got_hit_with_sugar = false;
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/ai/pwahs11/SugarAI.java import java.util.ListIterator; import wota.gamemaster.AIInformation; import wota.gameobjects.*; import wota.utility.Vector; /** * */ package wota.ai.pwahs11; /* <-- change this to wota.ai.YOUR_AI_NAME * make sure your file is in the folder /de/wota/ai/YOUR_AI_NAME * and has the same name as the class (change TemplateAI to * the name of your choice) */ /** * Put a description of you AI here. */ @AIInformation(creator = "Anonymous", name = "Anonymous's AI") public class SugarAI extends TalkingAntAI { double last_health = -1; Snapshot target_sugar = null; Snapshot avoid = null; boolean got_hit_with_sugar = false;
Vector siege_position = null;
wotateam/wota
src/wota/ai/solitary/HillAI.java
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; import wota.utility.SeededRandomizer;
package wota.ai.solitary; @AIInformation(creator = "Wota Team", name = "SolitaryAI") public class HillAI extends wota.gameobjects.HillAI { @Override public void tick() { int antsToProduce = (int) (self.food / parameters.ANT_COST); for (int i=0; i<antsToProduce; i++) { if (random.nextInt(5) <= 3) {
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // Path: src/wota/ai/solitary/HillAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; import wota.utility.SeededRandomizer; package wota.ai.solitary; @AIInformation(creator = "Wota Team", name = "SolitaryAI") public class HillAI extends wota.gameobjects.HillAI { @Override public void tick() { int antsToProduce = (int) (self.food / parameters.ANT_COST); for (int i=0; i<antsToProduce; i++) { if (random.nextInt(5) <= 3) {
createAnt(Caste.Gatherer, GathererAI.class);
wotateam/wota
src/wota/ai/firstopponent/HillAI.java
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.Caste;
/** * */ package wota.ai.firstopponent; /** * Give your information about this HillAI here. */ @AIInformation(creator = "Wota Team", name = "A first opponent.") public class HillAI extends wota.gameobjects.HillAI { @Override public void tick() throws Exception { int antsToProduce = (int) (self.food / parameters.ANT_COST); for (int i=0; i<antsToProduce; i++) {
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // Path: src/wota/ai/firstopponent/HillAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; /** * */ package wota.ai.firstopponent; /** * Give your information about this HillAI here. */ @AIInformation(creator = "Wota Team", name = "A first opponent.") public class HillAI extends wota.gameobjects.HillAI { @Override public void tick() throws Exception { int antsToProduce = (int) (self.food / parameters.ANT_COST); for (int i=0; i<antsToProduce; i++) {
createAnt(Caste.Gatherer, GathererAI.class);
wotateam/wota
src/wota/gamemaster/Logger.java
// Path: src/wota/gameobjects/GameWorld.java // public class Player { // private final List<AntObject> antObjects = new LinkedList<AntObject>(); // private final List<AntCorpseObject> antCorpseObjects = new LinkedList<AntCorpseObject>(); // private final HillObject hillObject; // // public final String name; // public final String creator; // // private final int id; // // public int id() { // return id; // } // // // TODO make this private and change addPlayer // public Player(Vector position, Class<? extends HillAI> hillAIClass) { // hillObject = new HillObject(position, this, hillAIClass, parameters); // spacePartitioning.addHillObject(getHillObject()); // // name = AILoader.getAIName(hillAIClass); // creator = AILoader.getAICreator(hillAIClass); // // id = nextPlayerId; // nextPlayerId++; // } // // @Override // public String toString() { // return "AI " + (id +1) + " " + name + " written by " + creator; // } // // public synchronized void addAntObject(AntObject antObject) { // getAntObjects().add(antObject); // spacePartitioning.addAntObject(antObject); // } // // /** // * removes antObject from the antObjects list // * @param antObject antObject to remove // */ // public synchronized void removeAntObject(AntObject antObject) { // getAntObjects().remove(antObject); // } // // /** // * @param caste // * @return number of ants of given caste // * @throws NullPointerException if antObjects is null // */ // public synchronized int numAnts(Caste caste) throws NullPointerException{ // int num = 0; // for (AntObject antObject : getAntObjects()) { // if (antObject.caste == caste) { // num++; // } // } // return num; // } // // /** // * @return antObjects // */ // public synchronized List<AntObject> getAntObjects() { // return antObjects; // } // // /** // * @return the antCorpseObjects // */ // public List<AntCorpseObject> getAntCorpseObjects() { // return antCorpseObjects; // } // // /** // * @return the hillObject // */ // public HillObject getHillObject() { // return hillObject; // } // // }
import wota.gameobjects.*; import wota.gameobjects.GameWorld.Player;
package wota.gamemaster; /** * Interface for all loggers. * Thinkable loggers print debugging messages to the console * or simply count events for the statistic * * log gets called by e.g. GameWorld */ public interface Logger { public void antCreated(AntObject antObject); public void antDied(AntObject antObject);
// Path: src/wota/gameobjects/GameWorld.java // public class Player { // private final List<AntObject> antObjects = new LinkedList<AntObject>(); // private final List<AntCorpseObject> antCorpseObjects = new LinkedList<AntCorpseObject>(); // private final HillObject hillObject; // // public final String name; // public final String creator; // // private final int id; // // public int id() { // return id; // } // // // TODO make this private and change addPlayer // public Player(Vector position, Class<? extends HillAI> hillAIClass) { // hillObject = new HillObject(position, this, hillAIClass, parameters); // spacePartitioning.addHillObject(getHillObject()); // // name = AILoader.getAIName(hillAIClass); // creator = AILoader.getAICreator(hillAIClass); // // id = nextPlayerId; // nextPlayerId++; // } // // @Override // public String toString() { // return "AI " + (id +1) + " " + name + " written by " + creator; // } // // public synchronized void addAntObject(AntObject antObject) { // getAntObjects().add(antObject); // spacePartitioning.addAntObject(antObject); // } // // /** // * removes antObject from the antObjects list // * @param antObject antObject to remove // */ // public synchronized void removeAntObject(AntObject antObject) { // getAntObjects().remove(antObject); // } // // /** // * @param caste // * @return number of ants of given caste // * @throws NullPointerException if antObjects is null // */ // public synchronized int numAnts(Caste caste) throws NullPointerException{ // int num = 0; // for (AntObject antObject : getAntObjects()) { // if (antObject.caste == caste) { // num++; // } // } // return num; // } // // /** // * @return antObjects // */ // public synchronized List<AntObject> getAntObjects() { // return antObjects; // } // // /** // * @return the antCorpseObjects // */ // public List<AntCorpseObject> getAntCorpseObjects() { // return antCorpseObjects; // } // // /** // * @return the hillObject // */ // public HillObject getHillObject() { // return hillObject; // } // // } // Path: src/wota/gamemaster/Logger.java import wota.gameobjects.*; import wota.gameobjects.GameWorld.Player; package wota.gamemaster; /** * Interface for all loggers. * Thinkable loggers print debugging messages to the console * or simply count events for the statistic * * log gets called by e.g. GameWorld */ public interface Logger { public void antCreated(AntObject antObject); public void antDied(AntObject antObject);
public void antCollectedFood(Player player, int amount);
wotateam/wota
src/wota/gameobjects/Sugar.java
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // }
import wota.utility.Vector;
package wota.gameobjects; /** * Large amount of sugar which wants to be collected * */ public class Sugar implements Snapshot { public final int amount; public final double radius;
// Path: src/wota/utility/Vector.java // public class Vector { // // /** x Coordinate */ // public double x; // // /** y Coordinate */ // public double y; // // /** Constructs a vector with x and y Coordinate */ // public Vector(double x, double y) { // this.x = x; // this.y = y; // } // // public Vector(Vector v) { // this.x = v.x; // this.y = v.y; // } // // /** @return The length of the vector. */ // public double length() { // return Math.sqrt(x*x + y*y); // } // // /** does not change instance */ // public Vector scale(double a) { // return Vector.scale(a, this); // } // // /** prints vector like: "Vector: x = 5; y = 3" */ // @Override // public String toString() { // return "Vector: x = " + x + "; y = " + y; // } // // /** returns this Vector scaled to specified length // * does not change instance */ // public Vector scaleTo(double length) { // return Vector.scale(length / this.length(), this); // } // // /** returns the polar coordinate of the vector // * special case: null vector returns 0.0 // * @return angle in degrees */ // public double angle() { // return Math.atan2(y, x)/(2.*Math.PI)*360.; // } // // public Vector boundLengthBy(double maximumLength) { // if (length() > maximumLength) { // return this.scaleTo(maximumLength); // } else { // return new Vector(this); // Optimization: Change x and y to be final and get rid of this. // } // } // // /** returns the sum of p1 and p2 */ // public static Vector add(final Vector p1, final Vector p2) { // return new Vector(p1.x + p2.x, p1.y + p2.y); // } // // /** returns the vector p, scaled by scaling_factor */ // public static Vector scale(double scalingFactor, final Vector p) { // return new Vector(p.x * scalingFactor, p.y * scalingFactor); // } // // public boolean isSameVectorAs(Vector other) { // return (subtract(this, other).length() < 1.e-8); // } // // /** creates a vector from polar coordinates. // * // * @param amplitude length of the vector // * @param direction phi-component. direction = 0 generates a vector along the x-axis. // * @return vector in x-y-coordinates // */ // public static Vector fromPolar(double amplitude, double direction) { // return new Vector(amplitude*Math.cos(direction/360.*2*Math.PI), amplitude*Math.sin(direction/360.*2*Math.PI)); // } // // /** // * Scalar product of the two vectors // * @param v1 // * @param v2 // * @return // */ // public static double scalarProduct(Vector v1, Vector v2) { // return v1.x * v2.x + v1.y * v2.y; // } // // /** // * returns the result of v1 - v2 // */ // public static Vector subtract(Vector v1, Vector v2) { // return new Vector(v1.x - v2.x, v1.y - v2.y); // } // } // Path: src/wota/gameobjects/Sugar.java import wota.utility.Vector; package wota.gameobjects; /** * Large amount of sugar which wants to be collected * */ public class Sugar implements Snapshot { public final int amount; public final double radius;
public final Vector position;
wotateam/wota
src/wota/ai/pwahs11/TalkingAntAI.java
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // }
import java.util.LinkedList; import java.util.List; import wota.gameobjects.*; import wota.utility.SeededRandomizer;
if (indices[nr_hill] >= hills[nr_hill].size()) indices[nr_hill] = 0; if (nr_hill==HillAI.NOSUGAR_IND && indices[nr_hill] + HillAI.SHOUT_LAST_NOSUGAR < hills[nr_hill].size()){ indices[nr_hill] = hills[nr_hill].size() - HillAI.SHOUT_LAST_NOSUGAR; } SnapshotMessagePair sm = hills[nr_hill].get(indices[nr_hill]); talk(sm.m.encode(),sm.s); } public void first_steps(){ if (time == 1){ //was just born, figure out time and directions: //find time: if (audibleHillMessage != null){ if (audibleHillMessage.content < 0) { initialTime = audibleHillMessage.content - HillAI.OFFSET_TIME; } } if (initialTime==1) { //in the beginning, figure out direction: int count = 0; int total = 0; for (Ant a: visibleFriends()) { if (a.caste.compareTo(self.caste) == 0) { total++; if (a.id < self.id) count++; } } dir = (360*(count - (count % 2) * HillAI.STARTER_PAIRING))/(total+1); }else{//later, just go some random direction:
// Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // Path: src/wota/ai/pwahs11/TalkingAntAI.java import java.util.LinkedList; import java.util.List; import wota.gameobjects.*; import wota.utility.SeededRandomizer; if (indices[nr_hill] >= hills[nr_hill].size()) indices[nr_hill] = 0; if (nr_hill==HillAI.NOSUGAR_IND && indices[nr_hill] + HillAI.SHOUT_LAST_NOSUGAR < hills[nr_hill].size()){ indices[nr_hill] = hills[nr_hill].size() - HillAI.SHOUT_LAST_NOSUGAR; } SnapshotMessagePair sm = hills[nr_hill].get(indices[nr_hill]); talk(sm.m.encode(),sm.s); } public void first_steps(){ if (time == 1){ //was just born, figure out time and directions: //find time: if (audibleHillMessage != null){ if (audibleHillMessage.content < 0) { initialTime = audibleHillMessage.content - HillAI.OFFSET_TIME; } } if (initialTime==1) { //in the beginning, figure out direction: int count = 0; int total = 0; for (Ant a: visibleFriends()) { if (a.caste.compareTo(self.caste) == 0) { total++; if (a.id < self.id) count++; } } dir = (360*(count - (count % 2) * HillAI.STARTER_PAIRING))/(total+1); }else{//later, just go some random direction:
dir = SeededRandomizer.nextDouble()*360;
wotateam/wota
src/wota/ai/bienemaja/HillAI.java
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // }
import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; import wota.utility.SeededRandomizer;
/** * */ package wota.ai.bienemaja; /** * Give your information about this HillAI here. */ @AIInformation(creator = "Simon", name = "Bienenkoenigin") public class HillAI extends MyHillAI { /* * your Hill is not able to move but can * communicate and create new ants. * * You can create new ants with createAnt(caste, antAIClass) * e.g. if you want a gatherer and the AI * you want use is called SuperGathererAI createAnt(Caste.Gatherer, SuperGathererAI.class) * */ @Override public void tick() throws Exception { /* * try to create an Ant using the TemplateAI in every tick * if you don't have enough food to create the ant your call * will be ignored */ double food=self.food; dowhatcanbedone(); if(time==1){
// Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // // Path: src/wota/utility/SeededRandomizer.java // public class SeededRandomizer { // private static long seed; // private static final Random internalRandom = new Random(); // // public static final SeededRandomizer random = new SeededRandomizer(); // // public static void resetSeed(long seed) { // SeededRandomizer.seed = seed; // internalRandom.setSeed(seed); // } // // /* I think this will only lead to confusion // public static int nextInt() { // return internalRandom.nextInt(); // } */ // // /** // * returns a internalRandom integer number between 0 and n-1 // * @param n Upper bound for internalRandom number // * @return a internalRandom integer number between 0 and n-1 // */ // public static int nextInt(int n) { // return internalRandom.nextInt(n); // } // // public static long nextLong() { // return internalRandom.nextLong(); // } // // /** // * @return Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 // */ // public static double nextDouble() // { // return internalRandom.nextDouble(); // } // // public static long getSeed() // { // return seed; // } // } // Path: src/wota/ai/bienemaja/HillAI.java import wota.gamemaster.AIInformation; import wota.gameobjects.Caste; import wota.utility.SeededRandomizer; /** * */ package wota.ai.bienemaja; /** * Give your information about this HillAI here. */ @AIInformation(creator = "Simon", name = "Bienenkoenigin") public class HillAI extends MyHillAI { /* * your Hill is not able to move but can * communicate and create new ants. * * You can create new ants with createAnt(caste, antAIClass) * e.g. if you want a gatherer and the AI * you want use is called SuperGathererAI createAnt(Caste.Gatherer, SuperGathererAI.class) * */ @Override public void tick() throws Exception { /* * try to create an Ant using the TemplateAI in every tick * if you don't have enough food to create the ant your call * will be ignored */ double food=self.food; dowhatcanbedone(); if(time==1){
createAnt(Caste.Scout, Huepfer.class);
wotateam/wota
src/wota/ai/loadingpleasewait/PatrollAntAI.java
// Path: src/wota/gameobjects/Ant.java // public class Ant extends BaseAnt { // // /** health is decreased by attacking enemies. Ant dies if health reaches 0. */ // public final double health; // // /** amount of sugar which is carried */ // public final int sugarCarry; // // /** The name of this ant's AI class, not including the package name.*/ // public final String antAIClassName; // // /** corresponding physical element of this Ant */ // final AntObject antObject; // should only be accessible for objects in the same package // // Ant(AntObject antObject) { // super(antObject); // health = antObject.getHealth(); // sugarCarry = antObject.getSugarCarry(); // antAIClassName = antObject.getAI().getClass().getSimpleName(); // this.antObject = antObject; // } // // /* (non-Javadoc) // * @see wota.gameobjects.Snapshot#hasSameOriginal(wota.gameobjects.Snapshot) // */ // @Override // public boolean hasSameOriginal(Snapshot other) { // if (other == null) { // return false; // } // if (other instanceof Ant) { // return ((Ant) other).antObject.equals(this.antObject); // } // else { // return false; // } // } // // } // // Path: src/wota/gameobjects/AntMessage.java // public class AntMessage extends Message { // // /** Ant which has send the message */ // public final Ant sender; // // public AntMessage(Vector position, Ant sender, int content, // Snapshot snapshot, Parameters parameters) { // super(position, content, snapshot, parameters); // this.sender = sender; // } // // @Override // public String toString() { // return new String(sender + ": " + super.toString()); // } // } // // Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // }
import wota.gameobjects.AntMessage; import wota.gameobjects.Caste; import java.util.LinkedList; import wota.gameobjects.Ant;
/** * */ package wota.ai.loadingpleasewait; /** * This ant protects the gatherers insert pun about the word troll here */ public class PatrollAntAI extends AntAILPW { private static final int TARGET_DOWN = -4;
// Path: src/wota/gameobjects/Ant.java // public class Ant extends BaseAnt { // // /** health is decreased by attacking enemies. Ant dies if health reaches 0. */ // public final double health; // // /** amount of sugar which is carried */ // public final int sugarCarry; // // /** The name of this ant's AI class, not including the package name.*/ // public final String antAIClassName; // // /** corresponding physical element of this Ant */ // final AntObject antObject; // should only be accessible for objects in the same package // // Ant(AntObject antObject) { // super(antObject); // health = antObject.getHealth(); // sugarCarry = antObject.getSugarCarry(); // antAIClassName = antObject.getAI().getClass().getSimpleName(); // this.antObject = antObject; // } // // /* (non-Javadoc) // * @see wota.gameobjects.Snapshot#hasSameOriginal(wota.gameobjects.Snapshot) // */ // @Override // public boolean hasSameOriginal(Snapshot other) { // if (other == null) { // return false; // } // if (other instanceof Ant) { // return ((Ant) other).antObject.equals(this.antObject); // } // else { // return false; // } // } // // } // // Path: src/wota/gameobjects/AntMessage.java // public class AntMessage extends Message { // // /** Ant which has send the message */ // public final Ant sender; // // public AntMessage(Vector position, Ant sender, int content, // Snapshot snapshot, Parameters parameters) { // super(position, content, snapshot, parameters); // this.sender = sender; // } // // @Override // public String toString() { // return new String(sender + ": " + super.toString()); // } // } // // Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // Path: src/wota/ai/loadingpleasewait/PatrollAntAI.java import wota.gameobjects.AntMessage; import wota.gameobjects.Caste; import java.util.LinkedList; import wota.gameobjects.Ant; /** * */ package wota.ai.loadingpleasewait; /** * This ant protects the gatherers insert pun about the word troll here */ public class PatrollAntAI extends AntAILPW { private static final int TARGET_DOWN = -4;
private LinkedList<Ant> deadEnemies = new LinkedList<Ant>();
wotateam/wota
src/wota/ai/loadingpleasewait/PatrollAntAI.java
// Path: src/wota/gameobjects/Ant.java // public class Ant extends BaseAnt { // // /** health is decreased by attacking enemies. Ant dies if health reaches 0. */ // public final double health; // // /** amount of sugar which is carried */ // public final int sugarCarry; // // /** The name of this ant's AI class, not including the package name.*/ // public final String antAIClassName; // // /** corresponding physical element of this Ant */ // final AntObject antObject; // should only be accessible for objects in the same package // // Ant(AntObject antObject) { // super(antObject); // health = antObject.getHealth(); // sugarCarry = antObject.getSugarCarry(); // antAIClassName = antObject.getAI().getClass().getSimpleName(); // this.antObject = antObject; // } // // /* (non-Javadoc) // * @see wota.gameobjects.Snapshot#hasSameOriginal(wota.gameobjects.Snapshot) // */ // @Override // public boolean hasSameOriginal(Snapshot other) { // if (other == null) { // return false; // } // if (other instanceof Ant) { // return ((Ant) other).antObject.equals(this.antObject); // } // else { // return false; // } // } // // } // // Path: src/wota/gameobjects/AntMessage.java // public class AntMessage extends Message { // // /** Ant which has send the message */ // public final Ant sender; // // public AntMessage(Vector position, Ant sender, int content, // Snapshot snapshot, Parameters parameters) { // super(position, content, snapshot, parameters); // this.sender = sender; // } // // @Override // public String toString() { // return new String(sender + ": " + super.toString()); // } // } // // Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // }
import wota.gameobjects.AntMessage; import wota.gameobjects.Caste; import java.util.LinkedList; import wota.gameobjects.Ant;
/** * */ package wota.ai.loadingpleasewait; /** * This ant protects the gatherers insert pun about the word troll here */ public class PatrollAntAI extends AntAILPW { private static final int TARGET_DOWN = -4; private LinkedList<Ant> deadEnemies = new LinkedList<Ant>(); private LinkedList<Ant> friendlyGatherers = new LinkedList<Ant>(); private Ant enemyThreat; @Override public void tick() {
// Path: src/wota/gameobjects/Ant.java // public class Ant extends BaseAnt { // // /** health is decreased by attacking enemies. Ant dies if health reaches 0. */ // public final double health; // // /** amount of sugar which is carried */ // public final int sugarCarry; // // /** The name of this ant's AI class, not including the package name.*/ // public final String antAIClassName; // // /** corresponding physical element of this Ant */ // final AntObject antObject; // should only be accessible for objects in the same package // // Ant(AntObject antObject) { // super(antObject); // health = antObject.getHealth(); // sugarCarry = antObject.getSugarCarry(); // antAIClassName = antObject.getAI().getClass().getSimpleName(); // this.antObject = antObject; // } // // /* (non-Javadoc) // * @see wota.gameobjects.Snapshot#hasSameOriginal(wota.gameobjects.Snapshot) // */ // @Override // public boolean hasSameOriginal(Snapshot other) { // if (other == null) { // return false; // } // if (other instanceof Ant) { // return ((Ant) other).antObject.equals(this.antObject); // } // else { // return false; // } // } // // } // // Path: src/wota/gameobjects/AntMessage.java // public class AntMessage extends Message { // // /** Ant which has send the message */ // public final Ant sender; // // public AntMessage(Vector position, Ant sender, int content, // Snapshot snapshot, Parameters parameters) { // super(position, content, snapshot, parameters); // this.sender = sender; // } // // @Override // public String toString() { // return new String(sender + ": " + super.toString()); // } // } // // Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // Path: src/wota/ai/loadingpleasewait/PatrollAntAI.java import wota.gameobjects.AntMessage; import wota.gameobjects.Caste; import java.util.LinkedList; import wota.gameobjects.Ant; /** * */ package wota.ai.loadingpleasewait; /** * This ant protects the gatherers insert pun about the word troll here */ public class PatrollAntAI extends AntAILPW { private static final int TARGET_DOWN = -4; private LinkedList<Ant> deadEnemies = new LinkedList<Ant>(); private LinkedList<Ant> friendlyGatherers = new LinkedList<Ant>(); private Ant enemyThreat; @Override public void tick() {
assert (self.caste.equals(Caste.Soldier)) : "Patrol ant was a " + self.caste;
wotateam/wota
src/wota/ai/loadingpleasewait/PatrollAntAI.java
// Path: src/wota/gameobjects/Ant.java // public class Ant extends BaseAnt { // // /** health is decreased by attacking enemies. Ant dies if health reaches 0. */ // public final double health; // // /** amount of sugar which is carried */ // public final int sugarCarry; // // /** The name of this ant's AI class, not including the package name.*/ // public final String antAIClassName; // // /** corresponding physical element of this Ant */ // final AntObject antObject; // should only be accessible for objects in the same package // // Ant(AntObject antObject) { // super(antObject); // health = antObject.getHealth(); // sugarCarry = antObject.getSugarCarry(); // antAIClassName = antObject.getAI().getClass().getSimpleName(); // this.antObject = antObject; // } // // /* (non-Javadoc) // * @see wota.gameobjects.Snapshot#hasSameOriginal(wota.gameobjects.Snapshot) // */ // @Override // public boolean hasSameOriginal(Snapshot other) { // if (other == null) { // return false; // } // if (other instanceof Ant) { // return ((Ant) other).antObject.equals(this.antObject); // } // else { // return false; // } // } // // } // // Path: src/wota/gameobjects/AntMessage.java // public class AntMessage extends Message { // // /** Ant which has send the message */ // public final Ant sender; // // public AntMessage(Vector position, Ant sender, int content, // Snapshot snapshot, Parameters parameters) { // super(position, content, snapshot, parameters); // this.sender = sender; // } // // @Override // public String toString() { // return new String(sender + ": " + super.toString()); // } // } // // Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // }
import wota.gameobjects.AntMessage; import wota.gameobjects.Caste; import java.util.LinkedList; import wota.gameobjects.Ant;
// protect the hill attack(closest(visibleEnemies())); if(vectorToHome().length() > 20 || visibleEnemies().isEmpty()) moveHome(); else moveToward(closest(visibleEnemies())); setHomeUnderAttack(enemySoldierCount() > 0); } else if (enemyThreat == null) { super.tick(); } else { attack(enemyThreat); if(!friendlyGatherers.isEmpty() && enemyThreat.caste.equals(Caste.Soldier)) moveToward(enemyThreat); } if (enemyThreat != null) { if (enemyThreat.health > 0.2 && enemyThreat.caste.equals(Caste.Soldier)) talk(AntAILPW.BACKUP_CALL, enemyThreat); else talk(PatrollAntAI.TARGET_DOWN, enemyThreat); } setLastLocation(self.getPosition()); } @Override protected void listen() { super.listen(); enemyThreat = null; //listen to information on enemy ants
// Path: src/wota/gameobjects/Ant.java // public class Ant extends BaseAnt { // // /** health is decreased by attacking enemies. Ant dies if health reaches 0. */ // public final double health; // // /** amount of sugar which is carried */ // public final int sugarCarry; // // /** The name of this ant's AI class, not including the package name.*/ // public final String antAIClassName; // // /** corresponding physical element of this Ant */ // final AntObject antObject; // should only be accessible for objects in the same package // // Ant(AntObject antObject) { // super(antObject); // health = antObject.getHealth(); // sugarCarry = antObject.getSugarCarry(); // antAIClassName = antObject.getAI().getClass().getSimpleName(); // this.antObject = antObject; // } // // /* (non-Javadoc) // * @see wota.gameobjects.Snapshot#hasSameOriginal(wota.gameobjects.Snapshot) // */ // @Override // public boolean hasSameOriginal(Snapshot other) { // if (other == null) { // return false; // } // if (other instanceof Ant) { // return ((Ant) other).antObject.equals(this.antObject); // } // else { // return false; // } // } // // } // // Path: src/wota/gameobjects/AntMessage.java // public class AntMessage extends Message { // // /** Ant which has send the message */ // public final Ant sender; // // public AntMessage(Vector position, Ant sender, int content, // Snapshot snapshot, Parameters parameters) { // super(position, content, snapshot, parameters); // this.sender = sender; // } // // @Override // public String toString() { // return new String(sender + ": " + super.toString()); // } // } // // Path: src/wota/gameobjects/Caste.java // public enum Caste { // Gatherer( // 40.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.15, // ATTACK // 10, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Soldier( // 100.0, // INITIAL_HEALTH // 10.0, // SPEED // 5.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.2, // ATTACK // 5, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ), // // Scout( // 100, // INITIAL_HEALTH // 15.0, // SPEED // 15.0, // SPEED_WHILE_ATTACKING // 5.0, // SPEED_WHILE_CARRYING_SUGAR // 0.0, // ATTACK // 0, // MAX_SUGAR_CARRY // 100, // SIGHT_RANGE // 100 // HEARING_RANGE TODO should hearing range == sight range? // ), // // Hill( // 0, // INITIAL_HEALTH // 0, // SPEED // 0, // SPEED_WHILE_ATTACKING // 0, // SPEED_WHILE_CARRYING_SUGAR // 0, // ATTACK // 0, // MAX_SUGAR_CARRY // 50, // SIGHT_RANGE // 50 // HEARING_RANGE // ); // // public final double INITIAL_HEALTH; // public final double SPEED; // public final double SPEED_WHILE_ATTACKING; // public final double SPEED_WHILE_CARRYING_SUGAR; // /** Damage caused when attacking */ // public final double ATTACK; // public final int MAX_SUGAR_CARRY; // public final double SIGHT_RANGE; // public final double HEARING_RANGE; // // private Caste( // double INITIAL_HEALTH, // double SPEED, // double SPEED_WHILE_ATTACKING, // double SPEED_WHILE_CARRYING_SUGAR, // double ATTACK, // int MAX_SUGAR_CARRY, // double SIGHT_RANGE, // double HEARING_RANGE) { // this.INITIAL_HEALTH = INITIAL_HEALTH; // this.SPEED = SPEED; // this.SPEED_WHILE_ATTACKING = SPEED_WHILE_ATTACKING; // this.SPEED_WHILE_CARRYING_SUGAR = SPEED_WHILE_CARRYING_SUGAR; // this.ATTACK = ATTACK; // this.MAX_SUGAR_CARRY = MAX_SUGAR_CARRY; // this.SIGHT_RANGE = SIGHT_RANGE; // this.HEARING_RANGE = HEARING_RANGE; // } // } // Path: src/wota/ai/loadingpleasewait/PatrollAntAI.java import wota.gameobjects.AntMessage; import wota.gameobjects.Caste; import java.util.LinkedList; import wota.gameobjects.Ant; // protect the hill attack(closest(visibleEnemies())); if(vectorToHome().length() > 20 || visibleEnemies().isEmpty()) moveHome(); else moveToward(closest(visibleEnemies())); setHomeUnderAttack(enemySoldierCount() > 0); } else if (enemyThreat == null) { super.tick(); } else { attack(enemyThreat); if(!friendlyGatherers.isEmpty() && enemyThreat.caste.equals(Caste.Soldier)) moveToward(enemyThreat); } if (enemyThreat != null) { if (enemyThreat.health > 0.2 && enemyThreat.caste.equals(Caste.Soldier)) talk(AntAILPW.BACKUP_CALL, enemyThreat); else talk(PatrollAntAI.TARGET_DOWN, enemyThreat); } setLastLocation(self.getPosition()); } @Override protected void listen() { super.listen(); enemyThreat = null; //listen to information on enemy ants
for (AntMessage message : audibleAntMessages) {
R2RML-api/R2RML-api
r2rml-api-rdf4j-binding/src/test/java/rdf4jTest/RDFStar_Test.java
// Path: r2rml-api-rdf4j-binding/src/main/java/eu/optique/r2rml/api/binding/rdf4j/RDF4JR2RMLMappingManager.java // public class RDF4JR2RMLMappingManager extends R2RMLMappingManagerImpl { // // private static RDF4JR2RMLMappingManager INSTANCE = new RDF4JR2RMLMappingManager(new RDF4J()); // // private RDF4JR2RMLMappingManager(RDF4J rdf) { // super(rdf); // } // // public Collection<TriplesMap> importMappings(Model model) throws InvalidR2RMLMappingException { // return importMappings(((RDF4J) getRDF()).asGraph(model)); // } // // @Override // public RDF4JGraph exportMappings(Collection<TriplesMap> maps) { // return (RDF4JGraph) super.exportMappings(maps); // } // // public static RDF4JR2RMLMappingManager getInstance(){ // return INSTANCE; // } // } // // Path: r2rml-api-core/src/main/java/eu/optique/r2rml/api/model/impl/SQLBaseTableOrViewImpl.java // public class SQLBaseTableOrViewImpl extends LogicalTableImpl implements SQLBaseTableOrView { // // String table; // // public SQLBaseTableOrViewImpl(RDF c, String tableName) { // super(c); // // setTableName(tableName); // // setNode(getRDF().createBlankNode()); // } // // @Override // public void setTableName(String tableName) { // if (tableName != null) { // table = tableName; // } else { // throw new NullPointerException("A SQLBaseTableOrView must have a table name."); // } // } // // @Override // public String getTableName() { // return table; // } // // @Override // public String getSQLQuery() { // return "SELECT * FROM " + table; // } // // @Override // public Set<Triple> serialize() { // Set<Triple> stmtSet = new HashSet<Triple>(); // // stmtSet.add(getRDF().createTriple(node, getRDF().createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), getRDF().createIRI(R2RMLVocabulary.TYPE_BASE_TABLE_OR_VIEW))); // // stmtSet.add(getRDF().createTriple(node, getRDF().createIRI(R2RMLVocabulary.PROP_TABLE_NAME), // getRDF().createLiteral(getTableName()))); // // return stmtSet; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((node == null) ? 0 : node.hashCode()); // result = prime * result + ((table == null) ? 0 : table.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // // if (obj == null) // return false; // // if (!(obj instanceof SQLBaseTableOrViewImpl)) // return false; // // SQLBaseTableOrViewImpl other = (SQLBaseTableOrViewImpl) obj; // if (node == null) { // if (other.node != null) { // return false; // } // } else if (!node.equals(other.node)) { // return false; // } // // if (table == null) { // if (other.table != null) { // return false; // } // } else if (!table.equals(other.table)) { // return false; // } // // return true; // } // // @Override // public String toString() { // return "SQLBaseTableOrViewImpl [table=" + table + ", node=" + node + "]"; // } // // }
import eu.optique.r2rml.api.binding.rdf4j.RDF4JR2RMLMappingManager; import eu.optique.r2rml.api.model.*; import eu.optique.r2rml.api.model.impl.SQLBaseTableOrViewImpl; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.impl.LinkedHashModel; import org.eclipse.rdf4j.rio.RDFFormat; import org.eclipse.rdf4j.rio.RDFParser; import org.eclipse.rdf4j.rio.Rio; import org.eclipse.rdf4j.rio.helpers.StatementCollector; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import java.io.InputStream; import java.util.Collection; import java.util.Iterator;
package rdf4jTest; /** * JUnit Test Cases for RDFStar support * * @author Lukas Sundqvist */ public class RDFStar_Test { @Test public void test1() throws Exception{ InputStream fis = getClass().getResourceAsStream("../mappingFiles/prof-rdfstar.ttl");
// Path: r2rml-api-rdf4j-binding/src/main/java/eu/optique/r2rml/api/binding/rdf4j/RDF4JR2RMLMappingManager.java // public class RDF4JR2RMLMappingManager extends R2RMLMappingManagerImpl { // // private static RDF4JR2RMLMappingManager INSTANCE = new RDF4JR2RMLMappingManager(new RDF4J()); // // private RDF4JR2RMLMappingManager(RDF4J rdf) { // super(rdf); // } // // public Collection<TriplesMap> importMappings(Model model) throws InvalidR2RMLMappingException { // return importMappings(((RDF4J) getRDF()).asGraph(model)); // } // // @Override // public RDF4JGraph exportMappings(Collection<TriplesMap> maps) { // return (RDF4JGraph) super.exportMappings(maps); // } // // public static RDF4JR2RMLMappingManager getInstance(){ // return INSTANCE; // } // } // // Path: r2rml-api-core/src/main/java/eu/optique/r2rml/api/model/impl/SQLBaseTableOrViewImpl.java // public class SQLBaseTableOrViewImpl extends LogicalTableImpl implements SQLBaseTableOrView { // // String table; // // public SQLBaseTableOrViewImpl(RDF c, String tableName) { // super(c); // // setTableName(tableName); // // setNode(getRDF().createBlankNode()); // } // // @Override // public void setTableName(String tableName) { // if (tableName != null) { // table = tableName; // } else { // throw new NullPointerException("A SQLBaseTableOrView must have a table name."); // } // } // // @Override // public String getTableName() { // return table; // } // // @Override // public String getSQLQuery() { // return "SELECT * FROM " + table; // } // // @Override // public Set<Triple> serialize() { // Set<Triple> stmtSet = new HashSet<Triple>(); // // stmtSet.add(getRDF().createTriple(node, getRDF().createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), getRDF().createIRI(R2RMLVocabulary.TYPE_BASE_TABLE_OR_VIEW))); // // stmtSet.add(getRDF().createTriple(node, getRDF().createIRI(R2RMLVocabulary.PROP_TABLE_NAME), // getRDF().createLiteral(getTableName()))); // // return stmtSet; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + ((node == null) ? 0 : node.hashCode()); // result = prime * result + ((table == null) ? 0 : table.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // // if (obj == null) // return false; // // if (!(obj instanceof SQLBaseTableOrViewImpl)) // return false; // // SQLBaseTableOrViewImpl other = (SQLBaseTableOrViewImpl) obj; // if (node == null) { // if (other.node != null) { // return false; // } // } else if (!node.equals(other.node)) { // return false; // } // // if (table == null) { // if (other.table != null) { // return false; // } // } else if (!table.equals(other.table)) { // return false; // } // // return true; // } // // @Override // public String toString() { // return "SQLBaseTableOrViewImpl [table=" + table + ", node=" + node + "]"; // } // // } // Path: r2rml-api-rdf4j-binding/src/test/java/rdf4jTest/RDFStar_Test.java import eu.optique.r2rml.api.binding.rdf4j.RDF4JR2RMLMappingManager; import eu.optique.r2rml.api.model.*; import eu.optique.r2rml.api.model.impl.SQLBaseTableOrViewImpl; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.impl.LinkedHashModel; import org.eclipse.rdf4j.rio.RDFFormat; import org.eclipse.rdf4j.rio.RDFParser; import org.eclipse.rdf4j.rio.Rio; import org.eclipse.rdf4j.rio.helpers.StatementCollector; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import java.io.InputStream; import java.util.Collection; import java.util.Iterator; package rdf4jTest; /** * JUnit Test Cases for RDFStar support * * @author Lukas Sundqvist */ public class RDFStar_Test { @Test public void test1() throws Exception{ InputStream fis = getClass().getResourceAsStream("../mappingFiles/prof-rdfstar.ttl");
RDF4JR2RMLMappingManager mm = RDF4JR2RMLMappingManager.getInstance();
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/data/api/DashboardRetrofitApi.java
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/DashboardEndpoint.java // public interface DashboardEndpoint { // @GET("v1/gifs/trending") // Call<DashboardListEndpointResponse> getDashboard(@Query("api_key") String apiKey); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/model/DashboardListEndpointResponse.java // public class DashboardListEndpointResponse { // public List<DashboardEndpointResponse> data; // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // }
import java.util.ArrayList; import java.util.List; import javax.inject.Inject; import retrofit2.Call; import retrofit2.Response; import com.txusballesteros.testing.data.api.endpoint.DashboardEndpoint; import com.txusballesteros.testing.data.api.endpoint.model.DashboardListEndpointResponse; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import java.io.IOException;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.api; public class DashboardRetrofitApi extends AbsRetrofitApi implements DashboardApi { private final DashboardEndpoint endpoint;
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/DashboardEndpoint.java // public interface DashboardEndpoint { // @GET("v1/gifs/trending") // Call<DashboardListEndpointResponse> getDashboard(@Query("api_key") String apiKey); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/model/DashboardListEndpointResponse.java // public class DashboardListEndpointResponse { // public List<DashboardEndpointResponse> data; // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // } // Path: app/src/main/java/com/txusballesteros/testing/data/api/DashboardRetrofitApi.java import java.util.ArrayList; import java.util.List; import javax.inject.Inject; import retrofit2.Call; import retrofit2.Response; import com.txusballesteros.testing.data.api.endpoint.DashboardEndpoint; import com.txusballesteros.testing.data.api.endpoint.model.DashboardListEndpointResponse; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import java.io.IOException; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.api; public class DashboardRetrofitApi extends AbsRetrofitApi implements DashboardApi { private final DashboardEndpoint endpoint;
private final ImageResponseMapper mapper;
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/data/api/DashboardRetrofitApi.java
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/DashboardEndpoint.java // public interface DashboardEndpoint { // @GET("v1/gifs/trending") // Call<DashboardListEndpointResponse> getDashboard(@Query("api_key") String apiKey); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/model/DashboardListEndpointResponse.java // public class DashboardListEndpointResponse { // public List<DashboardEndpointResponse> data; // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // }
import java.util.ArrayList; import java.util.List; import javax.inject.Inject; import retrofit2.Call; import retrofit2.Response; import com.txusballesteros.testing.data.api.endpoint.DashboardEndpoint; import com.txusballesteros.testing.data.api.endpoint.model.DashboardListEndpointResponse; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import java.io.IOException;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.api; public class DashboardRetrofitApi extends AbsRetrofitApi implements DashboardApi { private final DashboardEndpoint endpoint; private final ImageResponseMapper mapper; @Inject public DashboardRetrofitApi(DashboardEndpoint endpoint, ImageResponseMapper mapper) { this.endpoint = endpoint; this.mapper = mapper; } @Override
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/DashboardEndpoint.java // public interface DashboardEndpoint { // @GET("v1/gifs/trending") // Call<DashboardListEndpointResponse> getDashboard(@Query("api_key") String apiKey); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/model/DashboardListEndpointResponse.java // public class DashboardListEndpointResponse { // public List<DashboardEndpointResponse> data; // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // } // Path: app/src/main/java/com/txusballesteros/testing/data/api/DashboardRetrofitApi.java import java.util.ArrayList; import java.util.List; import javax.inject.Inject; import retrofit2.Call; import retrofit2.Response; import com.txusballesteros.testing.data.api.endpoint.DashboardEndpoint; import com.txusballesteros.testing.data.api.endpoint.model.DashboardListEndpointResponse; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import java.io.IOException; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.api; public class DashboardRetrofitApi extends AbsRetrofitApi implements DashboardApi { private final DashboardEndpoint endpoint; private final ImageResponseMapper mapper; @Inject public DashboardRetrofitApi(DashboardEndpoint endpoint, ImageResponseMapper mapper) { this.endpoint = endpoint; this.mapper = mapper; } @Override
public List<ImageResponse> getDashboard() {
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/data/api/DashboardRetrofitApi.java
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/DashboardEndpoint.java // public interface DashboardEndpoint { // @GET("v1/gifs/trending") // Call<DashboardListEndpointResponse> getDashboard(@Query("api_key") String apiKey); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/model/DashboardListEndpointResponse.java // public class DashboardListEndpointResponse { // public List<DashboardEndpointResponse> data; // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // }
import java.util.ArrayList; import java.util.List; import javax.inject.Inject; import retrofit2.Call; import retrofit2.Response; import com.txusballesteros.testing.data.api.endpoint.DashboardEndpoint; import com.txusballesteros.testing.data.api.endpoint.model.DashboardListEndpointResponse; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import java.io.IOException;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.api; public class DashboardRetrofitApi extends AbsRetrofitApi implements DashboardApi { private final DashboardEndpoint endpoint; private final ImageResponseMapper mapper; @Inject public DashboardRetrofitApi(DashboardEndpoint endpoint, ImageResponseMapper mapper) { this.endpoint = endpoint; this.mapper = mapper; } @Override public List<ImageResponse> getDashboard() { List<ImageResponse> result = new ArrayList<>(); try {
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/DashboardEndpoint.java // public interface DashboardEndpoint { // @GET("v1/gifs/trending") // Call<DashboardListEndpointResponse> getDashboard(@Query("api_key") String apiKey); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/model/DashboardListEndpointResponse.java // public class DashboardListEndpointResponse { // public List<DashboardEndpointResponse> data; // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // } // Path: app/src/main/java/com/txusballesteros/testing/data/api/DashboardRetrofitApi.java import java.util.ArrayList; import java.util.List; import javax.inject.Inject; import retrofit2.Call; import retrofit2.Response; import com.txusballesteros.testing.data.api.endpoint.DashboardEndpoint; import com.txusballesteros.testing.data.api.endpoint.model.DashboardListEndpointResponse; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import java.io.IOException; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.api; public class DashboardRetrofitApi extends AbsRetrofitApi implements DashboardApi { private final DashboardEndpoint endpoint; private final ImageResponseMapper mapper; @Inject public DashboardRetrofitApi(DashboardEndpoint endpoint, ImageResponseMapper mapper) { this.endpoint = endpoint; this.mapper = mapper; } @Override public List<ImageResponse> getDashboard() { List<ImageResponse> result = new ArrayList<>(); try {
final Call<DashboardListEndpointResponse> apiCaller = endpoint.getDashboard(API_KEY);
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractorUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { }
import org.junit.Test; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.List; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractorUnitTest extends UnitTest { @Mock ThreadExecutor threadExecutorMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { } // Path: app/src/test/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractorUnitTest.java import org.junit.Test; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.List; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractorUnitTest extends UnitTest { @Mock ThreadExecutor threadExecutorMock;
@Mock PostExecutionThread postExecutionThreadMock;
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractorUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { }
import org.junit.Test; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.List; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractorUnitTest extends UnitTest { @Mock ThreadExecutor threadExecutorMock; @Mock PostExecutionThread postExecutionThreadMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { } // Path: app/src/test/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractorUnitTest.java import org.junit.Test; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.List; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractorUnitTest extends UnitTest { @Mock ThreadExecutor threadExecutorMock; @Mock PostExecutionThread postExecutionThreadMock;
@Mock DashboardRepository dashboardRepositoryMock;
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractorUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { }
import org.junit.Test; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.List; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractorUnitTest extends UnitTest { @Mock ThreadExecutor threadExecutorMock; @Mock PostExecutionThread postExecutionThreadMock; @Mock DashboardRepository dashboardRepositoryMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { } // Path: app/src/test/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractorUnitTest.java import org.junit.Test; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.List; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractorUnitTest extends UnitTest { @Mock ThreadExecutor threadExecutorMock; @Mock PostExecutionThread postExecutionThreadMock; @Mock DashboardRepository dashboardRepositoryMock;
@Mock GetDashboardUseCase.Callback callbackMock;
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractorUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { }
import org.junit.Test; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.List; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractorUnitTest extends UnitTest { @Mock ThreadExecutor threadExecutorMock; @Mock PostExecutionThread postExecutionThreadMock; @Mock DashboardRepository dashboardRepositoryMock; @Mock GetDashboardUseCase.Callback callbackMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { } // Path: app/src/test/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractorUnitTest.java import org.junit.Test; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.List; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractorUnitTest extends UnitTest { @Mock ThreadExecutor threadExecutorMock; @Mock PostExecutionThread postExecutionThreadMock; @Mock DashboardRepository dashboardRepositoryMock; @Mock GetDashboardUseCase.Callback callbackMock;
@Mock List<Image> repositoryResultMock;
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/view/MainActivity.java
// Path: app/src/main/java/com/txusballesteros/testing/presentation/MainPresenter.java // public interface MainPresenter { // void onStart(); // void onStop(); // // interface View { // void renderDashboard(List<ImageModel> images); // void renderError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/model/ImageModel.java // public class ImageModel { // private Uri url; // // private ImageModel() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageModel image; // // public Builder() { // this.image = new ImageModel(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageModel build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/instrumentation/ImageLoader.java // public interface ImageLoader { // void loadImageAsGif(Uri imageUrl, ImageView imageView); // }
import com.txusballesteros.testing.view.instrumentation.ImageLoader; import java.util.List; import javax.inject.Inject; import butterknife.Bind; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import com.txusballesteros.testing.R; import com.txusballesteros.testing.presentation.MainPresenter; import com.txusballesteros.testing.presentation.model.ImageModel;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.view; public class MainActivity extends AbsActivity implements MainPresenter.View { @Inject MainPresenter presenter;
// Path: app/src/main/java/com/txusballesteros/testing/presentation/MainPresenter.java // public interface MainPresenter { // void onStart(); // void onStop(); // // interface View { // void renderDashboard(List<ImageModel> images); // void renderError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/model/ImageModel.java // public class ImageModel { // private Uri url; // // private ImageModel() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageModel image; // // public Builder() { // this.image = new ImageModel(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageModel build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/instrumentation/ImageLoader.java // public interface ImageLoader { // void loadImageAsGif(Uri imageUrl, ImageView imageView); // } // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java import com.txusballesteros.testing.view.instrumentation.ImageLoader; import java.util.List; import javax.inject.Inject; import butterknife.Bind; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import com.txusballesteros.testing.R; import com.txusballesteros.testing.presentation.MainPresenter; import com.txusballesteros.testing.presentation.model.ImageModel; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.view; public class MainActivity extends AbsActivity implements MainPresenter.View { @Inject MainPresenter presenter;
@Inject ImageLoader imageLoader;
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/view/MainActivity.java
// Path: app/src/main/java/com/txusballesteros/testing/presentation/MainPresenter.java // public interface MainPresenter { // void onStart(); // void onStop(); // // interface View { // void renderDashboard(List<ImageModel> images); // void renderError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/model/ImageModel.java // public class ImageModel { // private Uri url; // // private ImageModel() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageModel image; // // public Builder() { // this.image = new ImageModel(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageModel build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/instrumentation/ImageLoader.java // public interface ImageLoader { // void loadImageAsGif(Uri imageUrl, ImageView imageView); // }
import com.txusballesteros.testing.view.instrumentation.ImageLoader; import java.util.List; import javax.inject.Inject; import butterknife.Bind; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import com.txusballesteros.testing.R; import com.txusballesteros.testing.presentation.MainPresenter; import com.txusballesteros.testing.presentation.model.ImageModel;
@Override void onViewReady() { initializeList(); } private void initializeList() { listAdapter = new DashboardListAdapter(this, imageLoader); listView.setLayoutManager(new GridLayoutManager(this, 2)); listView.setHasFixedSize(true); listView.setAdapter(listAdapter); } @Override void onInitializeInjection() { getDependenciesInjector().inject(this); } @Override protected void onStart() { super.onStart(); presenter.onStart(); } @Override protected void onStop() { super.onStop(); presenter.onStop(); } @Override
// Path: app/src/main/java/com/txusballesteros/testing/presentation/MainPresenter.java // public interface MainPresenter { // void onStart(); // void onStop(); // // interface View { // void renderDashboard(List<ImageModel> images); // void renderError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/model/ImageModel.java // public class ImageModel { // private Uri url; // // private ImageModel() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageModel image; // // public Builder() { // this.image = new ImageModel(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageModel build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/instrumentation/ImageLoader.java // public interface ImageLoader { // void loadImageAsGif(Uri imageUrl, ImageView imageView); // } // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java import com.txusballesteros.testing.view.instrumentation.ImageLoader; import java.util.List; import javax.inject.Inject; import butterknife.Bind; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import com.txusballesteros.testing.R; import com.txusballesteros.testing.presentation.MainPresenter; import com.txusballesteros.testing.presentation.model.ImageModel; @Override void onViewReady() { initializeList(); } private void initializeList() { listAdapter = new DashboardListAdapter(this, imageLoader); listView.setLayoutManager(new GridLayoutManager(this, 2)); listView.setHasFixedSize(true); listView.setAdapter(listAdapter); } @Override void onInitializeInjection() { getDependenciesInjector().inject(this); } @Override protected void onStart() { super.onStart(); presenter.onStart(); } @Override protected void onStop() { super.onStop(); presenter.onStop(); } @Override
public void renderDashboard(List<ImageModel> images) {
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractor.java
// Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { }
import java.util.List; import javax.inject.Inject; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractor extends AbsInteractor implements GetDashboardUseCase, Runnable { private final ThreadExecutor executor;
// Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { } // Path: app/src/main/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractor.java import java.util.List; import javax.inject.Inject; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractor extends AbsInteractor implements GetDashboardUseCase, Runnable { private final ThreadExecutor executor;
private final PostExecutionThread postExecution;
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractor.java
// Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { }
import java.util.List; import javax.inject.Inject; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractor extends AbsInteractor implements GetDashboardUseCase, Runnable { private final ThreadExecutor executor; private final PostExecutionThread postExecution;
// Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { } // Path: app/src/main/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractor.java import java.util.List; import javax.inject.Inject; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractor extends AbsInteractor implements GetDashboardUseCase, Runnable { private final ThreadExecutor executor; private final PostExecutionThread postExecution;
private final DashboardRepository repository;
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractor.java
// Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { }
import java.util.List; import javax.inject.Inject; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractor extends AbsInteractor implements GetDashboardUseCase, Runnable { private final ThreadExecutor executor; private final PostExecutionThread postExecution; private final DashboardRepository repository; private Callback callback; @Inject public GetDashboardInteractor(ThreadExecutor executor, PostExecutionThread postExecution, DashboardRepository repository) { this.executor = executor; this.postExecution = postExecution; this.repository = repository; } @Override public void execute(final Callback callback) { this.callback = callback; this.executor.execute(this); } @Override public void run() { repository.getDashboard(new DashboardRepository.Callback() { @Override
// Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/GetDashboardUseCase.java // public interface GetDashboardUseCase { // void execute(final Callback callback); // // interface Callback { // void onDashboardReady(List<Image> images); // void onError(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/PostExecutionThread.java // public interface PostExecutionThread { // void post(Runnable runnable); // } // // Path: app/src/main/java/com/txusballesteros/testing/threading/ThreadExecutor.java // public interface ThreadExecutor extends Executor { } // Path: app/src/main/java/com/txusballesteros/testing/domain/interactor/GetDashboardInteractor.java import java.util.List; import javax.inject.Inject; import com.txusballesteros.testing.domain.model.Image; import com.txusballesteros.testing.domain.repository.DashboardRepository; import com.txusballesteros.testing.domain.usecase.GetDashboardUseCase; import com.txusballesteros.testing.threading.PostExecutionThread; import com.txusballesteros.testing.threading.ThreadExecutor; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.interactor; public class GetDashboardInteractor extends AbsInteractor implements GetDashboardUseCase, Runnable { private final ThreadExecutor executor; private final PostExecutionThread postExecution; private final DashboardRepository repository; private Callback callback; @Inject public GetDashboardInteractor(ThreadExecutor executor, PostExecutionThread postExecution, DashboardRepository repository) { this.executor = executor; this.postExecution = postExecution; this.repository = repository; } @Override public void execute(final Callback callback) { this.callback = callback; this.executor.execute(this); } @Override public void run() { repository.getDashboard(new DashboardRepository.Callback() { @Override
public void onSuccess(final List<Image> images) {
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ActivityModule.java // public interface ActivityModule { // Activity provideActivity(); // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import dagger.Module; import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import com.txusballesteros.testing.view.internal.di.ActivityModule; import com.txusballesteros.testing.view.internal.di.ViewModule;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.instrumentation.view.internal.di; @Module(includes = { ViewModule.class,
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ActivityModule.java // public interface ActivityModule { // Activity provideActivity(); // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java import dagger.Module; import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import com.txusballesteros.testing.view.internal.di.ActivityModule; import com.txusballesteros.testing.view.internal.di.ViewModule; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.instrumentation.view.internal.di; @Module(includes = { ViewModule.class,
PresentationModule.class,
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ActivityModule.java // public interface ActivityModule { // Activity provideActivity(); // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import dagger.Module; import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import com.txusballesteros.testing.view.internal.di.ActivityModule; import com.txusballesteros.testing.view.internal.di.ViewModule;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.instrumentation.view.internal.di; @Module(includes = { ViewModule.class, PresentationModule.class,
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ActivityModule.java // public interface ActivityModule { // Activity provideActivity(); // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java import dagger.Module; import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import com.txusballesteros.testing.view.internal.di.ActivityModule; import com.txusballesteros.testing.view.internal.di.ViewModule; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.instrumentation.view.internal.di; @Module(includes = { ViewModule.class, PresentationModule.class,
UseCasesModule.class
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ActivityModule.java // public interface ActivityModule { // Activity provideActivity(); // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import dagger.Module; import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import com.txusballesteros.testing.view.internal.di.ActivityModule; import com.txusballesteros.testing.view.internal.di.ViewModule;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.instrumentation.view.internal.di; @Module(includes = { ViewModule.class, PresentationModule.class, UseCasesModule.class })
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ActivityModule.java // public interface ActivityModule { // Activity provideActivity(); // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java import dagger.Module; import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import com.txusballesteros.testing.view.internal.di.ActivityModule; import com.txusballesteros.testing.view.internal.di.ViewModule; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.instrumentation.view.internal.di; @Module(includes = { ViewModule.class, PresentationModule.class, UseCasesModule.class })
public class TestingActivityModule implements ActivityModule {
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // }
import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import dagger.Module;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.view.internal.di; @Module( includes = { ViewModule.class,
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import dagger.Module; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.view.internal.di; @Module( includes = { ViewModule.class,
PresentationModule.class,
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // }
import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import dagger.Module;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.view.internal.di; @Module( includes = { ViewModule.class, PresentationModule.class,
// Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java import dagger.Provides; import android.app.Activity; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; import dagger.Module; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.view.internal.di; @Module( includes = { ViewModule.class, PresentationModule.class,
UseCasesModule.class
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java
// Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // }
import com.txusballesteros.testing.domain.model.Image; import java.util.List;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.repository; public interface DashboardRepository { void getDashboard(final Callback callback); interface Callback {
// Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java import com.txusballesteros.testing.domain.model.Image; import java.util.List; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.domain.repository; public interface DashboardRepository { void getDashboard(final Callback callback); interface Callback {
void onSuccess(final List<Image> images);
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/integration/internal/di/IntegrationTestComponent.java
// Path: app/src/androidTest/java/com/txusballesteros/testing/integration/api/DashboardApiIntegrationTest.java // @LargeTest // public class DashboardApiIntegrationTest extends IntegrationTest { // @Inject DashboardApi api; // // @Override // protected void onInitializeInjection() { // DaggerIntegrationTestComponent.builder() // .build() // .inject(this); // } // // @Test // public void shouldGetDashboard() { // final List<ImageResponse> response = api.getDashboard(); // // assertNotNull(response); // assertFalse(response.isEmpty()); // } // }
import com.txusballesteros.testing.integration.api.DashboardApiIntegrationTest; import javax.inject.Singleton; import dagger.Component;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.integration.internal.di; @Singleton @Component( modules = IntegrationTestModule.class ) public interface IntegrationTestComponent {
// Path: app/src/androidTest/java/com/txusballesteros/testing/integration/api/DashboardApiIntegrationTest.java // @LargeTest // public class DashboardApiIntegrationTest extends IntegrationTest { // @Inject DashboardApi api; // // @Override // protected void onInitializeInjection() { // DaggerIntegrationTestComponent.builder() // .build() // .inject(this); // } // // @Test // public void shouldGetDashboard() { // final List<ImageResponse> response = api.getDashboard(); // // assertNotNull(response); // assertFalse(response.isEmpty()); // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/integration/internal/di/IntegrationTestComponent.java import com.txusballesteros.testing.integration.api.DashboardApiIntegrationTest; import javax.inject.Singleton; import dagger.Component; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.integration.internal.di; @Singleton @Component( modules = IntegrationTestModule.class ) public interface IntegrationTestComponent {
void inject(DashboardApiIntegrationTest test);
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/presentation/MainPresenter.java
// Path: app/src/main/java/com/txusballesteros/testing/presentation/model/ImageModel.java // public class ImageModel { // private Uri url; // // private ImageModel() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageModel image; // // public Builder() { // this.image = new ImageModel(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageModel build() { // return image; // } // } // }
import com.txusballesteros.testing.presentation.model.ImageModel; import java.util.List;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.presentation; public interface MainPresenter { void onStart(); void onStop(); interface View {
// Path: app/src/main/java/com/txusballesteros/testing/presentation/model/ImageModel.java // public class ImageModel { // private Uri url; // // private ImageModel() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageModel image; // // public Builder() { // this.image = new ImageModel(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageModel build() { // return image; // } // } // } // Path: app/src/main/java/com/txusballesteros/testing/presentation/MainPresenter.java import com.txusballesteros.testing.presentation.model.ImageModel; import java.util.List; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.presentation; public interface MainPresenter { void onStart(); void onStop(); interface View {
void renderDashboard(List<ImageModel> images);
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/integration/internal/di/IntegrationTestModule.java
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/internal/di/EndpointsModule.java // @Module // public class EndpointsModule { // private static final String BASE_URL = "http://api.giphy.com/"; // // @Provides @Singleton // DashboardEndpoint provideDashboardEndpoint() { // return getRetrofitBuilder().create(DashboardEndpoint.class); // } // // private Retrofit getRetrofitBuilder() { // return new Retrofit.Builder() // .baseUrl(BASE_URL) // .addConverterFactory(GsonConverterFactory.create()) // .build(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/internal/di/ApiModule.java // @Module // public class ApiModule { // @Provides // DashboardApi provideDashboardApi(DashboardRetrofitApi api) { // return api; // } // // @Provides // ImageResponseMapper provideImageResponseMapper(ImageResponseMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/transformer/internal/di/TranformerModule.java // @Module // public class TranformerModule { // @Provides @Singleton // ImageUriTransformer provideImageUriTransformer(GiphyImageUriTransformer transformer) { // return transformer; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // }
import dagger.Module; import com.txusballesteros.testing.data.api.endpoint.internal.di.EndpointsModule; import com.txusballesteros.testing.data.api.internal.di.ApiModule; import com.txusballesteros.testing.data.api.transformer.internal.di.TranformerModule; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.integration.internal.di; @Module (includes = { ApiModule.class,
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/internal/di/EndpointsModule.java // @Module // public class EndpointsModule { // private static final String BASE_URL = "http://api.giphy.com/"; // // @Provides @Singleton // DashboardEndpoint provideDashboardEndpoint() { // return getRetrofitBuilder().create(DashboardEndpoint.class); // } // // private Retrofit getRetrofitBuilder() { // return new Retrofit.Builder() // .baseUrl(BASE_URL) // .addConverterFactory(GsonConverterFactory.create()) // .build(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/internal/di/ApiModule.java // @Module // public class ApiModule { // @Provides // DashboardApi provideDashboardApi(DashboardRetrofitApi api) { // return api; // } // // @Provides // ImageResponseMapper provideImageResponseMapper(ImageResponseMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/transformer/internal/di/TranformerModule.java // @Module // public class TranformerModule { // @Provides @Singleton // ImageUriTransformer provideImageUriTransformer(GiphyImageUriTransformer transformer) { // return transformer; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/integration/internal/di/IntegrationTestModule.java import dagger.Module; import com.txusballesteros.testing.data.api.endpoint.internal.di.EndpointsModule; import com.txusballesteros.testing.data.api.internal.di.ApiModule; import com.txusballesteros.testing.data.api.transformer.internal.di.TranformerModule; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.integration.internal.di; @Module (includes = { ApiModule.class,
EndpointsModule.class,
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/integration/internal/di/IntegrationTestModule.java
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/internal/di/EndpointsModule.java // @Module // public class EndpointsModule { // private static final String BASE_URL = "http://api.giphy.com/"; // // @Provides @Singleton // DashboardEndpoint provideDashboardEndpoint() { // return getRetrofitBuilder().create(DashboardEndpoint.class); // } // // private Retrofit getRetrofitBuilder() { // return new Retrofit.Builder() // .baseUrl(BASE_URL) // .addConverterFactory(GsonConverterFactory.create()) // .build(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/internal/di/ApiModule.java // @Module // public class ApiModule { // @Provides // DashboardApi provideDashboardApi(DashboardRetrofitApi api) { // return api; // } // // @Provides // ImageResponseMapper provideImageResponseMapper(ImageResponseMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/transformer/internal/di/TranformerModule.java // @Module // public class TranformerModule { // @Provides @Singleton // ImageUriTransformer provideImageUriTransformer(GiphyImageUriTransformer transformer) { // return transformer; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // }
import dagger.Module; import com.txusballesteros.testing.data.api.endpoint.internal.di.EndpointsModule; import com.txusballesteros.testing.data.api.internal.di.ApiModule; import com.txusballesteros.testing.data.api.transformer.internal.di.TranformerModule; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.integration.internal.di; @Module (includes = { ApiModule.class, EndpointsModule.class,
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/internal/di/EndpointsModule.java // @Module // public class EndpointsModule { // private static final String BASE_URL = "http://api.giphy.com/"; // // @Provides @Singleton // DashboardEndpoint provideDashboardEndpoint() { // return getRetrofitBuilder().create(DashboardEndpoint.class); // } // // private Retrofit getRetrofitBuilder() { // return new Retrofit.Builder() // .baseUrl(BASE_URL) // .addConverterFactory(GsonConverterFactory.create()) // .build(); // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/internal/di/ApiModule.java // @Module // public class ApiModule { // @Provides // DashboardApi provideDashboardApi(DashboardRetrofitApi api) { // return api; // } // // @Provides // ImageResponseMapper provideImageResponseMapper(ImageResponseMapperImpl mapper) { // return mapper; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/transformer/internal/di/TranformerModule.java // @Module // public class TranformerModule { // @Provides @Singleton // ImageUriTransformer provideImageUriTransformer(GiphyImageUriTransformer transformer) { // return transformer; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/usecase/internal/di/UseCasesModule.java // @Module // public class UseCasesModule { // @Provides // GetDashboardUseCase provideGetUseCase(GetDashboardInteractor interactor) { // return interactor; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/presentation/internal/di/PresentationModule.java // @Module // public class PresentationModule { // @Provides // MainPresenter provideMainPresenter(MainPresenterImpl presenter) { // return presenter; // } // // @Provides // ImageModelMapper provideImageModelMapper(ImageModelMapperImpl mapper) { // return mapper; // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/integration/internal/di/IntegrationTestModule.java import dagger.Module; import com.txusballesteros.testing.data.api.endpoint.internal.di.EndpointsModule; import com.txusballesteros.testing.data.api.internal.di.ApiModule; import com.txusballesteros.testing.data.api.transformer.internal.di.TranformerModule; import com.txusballesteros.testing.domain.usecase.internal.di.UseCasesModule; import com.txusballesteros.testing.presentation.internal.di.PresentationModule; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.integration.internal.di; @Module (includes = { ApiModule.class, EndpointsModule.class,
TranformerModule.class
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/internal/di/TestingDependenciesInjector.java
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java // @Module(includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // }) // public class TestingActivityModule implements ActivityModule { // private final Activity activity; // // public TestingActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.instrumentation.view.internal.di.DaggerTestingActivityComponent; import com.txusballesteros.testing.instrumentation.view.internal.di.TestingActivityModule; import com.txusballesteros.testing.view.MainActivity;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class TestingDependenciesInjector implements DependenciesInjector { @Override
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java // @Module(includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // }) // public class TestingActivityModule implements ActivityModule { // private final Activity activity; // // public TestingActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/internal/di/TestingDependenciesInjector.java import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.instrumentation.view.internal.di.DaggerTestingActivityComponent; import com.txusballesteros.testing.instrumentation.view.internal.di.TestingActivityModule; import com.txusballesteros.testing.view.MainActivity; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class TestingDependenciesInjector implements DependenciesInjector { @Override
public void inject(MainActivity client) {
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/internal/di/TestingDependenciesInjector.java
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java // @Module(includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // }) // public class TestingActivityModule implements ActivityModule { // private final Activity activity; // // public TestingActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.instrumentation.view.internal.di.DaggerTestingActivityComponent; import com.txusballesteros.testing.instrumentation.view.internal.di.TestingActivityModule; import com.txusballesteros.testing.view.MainActivity;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class TestingDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerTestingActivityComponent.builder() .applicationComponent(getApplicationComponent(client))
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java // @Module(includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // }) // public class TestingActivityModule implements ActivityModule { // private final Activity activity; // // public TestingActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/internal/di/TestingDependenciesInjector.java import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.instrumentation.view.internal.di.DaggerTestingActivityComponent; import com.txusballesteros.testing.instrumentation.view.internal.di.TestingActivityModule; import com.txusballesteros.testing.view.MainActivity; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class TestingDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerTestingActivityComponent.builder() .applicationComponent(getApplicationComponent(client))
.testingActivityModule(new TestingActivityModule(client))
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/internal/di/TestingDependenciesInjector.java
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java // @Module(includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // }) // public class TestingActivityModule implements ActivityModule { // private final Activity activity; // // public TestingActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.instrumentation.view.internal.di.DaggerTestingActivityComponent; import com.txusballesteros.testing.instrumentation.view.internal.di.TestingActivityModule; import com.txusballesteros.testing.view.MainActivity;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class TestingDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerTestingActivityComponent.builder() .applicationComponent(getApplicationComponent(client)) .testingActivityModule(new TestingActivityModule(client))
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java // @Module(includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // }) // public class TestingActivityModule implements ActivityModule { // private final Activity activity; // // public TestingActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/internal/di/TestingDependenciesInjector.java import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.instrumentation.view.internal.di.DaggerTestingActivityComponent; import com.txusballesteros.testing.instrumentation.view.internal.di.TestingActivityModule; import com.txusballesteros.testing.view.MainActivity; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class TestingDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerTestingActivityComponent.builder() .applicationComponent(getApplicationComponent(client)) .testingActivityModule(new TestingActivityModule(client))
.viewModule(new ViewModule(client))
txusballesteros/Android-Clean-Testing
app/src/androidTest/java/com/txusballesteros/testing/internal/di/TestingDependenciesInjector.java
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java // @Module(includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // }) // public class TestingActivityModule implements ActivityModule { // private final Activity activity; // // public TestingActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.instrumentation.view.internal.di.DaggerTestingActivityComponent; import com.txusballesteros.testing.instrumentation.view.internal.di.TestingActivityModule; import com.txusballesteros.testing.view.MainActivity;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class TestingDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerTestingActivityComponent.builder() .applicationComponent(getApplicationComponent(client)) .testingActivityModule(new TestingActivityModule(client)) .viewModule(new ViewModule(client)) .build() .inject(client); } private ApplicationComponent getApplicationComponent(Activity activity) {
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/androidTest/java/com/txusballesteros/testing/instrumentation/view/internal/di/TestingActivityModule.java // @Module(includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // }) // public class TestingActivityModule implements ActivityModule { // private final Activity activity; // // public TestingActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/androidTest/java/com/txusballesteros/testing/internal/di/TestingDependenciesInjector.java import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.instrumentation.view.internal.di.DaggerTestingActivityComponent; import com.txusballesteros.testing.instrumentation.view.internal.di.TestingActivityModule; import com.txusballesteros.testing.view.MainActivity; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class TestingDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerTestingActivityComponent.builder() .applicationComponent(getApplicationComponent(client)) .testingActivityModule(new TestingActivityModule(client)) .viewModule(new ViewModule(client)) .build() .inject(client); } private ApplicationComponent getApplicationComponent(Activity activity) {
return ((Application)activity.getApplication()).getApplicationComponent();
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/data/datasource/DashboardCloudDatasourceUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/DashboardApi.java // public interface DashboardApi { // List<ImageResponse> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // }
import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.api.DashboardApi; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import org.junit.Test;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.datasource; public class DashboardCloudDatasourceUnitTest extends UnitTest { @Mock DashboardApi dashboardApiMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/DashboardApi.java // public interface DashboardApi { // List<ImageResponse> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // } // Path: app/src/test/java/com/txusballesteros/testing/data/datasource/DashboardCloudDatasourceUnitTest.java import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.api.DashboardApi; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import org.junit.Test; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.datasource; public class DashboardCloudDatasourceUnitTest extends UnitTest { @Mock DashboardApi dashboardApiMock;
@Mock ImageResponseMapper imageResponseMapperMock;
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/data/datasource/DashboardCloudDatasourceUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/DashboardApi.java // public interface DashboardApi { // List<ImageResponse> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // }
import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.api.DashboardApi; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import org.junit.Test;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.datasource; public class DashboardCloudDatasourceUnitTest extends UnitTest { @Mock DashboardApi dashboardApiMock; @Mock ImageResponseMapper imageResponseMapperMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/DashboardApi.java // public interface DashboardApi { // List<ImageResponse> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponse.java // public class ImageResponse { // private Uri url; // // private ImageResponse() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageResponse image; // // public Builder() { // this.image = new ImageResponse(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageResponse build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/api/model/ImageResponseMapper.java // public interface ImageResponseMapper { // List<ImageResponse> map(DashboardListEndpointResponse source); // List<ImageEntity> map(List<ImageResponse> source); // ImageEntity map(ImageResponse source); // ImageResponse map(DashboardEndpointResponse source); // } // Path: app/src/test/java/com/txusballesteros/testing/data/datasource/DashboardCloudDatasourceUnitTest.java import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.api.DashboardApi; import com.txusballesteros.testing.data.api.model.ImageResponse; import com.txusballesteros.testing.data.api.model.ImageResponseMapper; import org.junit.Test; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.datasource; public class DashboardCloudDatasourceUnitTest extends UnitTest { @Mock DashboardApi dashboardApiMock; @Mock ImageResponseMapper imageResponseMapperMock;
@Mock List<ImageResponse> apiRessultMock;
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // }
import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // Path: app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock;
@Mock DashboardCache cacheMock;
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // }
import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock; @Mock DashboardCache cacheMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // Path: app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock; @Mock DashboardCache cacheMock;
@Mock ImageEntityMapper mapperMock;
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // }
import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock; @Mock DashboardCache cacheMock; @Mock ImageEntityMapper mapperMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // Path: app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock; @Mock DashboardCache cacheMock; @Mock ImageEntityMapper mapperMock;
@Mock DashboardRepository.Callback callbackMock;
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // }
import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock; @Mock DashboardCache cacheMock; @Mock ImageEntityMapper mapperMock; @Mock DashboardRepository.Callback callbackMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // Path: app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock; @Mock DashboardCache cacheMock; @Mock ImageEntityMapper mapperMock; @Mock DashboardRepository.Callback callbackMock;
@Mock List<ImageEntity> entitiesListMock;
txusballesteros/Android-Clean-Testing
app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // }
import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock; @Mock DashboardCache cacheMock; @Mock ImageEntityMapper mapperMock; @Mock DashboardRepository.Callback callbackMock; @Mock List<ImageEntity> entitiesListMock;
// Path: app/src/test/java/com/txusballesteros/testing/UnitTest.java // @RunWith(JUnit4.class) // @SmallTest // public abstract class UnitTest { // @Before // public final void setup() { // initializeMocks(); // onSetup(); // } // // private void initializeMocks() { // MockitoAnnotations.initMocks(this); // } // // protected abstract void onSetup(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/cache/DashboardCache.java // public interface DashboardCache { // boolean isValid(); // void cache(List<ImageEntity> values); // List<ImageEntity> get(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/DashboardDatasource.java // public interface DashboardDatasource { // List<ImageEntity> getDashboard(); // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntity.java // public class ImageEntity { // private Uri url; // // private ImageEntity() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private ImageEntity image; // // public Builder() { // this.image = new ImageEntity(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public ImageEntity build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/data/datasource/model/ImageEntityMapper.java // public interface ImageEntityMapper { // List<Image> map(List<ImageEntity> source); // Image map(ImageEntity source); // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/model/Image.java // public class Image { // private Uri url; // // private Image() { } // // public Uri getUrl() { // return url; // } // // public static class Builder { // private Image image; // // public Builder() { // this.image = new Image(); // } // // public Builder setUrl(Uri url) { // image.url = url; // return this; // } // // public Image build() { // return image; // } // } // } // // Path: app/src/main/java/com/txusballesteros/testing/domain/repository/DashboardRepository.java // public interface DashboardRepository { // void getDashboard(final Callback callback); // // interface Callback { // void onSuccess(final List<Image> images); // void onError(); // } // } // Path: app/src/test/java/com/txusballesteros/testing/data/DashboardRepositoryUnitTest.java import com.txusballesteros.testing.domain.repository.DashboardRepository; import org.junit.Test; import org.mockito.Mock; import java.util.List; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import com.txusballesteros.testing.UnitTest; import com.txusballesteros.testing.data.cache.DashboardCache; import com.txusballesteros.testing.data.datasource.DashboardDatasource; import com.txusballesteros.testing.data.datasource.model.ImageEntity; import com.txusballesteros.testing.data.datasource.model.ImageEntityMapper; import com.txusballesteros.testing.domain.model.Image; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data; public class DashboardRepositoryUnitTest extends UnitTest { @Mock DashboardDatasource datasourceMock; @Mock DashboardCache cacheMock; @Mock ImageEntityMapper mapperMock; @Mock DashboardRepository.Callback callbackMock; @Mock List<ImageEntity> entitiesListMock;
@Mock List<Image> resultMock;
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/data/api/endpoint/DashboardEndpoint.java
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/model/DashboardListEndpointResponse.java // public class DashboardListEndpointResponse { // public List<DashboardEndpointResponse> data; // }
import com.txusballesteros.testing.data.api.endpoint.model.DashboardListEndpointResponse; import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Query;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.api.endpoint; public interface DashboardEndpoint { @GET("v1/gifs/trending")
// Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/model/DashboardListEndpointResponse.java // public class DashboardListEndpointResponse { // public List<DashboardEndpointResponse> data; // } // Path: app/src/main/java/com/txusballesteros/testing/data/api/endpoint/DashboardEndpoint.java import com.txusballesteros.testing.data.api.endpoint.model.DashboardListEndpointResponse; import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Query; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.data.api.endpoint; public interface DashboardEndpoint { @GET("v1/gifs/trending")
Call<DashboardListEndpointResponse> getDashboard(@Query("api_key") String apiKey);
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/internal/di/RuntimeDependenciesInjector.java
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java // @Module( // includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // } // ) // public class RuntimeActivityModule implements ActivityModule { // private final Activity activity; // // public RuntimeActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.view.MainActivity; import com.txusballesteros.testing.view.internal.di.DaggerRuntimeActivityComponent; import com.txusballesteros.testing.view.internal.di.RuntimeActivityModule;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class RuntimeDependenciesInjector implements DependenciesInjector { @Override
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java // @Module( // includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // } // ) // public class RuntimeActivityModule implements ActivityModule { // private final Activity activity; // // public RuntimeActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/main/java/com/txusballesteros/testing/internal/di/RuntimeDependenciesInjector.java import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.view.MainActivity; import com.txusballesteros.testing.view.internal.di.DaggerRuntimeActivityComponent; import com.txusballesteros.testing.view.internal.di.RuntimeActivityModule; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class RuntimeDependenciesInjector implements DependenciesInjector { @Override
public void inject(MainActivity client) {
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/internal/di/RuntimeDependenciesInjector.java
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java // @Module( // includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // } // ) // public class RuntimeActivityModule implements ActivityModule { // private final Activity activity; // // public RuntimeActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.view.MainActivity; import com.txusballesteros.testing.view.internal.di.DaggerRuntimeActivityComponent; import com.txusballesteros.testing.view.internal.di.RuntimeActivityModule;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class RuntimeDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerRuntimeActivityComponent.builder() .applicationComponent(getApplicationComponent(client))
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java // @Module( // includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // } // ) // public class RuntimeActivityModule implements ActivityModule { // private final Activity activity; // // public RuntimeActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/main/java/com/txusballesteros/testing/internal/di/RuntimeDependenciesInjector.java import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.view.MainActivity; import com.txusballesteros.testing.view.internal.di.DaggerRuntimeActivityComponent; import com.txusballesteros.testing.view.internal.di.RuntimeActivityModule; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class RuntimeDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerRuntimeActivityComponent.builder() .applicationComponent(getApplicationComponent(client))
.runtimeActivityModule(new RuntimeActivityModule(client))
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/internal/di/RuntimeDependenciesInjector.java
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java // @Module( // includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // } // ) // public class RuntimeActivityModule implements ActivityModule { // private final Activity activity; // // public RuntimeActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.view.MainActivity; import com.txusballesteros.testing.view.internal.di.DaggerRuntimeActivityComponent; import com.txusballesteros.testing.view.internal.di.RuntimeActivityModule;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class RuntimeDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerRuntimeActivityComponent.builder() .applicationComponent(getApplicationComponent(client)) .runtimeActivityModule(new RuntimeActivityModule(client))
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java // @Module( // includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // } // ) // public class RuntimeActivityModule implements ActivityModule { // private final Activity activity; // // public RuntimeActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/main/java/com/txusballesteros/testing/internal/di/RuntimeDependenciesInjector.java import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.view.MainActivity; import com.txusballesteros.testing.view.internal.di.DaggerRuntimeActivityComponent; import com.txusballesteros.testing.view.internal.di.RuntimeActivityModule; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class RuntimeDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerRuntimeActivityComponent.builder() .applicationComponent(getApplicationComponent(client)) .runtimeActivityModule(new RuntimeActivityModule(client))
.viewModule(new ViewModule(client))
txusballesteros/Android-Clean-Testing
app/src/main/java/com/txusballesteros/testing/internal/di/RuntimeDependenciesInjector.java
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java // @Module( // includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // } // ) // public class RuntimeActivityModule implements ActivityModule { // private final Activity activity; // // public RuntimeActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // }
import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.view.MainActivity; import com.txusballesteros.testing.view.internal.di.DaggerRuntimeActivityComponent; import com.txusballesteros.testing.view.internal.di.RuntimeActivityModule;
/* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class RuntimeDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerRuntimeActivityComponent.builder() .applicationComponent(getApplicationComponent(client)) .runtimeActivityModule(new RuntimeActivityModule(client)) .viewModule(new ViewModule(client)) .build() .inject(client); } private ApplicationComponent getApplicationComponent(Activity activity) {
// Path: app/src/main/java/com/txusballesteros/testing/Application.java // public class Application extends android.app.Application { // private RuntimeApplicationComponent applicationComponent; // @Inject DependenciesInjector injector; // // @Override // public void onCreate() { // super.onCreate(); // initializeInjection(); // } // // private void initializeInjection() { // applicationComponent = DaggerRuntimeApplicationComponent.builder() // .runtimeApplicationModule(new RuntimeApplicationModule(this)) // .build(); // applicationComponent.inject(this); // } // // public ApplicationComponent getApplicationComponent() { // return applicationComponent; // } // // public DependenciesInjector getDependenciesInjector() { // return injector; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/MainActivity.java // public class MainActivity extends AbsActivity implements MainPresenter.View { // @Inject MainPresenter presenter; // @Inject ImageLoader imageLoader; // @Bind(R.id.list) RecyclerView listView; // private DashboardListAdapter listAdapter; // // @Override // int onRequestLayout() { // return R.layout.activity_main; // } // // @Override // void onViewReady() { // initializeList(); // } // // private void initializeList() { // listAdapter = new DashboardListAdapter(this, imageLoader); // listView.setLayoutManager(new GridLayoutManager(this, 2)); // listView.setHasFixedSize(true); // listView.setAdapter(listAdapter); // } // // @Override // void onInitializeInjection() { // getDependenciesInjector().inject(this); // } // // @Override // protected void onStart() { // super.onStart(); // presenter.onStart(); // } // // @Override // protected void onStop() { // super.onStop(); // presenter.onStop(); // } // // @Override // public void renderDashboard(List<ImageModel> images) { // listAdapter.addAll(images); // } // // @Override // public void renderError() { } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/RuntimeActivityModule.java // @Module( // includes = { // ViewModule.class, // PresentationModule.class, // UseCasesModule.class // } // ) // public class RuntimeActivityModule implements ActivityModule { // private final Activity activity; // // public RuntimeActivityModule(Activity activity) { // this.activity = activity; // } // // @Override @Provides // public Activity provideActivity() { // return activity; // } // } // // Path: app/src/main/java/com/txusballesteros/testing/view/internal/di/ViewModule.java // @Module // public class ViewModule { // private MainPresenter.View mainPresenterView; // // public ViewModule(MainPresenter.View view) { // this.mainPresenterView = view; // } // // @Provides // MainPresenter.View provideMainPresenterView() { // return mainPresenterView; // } // } // Path: app/src/main/java/com/txusballesteros/testing/internal/di/RuntimeDependenciesInjector.java import com.txusballesteros.testing.view.internal.di.ViewModule; import android.app.Activity; import com.txusballesteros.testing.Application; import com.txusballesteros.testing.view.MainActivity; import com.txusballesteros.testing.view.internal.di.DaggerRuntimeActivityComponent; import com.txusballesteros.testing.view.internal.di.RuntimeActivityModule; /* * Copyright Txus Ballesteros 2016 (@txusballesteros) * * This file is part of some open source application. * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * Contact: Txus Ballesteros <txus.ballesteros@gmail.com> */ package com.txusballesteros.testing.internal.di; public class RuntimeDependenciesInjector implements DependenciesInjector { @Override public void inject(MainActivity client) { DaggerRuntimeActivityComponent.builder() .applicationComponent(getApplicationComponent(client)) .runtimeActivityModule(new RuntimeActivityModule(client)) .viewModule(new ViewModule(client)) .build() .inject(client); } private ApplicationComponent getApplicationComponent(Activity activity) {
return ((Application)activity.getApplication()).getApplicationComponent();