How to maintain order of methods of interface in implemented class - eclipse

Suppose I am having below interface inside binary jar:
public interface OrderDemo
{
public void add();
public void shut();
public void manage();
}
When I am adding this as Jar as part of dependency in my project in eclipse after implementing OrderDemo interface order of method get changed.
public class Demo implements OrderDemo
{
#Override
public void add();
{
}
#Override
public void manage()
{
}
#Override
public void shut()
{
}
}
Tried option given in eclipse preference but won't work.

Related

Interface in java

interface A {
public void eg1();
}
interface B {
public void eg1();
}
public class SomeOtherClassName implements A, B {
#Override
public void eg1() {
System.out.println("test.eg1()");
}
}
What is the output and what occurs if method is overriden in interface?
First of all it's of no use to implement both class A and B as both
of them has same method signature i.e both has same method name and
return type.
Secondly you'll need a main method to run the program.
Also in interface you can only declare the methods, the implementation
has to be done in the class which implements it.
interface A {
public void eg1();
}
interface B {
public void eg1();
}
public class Test implements A{
#Override
public void eg1() {
System.out.println("test.eg1()");
}
public static void main (String args[]) {
A a = new test();
a.eg1();
}
}
Output : test.eg1()

Gwtp Autobean and rest

I have InfraNameModel (Rest-type) to work with JSON
public interface IInfraNameBeanFactory extends AutoBeanFactory {
IInfraNameBeanFactory INSTANCE = GWT.create(IInfraNameBeanFactory.class);
AutoBean<InfraNameModel> infraName();
AutoBean<InfraNameListModel> results();
}
public interface InfraNameListModel {
List<InfraNameModel> getResults();
void setResults(List<InfraNameModel> results);
}
public class InfraNameListModelImpl implements InfraNameListModel {
private List<InfraNameModel> results;
#Override
public List<InfraNameModel> getResults() {
return results;
}
#Override
public void setResults(List<InfraNameModel> results) {
this.results = results;
}
}
public interface InfraNameModel {
String getInfraName();
void setInfraName(String infraName);
}
public class InfraNameModelImpl implements InfraNameModel {
private String infraName;
#Override
public String getInfraName() {
return infraName;
}
#Override
public void setInfraName(String infraName) {
this.infraName = infraName;
}
}
I wanted to make them into a separate JAR
To make it common for the client and the server
But now I have errors
[WARN] Class by.models.infraNameModel.InfraNameModel is used in Gin, but not available in GWT client code.
Is it real to pull such beans into a separate library?

Working with WorkerStateEvent without casting?

I am currently dispatching my Business Logic via the Concurrency API JavaFX offers. But there is one part I stumble over which does not feel clean to me.
Basically if you create a Service which may look like this
public class FooCommand extends Service<Foo> {
#Override protected Task<Foo> createTask() {
return new Foo();
}
}
and I set the onSucceeded
FooCommand fooCommand = CommandProvider.get(FooCommand.class);
fooCommand.setOnSucceeded(new FooSucceededHandler());
fooCommand.start();
to an instance of this class
public class FooSucceededHandler implements EventHandler<WorkerStateEvent> {
#Override public void handle(WorkerStateEvent event) {
Foo f = (Foo) event.getSource().getValue();
}
}
But as you can see I need to cast the value of the Worker to (Foo). Is there some cleaner way to do it?
You could just make your own abstract class:
public abstract class EventCallback<T> implements EventHandler<WorkerStateEvent> {
#Override
public void handle(final WorkerStateEvent workerStateEvent) {
T returnType = (T) workerStateEvent.getSource().valueProperty().get();
this.handle(returnType);
}
public abstract void handle(T objectReturned);
}
And then using it:
final EventCallback<MonType> eventCallback = new EventCallback<MonType>() {
#Override
public void handle(final MonType objectReturned) {
// DO STUFF
}
};
As it is also an EventHandler, it is compatible with JavaFX concurrent API.

GWT Platform UiHandlers not working

I have followed the GettingStarted on the GWTP tutorial
http://code.google.com/p/gwt-platform/wiki/GettingStarted
but unfortunately handlers not working, getUiHandlers() return null and exception stacktrace is same as in:
How to use UiHandlers of GWT Platform?
.
View Class
public class AView extends ViewWithUiHandlers<AUiHandlers> implements APresenter.Display {
#UiTemplate("AView.ui.xml")
interface AViewUiBinder extends UiBinder<Widget, AView> {}
private static AViewUiBinder uiBinder = GWT.create(AViewUiBinder.class);
#UiField Button saveBtn;
#UiField Button cancelBtn;
#UiField DivElement errorDiv;
private Widget widget;
#Inject
public AssetView() {
widget = uiBinder.createAndBindUi(this);
}
public Widget asWidget() {
return widget;
}
// Implementation: Presenter's Display methods
public void setErrorDivText(String msg) {
errorDiv.getStyle().setDisplay(Display.BLOCK);
errorDiv.setInnerText(msg);
}
// Handlers
#UiHandler("saveBtn")
void onSaveButtonClick(ClickEvent event) {
if(getUiHandlers() != null) {
getUiHandlers().onSaveButtonClick();
}
}
#UiHandler("cancelBtn")
void onCancelButtonClick(ClickEvent event) {
if(getUiHandlers() != null) {
getUiHandlers().onCancelButtonClick();
}
}
}
Handler Interface
public interface AUiHandlers extends UiHandlers {
void onSaveButtonClick();
void onCancelButtonClick();
}
Presenter
public class APresenter extends Presenter<APresenter.Display, APresenter.AssetProxy> implements AUiHandlers {
public interface Display extends View, HasUiHandlers<AUiHandlers> {
public void setErrorDivText(String msg);
}
#ProxyStandard
#NameToken(NameTokens.ASSET)
public interface AssetProxy extends ProxyPlace<AssetPresenter> {}
#Inject
public AssetPresenter(EventBus eventBus, Display view, AssetProxy proxy) {
super(eventBus, view, proxy);
getView().setUiHandlers(this);
}
#Override
protected void onBind() {
super.onBind();
}
#Override
protected void revealInParent() {
RevealRootContentEvent.fire( this, this );
}
public void onSaveButtonClick() {
getView().setErrorDivText("Save clicked.");
}
public void onCancelButtonClick() {
getView().setErrorDivText("Cancel clicked.");
}
}
Unable to understand where i am making mistake, implementation regarding UiHandlers is same as told in the above mentioned tutorial's link.
UiHandlers is not generic; it cannot be parameterized with arguments
As I see your handler interface, you have passed AUiHandlers type. I don't understand the package structure of UiHandlers . it should be com.gwtplatform.mvp.client.UiHandlers.
Please check import of it.
Update:
Remove private static AViewUiBinder uiBinder = GWT.create(AViewUiBinder.class);
and Pass as constructor argument
#Inject
public AssetView(AViewUiBinder uiBinder) {
widget = uiBinder.createAndBindUi(this);
}

How to list all classes in autocompletion inside annotations in Intellij IDEA?

I have custom class InternalTimerServiceController in my application. I want to use it in another class inside android annotations. And it seems that autocompletion does not work correctly in this case.
I have this interface
public interface InternalTimerServiceControllerContract
{
void doWork();
}
And this class
#EBean
public class InternalTimerServiceController implements InternalTimerServiceControllerContract
{
#Override
public void doWork()
{
// do work
}
}
And this is my Activity
public class MyActivity extends Activity
{
// try uncomment line below and see if autocomplete works properly
//#Bean(Internal)
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
It's a bug, thanks for reporting. I've created a ticket for it: http://youtrack.jetbrains.com/issue/IDEA-98298