Read the contents of the import Package - java

I am working on creating a computer controlled bots for a game using Java. I got a example bot program and I am understanding this currently.
I am not able to understand what does #JProp means in the code below. Can any one help me on this. Also, how do I view all the contents of the import files at the start of the program.
package com.mycompany.mavenproject1;
import cz.cuni.amis.introspection.java.JProp;
import cz.cuni.amis.pogamut.base.agent.impl.AgentId;
import cz.cuni.amis.pogamut.base.agent.module.comm.PogamutJVMComm;
import cz.cuni.amis.pogamut.base.agent.navigation.IPathExecutorState;
import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.EventListener;
import cz.cuni.amis.pogamut.base.utils.guice.AgentScoped;
import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
import cz.cuni.amis.pogamut.ut2004.agent.module.utils.TabooSet;
import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004PathAutoFixer;
import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004DistanceStuckDetector;
import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004PositionStuckDetector;
import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004TimeStuckDetector;
import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController;
import cz.cuni.amis.pogamut.ut2004.bot.params.UT2004BotParameters;
import cz.cuni.amis.pogamut.ut2004.communication.messages.UT2004ItemType;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.FlagInfo;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Item;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerKilled;
import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
import cz.cuni.amis.pogamut.ut2004.utils.UT2004BotRunner;
import cz.cuni.amis.utils.Heatup;
import cz.cuni.amis.utils.exception.PogamutException;
import cz.cuni.amis.utils.flag.FlagListener;
/**
* Example of Simple Pogamut bot, that randomly walks around the map searching
* for preys shooting at everything that is in its way.
*
* #author Rudolf Kadlec aka ik
* #author Jimmy
*/
#AgentScoped
public class CTFBot extends UT2004BotModuleController<UT2004Bot> {
/** boolean switch to activate engage behavior */
#JProp
public boolean shouldEngage = true;
/** boolean switch to activate pursue behavior */

It seems this JProp annotation is used for introspection purposes (allowing the contents of the variable which is decorated to be easily inspected from within your IDE).
Quoting this manual:
Introspection is designed to ease the bot's parameterization. It is
often needed to adjust multiple behavior parameters at runtime and you
will probably end up creating your own GUI (graphical user interface)
for this purpose. In introspection, you just annotate desired
variables with #JProp annotation and they will be accessible via the
Netbeans GUI.
Let's look how logging and introspection works in EmptyBot example.
First start the bot (F6), then have a look on it's source code. In the
initial section several variables annotated with the #JProp are
defined.
#JProp
public String stringProp = "Hello bot example";
#JProp
public boolean boolProp = true;
#JProp
public int intProp = 2;
#JProp
public double doubleProp = 1.0;
Now expand bot's node under the UT server node (in Services tab), you
will see two new nodes - Logs and Introspection. After selecting the
Introspection node the annotated variables will be shown in the
Properties (Ctrl + Shift + 7) window. Note that the intProp variable
is being continuously updated. New values of variables can be also set
in this window.

Related

Stringing together multiple page object files in Eclipse/Cucumber/Java

I am having trouble stringing together multiple Page Object Files and step definitions.
I have imported the following, which is super heavily edited due to it being work code:
package <the package my step definition file is in>
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import <the other project my team created>.browsercapabilities.Browser;
import <the other project my team created>.Browsers;
import <a package a different step definition file is
in>.addNewContact.AddNewContactStepDefs;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import <the other project my team created>.webcomponents.WebButton;
import <my page objects package>.authenticationpages.CommandLoginPage;
import <my page object package>ThirdPageObjectFile;
import <my page object package>.SecondPageObjectFile;
import <my page object package>.FirstPageObjectFile;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
public class ThirdPageStepDefs extends BrowserBase {
private static final Logger LOG =
LoggerFactory.getLogger(ThirdPageStepDefs.class);
private WebDriver driver = mainBrowser().getDriver();
private Browser browser = Browsers.getBrowser();
private WebDriverWait wait = new WebDriverWait(driver,10);
LoginPage login = new LoginPage (browser);
SecondPageObjectFile contact = new SecondPageObjectFile (browser);
FirstPageObjectFile searchContact = new FirstPageObjectFile (browser);
ThirdPageObjectFile deal = new ThirdPageObjectFile (browser);
#Then("^I click the contacts icon$")
public void i_click_the_contacts_icon() throws Throwable {
contact.get_contact_link().clickLink();
}
I was getting an initialization error when I ran the runner code saying that the runner could not instantiate an instance of my ThirdStepDefFile, i.e. "Failed to Instantiate Class "
My runner is working fine:
package <Utility package>.utilities;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#RunWith(Cucumber.class)
#CucumberOptions(
features="src\\test\\resources\\<my feature folder>",
plugin={"pretty", "html:target/cucumber-html-report",
"json:target/cucumber.json"},
glue= "<My step def folder>",
tags = "#<my tags>"
)
public class ComUITestRunner extends AbstractTestNGCucumberTests {
}
I have many more lines in scenarios that I've commented out and since I was getting the initialization error, I edited to troubleshoot as following:
-Comment all methods out (green)
-Leave all methods in (red)
-Leave one method in (red)
When I have even one method that isn't commented out, then I get an error.
My project is a series of screens that a user has to get to in order to log in. The login screen, first screen, second screen, and third screen all have their own page objects. Eventually I want to abstract those screens out to a main project that all sub projects share as they'll be pre-conditions to everything else. Stringing these screens together seems to fail and I'm considering refactoring the whole thing.
Am also new to Java/Eclipse, so it's possible that I am not seeing the stack trace correctly. For instance, the bottom of my junit screen says "62 more" lines detailing the failure that I'm not able to see. I tried debugging to no avail and I clicked on the outline on the left hand side of the junit output and when I hovered over it, it says Test Class Not Found

How to import classes from within another directory / package

I am working on a somewhat large project with many subdirectories. I am, however, coming across an issue of importing classes from within another directory. The directory structure is as so:
main.dir
repository.dir
Bill.java
transaction.dir
AutomaticBillPay.java
How can I import Bill into AutomaticBillPay?
I have tried may iterations of:
package main;
package main.repositorysys;
import main.repositorysys.Bill;
import repositorysys.Bill;
import Bill;
Sadly, the only line that compiles is the first: package main;. Any tips / direction will help!
You can achieve it through this
/*Declare your class package */
package main.transactionsubsys;
/*import the classes you want */
import main.repositorysys.Bill;
/*Write your class*/
public class AutomaticBillPay {
/*AutomaticBillPay code */
}
Your AutomaticBillPay should look like this:
package main.transaction;
import main.repository.Bill;
public class AutomaticBillPay {
// your class implementation here
}
Not sure where repositorysys came from?
package should be the full path to your encompassing directory
import should be the full path to the class you want to import

Where is log declared?

I'm trying to propose a patch to deeplearning4j, but first I need to be able to build the project. I'm able to build it from maven using the manual instructions, but IntelliJ (2016.3.6) is finding errors, and when I look at the source code, I don't blame it.
The source file I'm specifically stumped by is https://github.com/deeplearning4j/deeplearning4j/blob/master/deeplearning4j-nlp-parent/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/word2vec/StaticWord2Vec.java, which has a couple references to a variable log that's not declared in this file.
package org.deeplearning4j.models.word2vec;
import lombok.extern.slf4j.Slf4j;
import org.deeplearning4j.models.embeddings.WeightLookupTable;
import org.deeplearning4j.models.embeddings.reader.ModelUtils;
import org.deeplearning4j.models.embeddings.wordvectors.WordVectors;
import org.deeplearning4j.models.word2vec.wordstore.VocabCache;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.compression.AbstractStorage;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.linalg.ops.transforms.Transforms;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* This is special limited Word2Vec implementation, suited for serving as lookup table in concurrent multi-gpu environment
* This implementation DOES NOT load all vectors onto any of gpus, instead of that it holds vectors in, optionally, compressed state in host memory.
* This implementation DOES NOT provide some of original Word2Vec methods, such as wordsNearest or wordsNearestSum.
*
* #author raver119#gmail.com
*/
#Slf4j
public class StaticWord2Vec implements WordVectors {
private List<Map<Integer, INDArray>> cacheWrtDevice = new ArrayList<>();
private AbstractStorage<Integer> storage;
private long cachePerDevice = 0L;
private VocabCache<VocabWord> vocabCache;
private String unk = null;
... snipped
The class extends an interface, but does not explicitly extend a parent class. Inspecting the class file generated by Maven using javap, I see:
Compiled from "StaticWord2Vec.java"
public class org.deeplearning4j.models.word2vec.StaticWord2Vec
implements org.deeplearning4j.models.embeddings.wordvectors.WordVectors {
private static final org.slf4j.Logger log;
... snipped
I finally noticed the annotation #Slf4j and tracing the import statement, discovered that I needed to add the Lombok plugin to IntelliJ to be able to build this project.

How can I import jDatePicker into a BlueJ Java program?

I'm trying to use the jDatePicker tool from here: sourceforge.net/projects/jdatepicker/files/latest/download and I've placed the .jar file in C:\Program Files (x86)\BlueJ\lib\userlib and it's been recognised in the BlueJ preferences but I have no idea how to actually use it in my project. I've tried all sorts of import commands but it's not picking it up. Any ideas?
Update: OK, i've now got it to compile, but the applet doesn't run, BlueJ just says "Applet not initialised":
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.util.*;
import java.util.Calendar;
import java.util.Date;
import net.sourceforge.jdatepicker.*;
import net.sourceforge.jdatepicker.impl.*;
import net.sourceforge.jdatepicker.util.*;
public class Task1 extends java.applet.Applet implements ActionListener
{
public void init()
{
setLayout(null);
setSize(200,240);
JButton btnConfirm=new JButton("Confirm"); //initalises the button
btnConfirm.setBounds(15,2,100,20);
add(btnConfirm); //paints it on the screen
btnConfirm.addActionListener(this);
TextField text = new TextField(20);
text.setBounds(5,24,185,20);
add(text);
UtilDateModel model = new UtilDateModel();
JDatePanelImpl datePanel = new JDatePanelImpl(model);
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel);
datePicker.setBounds(50,80,185,20);
add(datePicker);
}
/* Use the method actionPerformed to trap the event button clicked */
public void actionPerformed(ActionEvent evt)
{
JOptionPane.showMessageDialog(null,"ALERT MESSAGE","TITLE",JOptionPane.WARNING_MESSAGE);
}
}
To import other classes in your Java files, you need to add an import statement with the full qualified name of the class (The file name with the package).
To import the JDatePicker class, you need to add:
import org.jdatepicker.JDatePicker;
If you want to import all the classes in a package, you can use *:
import org.jdatepicker.*;
The classes must be present in the Classpath. As you are adding the JAR file in the BlueJ\lib\userlib folder, this should be enough to import the classes correctly.
You may need to import other classes in other packages like:
import org.jdatepicker.impl.*;
import org.jdatepicker.util.*;
Import your required classes or packages as needed.
You need to tell java where to find the library. You do this by adding the location, where you put the library to your classpath.
Usually your IDE supports you in this process by providing a GUI to do this.
For BlueJ, take a look here: http://www.bluej.org/faq.html#faq_How_do_I_use_custom_class_libraries__JARs__

Import "imports" in eclipse - Java

I have several java files in a package and all of them have the same import blocks e.g :
package org.ezim.core;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import org.ezim.core.Ezim;
import org.ezim.core.EzimDtxSemantics;
import org.ezim.core.EzimLogger;
import org.ezim.ui.EzimFileOut;
import org.ezim.ui.EzimMain;
It looks awful having the same batches of code in each file and i want to refactor it.
I was wondering if its possible to put all these imports in a single java file then use a single line in all the other java files to call them.
Its like the extend function for classes (for variables) , but i want one for the imports.
Thanks
No. That isn't possible. What is possible is not using imports at all, instead you can use fully qualified class names like
org.ezim.core.Ezim ezim = new org.ezim.core.Ezim(); // <-- not import needed.
You can always use * sign to import multiple classes from one package, but thus watch for name clashes.

Categories