interface

Mocking mgo chaining functions

跟風遠走 提交于 2019-12-11 09:05:53
问题 While testing some of my codebase I found it useful to mock out objects from "gopkg.in/mgo.v2" with interfaces. I'm running into a problem where mgo.Query does not implement my interface Query. import mgo "gopkg.in/mgo.v2" type Collection interface { FindId(interface{}) Query Find(interface{}) Query UpdateId(interface{}, interface{}) error Update(interface{}, interface{}) error UpsertId(interface{}, interface{}) (interface{}, error) Insert(...interface{}) error RemoveId(interface{}) error }

How to make this to OOP

巧了我就是萌 提交于 2019-12-11 08:49:02
问题 @Override public void onMotionSensingEvent( MotionSensingEvent arg0) { double gradient = 1.38; double speed; float testpitch = 0; testpitch = arg0.getOrientation().getPitch(); float testroll = 0; testroll = arg0.getOrientation().getRoll(); if (testroll > 16 && flyingControl) { speed = gradient*testroll-22.1; System.out.println("kanan = " + speed); ardrone.goRight(speed); } else if (testroll < (-24) && flyingControl) { speed = gradient*testroll*-1 - 22.1; System.out.println("kiri = " + speed);

Interface Builder / Putting UIButton in front of UIImageView (when UIButtons have been created before UImageView…)

有些话、适合烂在心里 提交于 2019-12-11 08:45:47
问题 I have already defined several buttons in a view with Interface Builder. Now, I would like to add an UIImageView in this view. The idea is to have the UIImageView display behind the already existing buttons. I have dropped a new UIImage View in the view but curiously, I cannot get the image appear under the buttons (buttons are hidden by the fresh UIImageView). When I move my old buttons onto the UIImageView, then they remain in front of them but I guess there is another way to reach what I

Error: “<Class> is not abstract and does not override abstract method <method>”

大憨熊 提交于 2019-12-11 08:39:46
问题 Error : java:com.company.Bicycle is not abstract and does not override abstract method applyBreakes(int) in com.company.Vehicle and same for the Bike class. package com.company; interface Vehicle { //all are the abstract method. void changeGear(int a); void speedUp(int a); void applyBreakes(int a); } class Bicycle implements Vehicle { int speed; int gear; //to change speed @Override public void changeGear(int newGear) { gear = newGear; } //to increase speed @Override public void speedUp(int

Could I return a FileStream as a generic interface to a file?

佐手、 提交于 2019-12-11 08:35:20
问题 I'm writing a class interface that needs to return references to binary files. Typically I would provide a reference to a file as a file path. However, I'm considering storing some of the files (such as a small thumbnail) in a database directly rather then on a file system. In this case I don't want to add the extra step of reading the thumbnail out of the database onto the disc and then returning a path to the file for my program to read. I'd want to stream the image directly out of the

Struct field not updated when implementing interface function

有些话、适合烂在心里 提交于 2019-12-11 08:29:19
问题 If for example we have the following interface: type IRoute interface { AddChildren(child IRoute) } The following struct: type Route struct { Alias string `json:"alias"` Children []Route `json:"children,omitempty"` Url string `json:"url,omitempty"` } And implemented the interface: func (this Route) AddChildren (child globals.IRoute){ this.Children = append(this.Children, child.(Route)) } Then in our main func, if we wanted to test this it would not work: rSettings := Route{"settings", nil, "

Difference between specifying the view.onclicklistener and just having onclicklistener

旧城冷巷雨未停 提交于 2019-12-11 07:58:33
问题 I looked on http://developer.android.com/reference/android/view/package-summary.html and saw that the view class has an interface named "View.OnClickListener" which is "Interface definition for a callback to be invoked when a view is clicked" My question is what the difference is if you specify the view or not in the interface? Basically is button.setOnClickListener(new Button.OnClickListener() the Same as button.setOnClickListener(new OnClickListener()? 回答1: There are 2 of setOnClickListener

Implement multiple classes in the same interface in Java?

感情迁移 提交于 2019-12-11 07:58:26
问题 I have got multiple classes which each implement multiple different methods within each. Now the problem statement is that I wish to use the methods from all these (maybe around ~200 such different class files/methods) in another class file which all different methods from the above class files. I thought that if I implement an interface which has all these various methods listed, then I just call/import/reference that single interface and can use all the methods? But I am stuck, as this

Matlab serial interface with Arduino is very slow

蓝咒 提交于 2019-12-11 07:47:13
问题 I am trying to establish a serial link in Matlab with an Arduino board. Reading data from the board goes well. However, writing data to the board takes about a second for each block of information I send. The code I am running to write data: s = serial(comprt,'BaudRate',9600,'DataBits',8); fopen(s); fprintf(s, '%c', 'c'); fprintf(s, '%u %u %u %u \n', [A B C D]); pause(1); fprintf(s, '%c', 'a'); pause(1); A, B, C, D are 8-bit numbers anywhere from 0 - 255, 'c' and 'a' are characters commands

Delphi TRttiType.GetMethods return zero TRttiMethod instances

折月煮酒 提交于 2019-12-11 07:34:25
问题 I've recently been able to fetch a TRttiType for an interface using TRttiContext.FindType using Robert Loves "GetType"-workaround ("registering" the interface by an explicit call to ctx.GetType, e.g. RType := ctx.GetType(TypeInfo(IMyPrettyLittleInterface));). One logical next step would be to iterate the methods of said interface. Consider program rtti_sb_1; {$APPTYPE CONSOLE} uses SysUtils, Rtti, mynamespace in 'mynamespace.pas'; var ctx: TRttiContext; RType: TRttiType; Method: TRttiMethod;