Search Results

Search found 5671 results on 227 pages for 'final'.

Page 9/227 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Final classes in Python 3.x- something Guido isn't telling me?

    - by GlenCrawford
    This question is built on top of many assumptions. If one assumption is wrong, then the whole thing falls over. I'm still relatively new to Python and have just entered the curious/exploratory phase. It is my understanding that Python does not support the creating of classes that cannot be subclassed (final classes). However, it seems to me that the bool class in Python cannot be subclassed. This makes sense when the intent of the bool class is considered (because bool is only supposed to have two values: true and false), and I'm happy with that. What I want to know is how this class was marked as final. So my question is: how exactly did Guido manage to prevent subclassing of bool? >>> class TestClass(bool): pass Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> class TestClass(bool): TypeError: type 'bool' is not an acceptable base type Related question: http://stackoverflow.com/questions/2172189/why-i-cant-extend-bool-in-python

    Read the article

  • Why am I having this InstantiationException in Java when accessing final local variables?

    - by Oscar Reyes
    I was playing with some code to make a "closure like" construct ( not working btw ) Everything looked fine but when I tried to access a final local variable in the code, the exception InstantiationException is thrown. If I remove the access to the local variable either by removing it altogether or by making it class attribute instead, no exception happens. The doc says: InstantiationException Thrown when an application tries to create an instance of a class using the newInstance method in class Class, but the specified class object cannot be instantiated. The instantiation can fail for a variety of reasons including but not limited to: - the class object represents an abstract class, an interface, an array class, a primitive type, or void - the class has no nullary constructor What other reason could have caused this problem? Here's the code. comment/uncomment the class attribute / local variable to see the effect (lines:5 and 10 ). import javax.swing.*; import java.awt.event.*; import java.awt.*; class InstantiationExceptionDemo { //static JTextField field = new JTextField();// works if uncommented public static void main( String [] args ) { JFrame frame = new JFrame(); JButton button = new JButton("Click"); final JTextField field = new JTextField();// fails if uncommented button.addActionListener( new _(){{ System.out.println("click " + field.getText()); }}); frame.add( field ); frame.add( button, BorderLayout.SOUTH ); frame.pack();frame.setVisible( true ); } } class _ implements ActionListener { public void actionPerformed( ActionEvent e ){ try { this.getClass().newInstance(); } catch( InstantiationException ie ){ throw new RuntimeException( ie ); } catch( IllegalAccessException ie ){ throw new RuntimeException( ie ); } } } Is this a bug in Java? edit Oh, I forgot, the stacktrace ( when thrown ) is: Caused by: java.lang.InstantiationException: InstantiationExceptionDemo$1 at java.lang.Class.newInstance0(Class.java:340) at java.lang.Class.newInstance(Class.java:308) at _.actionPerformed(InstantiationExceptionDemo.java:25)

    Read the article

  • Simplest way to automatically alter "const" value in Java during compile time

    - by Michael Mao
    Hi all: This is a question corresponds to my uni assignment so I am very sorry to say I cannot adopt any one of the following best practices in a short time -- you know -- assignment is due tomorrow :( link to Best way to alter const in Java on StackOverflow Basically the only task (I hope so) left for me is the performance tuning. I've got a bunch of predefined "const" values in my single-class agent source code like this: //static final values private static final long FT_THRESHOLD = 400; private static final long FT_THRESHOLD_MARGIN = 50; private static final long FT_SMOOTH_PRICE_IDICATOR = 20; private static final long FT_BUY_PRICE_MODIFIER = 0; private static final long FT_LAST_ROUNDS_STARTTIME = 90; private static final long FT_AMOUNT_ADJUST_MODIFIER = 5; private static final long FT_HISTORY_PIRCES_LENGTH = 10; private static final long FT_TRACK_DURATION = 5; private static final int MAX_BED_BID_NUM_PER_AUC = 12; I can definitely alter the values manually and then compile the code to give it another go around. But the execution time for a thorough "statistic analysis" usually requires over 2000 times of execution, which will typically lasts more than half an hour on my own laptop... So I hope there is a way to alter values using other ways than dig into the source code to change the "const" values there, so I can automatically distributed compiled code to other people's PC and let them run the statistic analysis instead. One other reason for a automatically value adjustment is that I can try using my own agent to defeat itself by choosing different "const" values. Although my values are derived from previous history and statistical results, they are far from the most optimized values. I hope there is a easy way so I can quickly adopt that so to have a good sleep tonight while the computer does everything for me... :) Any hints on this sort of stuff? Any suggestion is welcomed and much appreciated.

    Read the article

  • Save/Load jFreechart TimeSeriesCollection chart from XML

    - by IMAnis_tn
    I'm working with this exemple wich put rondom dynamic data into a TimeSeriesCollection chart. My problem is that i can't find how to : 1- Make a track of the old data (of the last hour) when they pass the left boundary (because the data point move from the right to the left ) of the view area just by implementing a horizontal scroll bar. 2- Is XML a good choice to save my data into when i want to have all the history of the data? public class DynamicDataDemo extends ApplicationFrame { /** The time series data. */ private TimeSeries series; /** The most recent value added. */ private double lastValue = 100.0; public DynamicDataDemo(final String title) { super(title); this.series = new TimeSeries("Random Data", Millisecond.class); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); } private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart( "Dynamic Data Demo", "Time", "Value", dataset, true, true, false ); final XYPlot plot = result.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); // 60 seconds axis = plot.getRangeAxis(); axis.setRange(0.0, 200.0); return result; } public void go() { final double factor = 0.90 + 0.2 * Math.random(); this.lastValue = this.lastValue * factor; final Millisecond now = new Millisecond(); System.out.println("Now = " + now.toString()); this.series.add(new Millisecond(), this.lastValue); } public static void main(final String[] args) throws InterruptedException { final DynamicDataDemo demo = new DynamicDataDemo("Dynamic Data Demo"); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); while(true){ demo.go(); Thread.currentThread().sleep(1000); } } }

    Read the article

  • How to format given string using regex?

    - by icoolninja
    So I have defined variables in such a way in my file: public static final String hello_world = "hello world" public static final String awesome_world = "awesome world" public static final String bye_world= "bye world" I have many declarations like that. Is it possible to format them as(All '=' in a line): public static final String hello_world = "hello world" public static final String awesome_world = "awesome world" public static final String bye_world = "bye world" I can't even think of a way to do it. Any kind of help is appreciated. P.S If it matters, I use sublime text 2.

    Read the article

  • Java: Best approach to have a long list of variables needed all the time without consuming memory?

    - by evilReiko
    I wrote an abstract class to contain all rules of the application because I need them almost everywhere in my application. So most of what it contains is static final variables, something like this: public abstract class appRules { public static final boolean IS_DEV = true; public static final String CLOCK_SHORT_TIME_FORMAT = "something"; public static final String CLOCK_SHORT_DATE_FORMAT = "something else"; public static final String CLOCK_FULL_FORMAT = "other thing"; public static final int USERNAME_MIN = 5; public static final int USERNAME_MAX = 16; // etc. } The class is big and contains LOTS of such variables. My Question: Isn't setting static variables means these variables are floating in memory all the time? Do you suggest insteading of having an abstract class, I have a instantiable class with non-static variables (just public final), so I instantiate the class and use the variables only when I need them. Or is what am I doing is completely wrong approach and you suggest something else?

    Read the article

  • Design for object with optional and modifiable attributtes?

    - by Ikuzen
    I've been using the Builder pattern to create objects with a large number of attributes, where most of them are optional. But up until now, I've defined them as final, as recommended by Joshua Block and other authors, and haven't needed to change their values. I am wondering what should I do though if I need a class with a substantial number of optional but non-final (mutable) attributes? My Builder pattern code looks like this: public class Example { //All possible parameters (optional or not) private final int param1; private final int param2; //Builder class public static class Builder { private final int param1; //Required parameters private int param2 = 0; //Optional parameters - initialized to default //Builder constructor public Builder (int param1) { this.param1 = param1; } //Setter-like methods for optional parameters public Builder param2(int value) { param2 = value; return this; } //build() method public Example build() { return new Example(this); } } //Private constructor private Example(Builder builder) { param1 = builder.param1; param2 = builder.param2; } } Can I just remove the final keyword from the declaration to be able to access the attributes externally (through normal setters, for example)? Or is there a creational pattern that allows optional but non-final attributes that would be better suited in this case?

    Read the article

  • Recommended design pattern for object with optional and modifiable attributtes? [on hold]

    - by Ikuzen
    I've been using the Builder pattern to create objects with a large number of attributes, where most of them are optional. But up until now, I've defined them as final, as recommended by Joshua Block and other authors, and haven't needed to change their values. I am wondering what should I do though if I need a class with a substantial number of optional but non-final (mutable) attributes? My Builder pattern code looks like this: public class Example { //All possible parameters (optional or not) private final int param1; private final int param2; //Builder class public static class Builder { private final int param1; //Required parameters private int param2 = 0; //Optional parameters - initialized to default //Builder constructor public Builder (int param1) { this.param1 = param1; } //Setter-like methods for optional parameters public Builder param2(int value) { param2 = value; return this; } //build() method public Example build() { return new Example(this); } } //Private constructor private Example(Builder builder) { param1 = builder.param1; param2 = builder.param2; } } Can I just remove the final keyword from the declaration to be able to access the attributes externally (through normal setters, for example)? Or is there a creational pattern that allows optional but non-final attributes that would be better suited in this case?

    Read the article

  • Is it possible to intercept an HTML form post and do some processing before sending it to it's final

    - by Brent
    I'm trying to extend the functionality of an ASP.net application that I'm working with. For its logon page, it uses an html form to post to a dll to handle it's login logic. I'm wondering if there is any way to redirect that html POST to my C# code so that I can do some processing and then (and this is the part that I haven't figured out yet) POST it to the dll so that the regular logon logic can continue. I can make changes to the logon page, but the final step must be to do an HTML POST to the dll. I can't change that.

    Read the article

  • Java: how to initialize private final int value with if-else in constructor?

    - by HH
    $ javac InitInt.java InitInt.java:7: variable right might not have been initialized InitInt(){} ^ 1 error $ cat InitInt.java import java.util.*; import java.io.*; public class InitInt { private final int right; InitInt(){} public static void main(String[] args) { // I don't want to assign any value. // just initialize it, how? InitInt test = new InitInt(); System.out.println(test.getRight()); // later assiging a value } public int getRight(){return right;} } Initialization problem with Constructor, due to if-else -loop InitInt{ // Still the error, "may not be initialized" // How to initialise it, without removing if-else? if(snippetBuilder.length()>(charwisePos+25)){ right=charwisePos+25; }else{ right=snippetBuilder.length()-1; } }

    Read the article

  • Does CodeIgniter have to load view in the final step?

    - by Peter
    I have a function function do_something() { // process $this->load->view('some_view', $data); exec('mv /path/to/folder1/*.mp3 /path/to/folder2/'); } My intention is to move files after outputting the view. But apparently it is done before rendering the view. My question is, does $this->load->view(); have to be the final step in a function? I did a little research, and seems like my question is similar to this topic. Correct?

    Read the article

  • A Good Final High School AP Computer Science Programming Project?

    - by user297663
    Hey guys this question might seem very specific but I am in need of some ideas for a project to do for my last month or so in my AP Computer Science class. I've been looking at some college final ideas and a lot of them just seem plain boring. At first I thought about writing a IRC client in JAVA but I wouldn't really be learning anything "new" that would help me in the future. Then I thought about doing IPhone/touch apps (I don't have an adroid phone and I can easily get my hands on an itouch) but I would need ideas to make apps for that. I want to do something that is going to feel trivial and need some explanation but will also help me in the long run learning new concepts in computer science. If you guys could help out I would greatly appreciate it. I really only have a month to do this project so try to keep the project inside of that range. Also, I don't mind learning new languages. Thanks :)

    Read the article

  • Sprint to the finish: how to keep all team-members busy in the final days of a Scrum sprint?

    - by sdg
    Given that the tasks in a specific sprint will not divide perfectly into the team, and all finish on the same date, what do you do to keep everyone working as the sprint moves into its final stages? Inevitably it seems like there will be one or two people freed-up. If all the other tasks are done-done, and the remaining tasks are already underway, then what? Do those team-members pick up items from the top of the product backlog, as they are likely to be needed in the next sprint anyways to get a head start? What do you or your teams do?

    Read the article

  • How to permanently leave a CALayer rotated at its final location?

    - by David
    Hello, I am trying to rotate a CALayer to a specific angle however, once the animation is done, the layer jumps back to its original position. How would I rotate the layer properly so that it stays at its final destination? Here is the code that I am using CABasicAnimation *rotationAnimation =[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; //Rotate about z-axis [rotationAnimation setFromValue:[NSNumber numberWithFloat:fromDegree]]; [rotationAnimation setToValue:[NSNumber numberWithFloat:toDegree]]; [rotationAnimation setDuration:0.2]; [rotationAnimation setRemovedOnCompletion:YES]; [rotationAnimation setFillMode:kCAFillModeForwards]; Any suggestions? Thank you.

    Read the article

  • How to multiseat with HW 3d accel on CentOS 6.3 Final?

    - by user35070
    I would like to setup a multiseat configuration on CentOS 6.3 (two video cards, two keyboards, two mice, two monitors) and have hardware accelerated 3D on both monitors. 3D HW acceleration rules out Xephyr. I saw somewhere that recent versions of GDM (3.3 and newer?) don't support multiseat, so do I have to install KDM to make this work? If I just create a duplicate section with new device identifiers in my xorg.conf file, will this 'just work'? Using different ports on the same video card and separate keyboards, mice, and displays, the result was a desktop which spanned both monitors with both keyboards and mice acting as the same input in the GUI. I will power down and put in the new video card and report on the results soon. Both video cards are nvidia. UPDATE after putting in another NVIDIA video card, default behavior (before changing xorg.conf) is that one screen works normally, and both mice and keyboards are connected to it. Changing xorg.conf and the display manager to KDM and following the directions here https://help.ubuntu.com/community/MultiseatX#Ubuntu_10.04_.28Lucid.29 , I have 2 mirrored screens connected to separate video cards, DRI enabled, and 2 mice both connected to the same pointer. Keyboards don't do anything, however, I probably just need to fix a setting in xorg.conf I would still like to get multiseat functionality, eg. separate screens with separate input devices I have verified that the separate X processes are running (see page above) using 'ps aux | grepX [01]'

    Read the article

  • Andengine put bullet to pull, when it leaves screen

    - by Ashot
    i'm creating a bullet with physics body. Bullet class (extends Sprite class) has die() method, which unregister physics connector, hide sprite and put it in pull public void die() { Log.d("bulletDie", "See you in hell!"); if (this.isVisible()) { this.setVisible(false); mPhysicsWorld.unregisterPhysicsConnector(physicsConnector); physicsConnector.setUpdatePosition(false); body.setActive(false); this.setIgnoreUpdate(true); bulletsPool.recyclePoolItem(this); } } in onUpdate method of PhysicsConnector i executes die method, when sprite leaves screen physicsConnector = new PhysicsConnector(this,body,true,false) { @Override public void onUpdate(final float pSecondsElapsed) { super.onUpdate(pSecondsElapsed); if (!camera.isRectangularShapeVisible(_bullet)) { Log.d("bulletDie","Dead?"); _bullet.die(); } } }; it works as i expected, but _bullet.die() executes TWICE. what i`m doing wrong and is it right way to hide sprites? here is full code of Bullet class (it is inner class of class that represents player) private class Bullet extends Sprite implements PhysicsConstants { private final Body body; private final PhysicsConnector physicsConnector; private final Bullet _bullet; private int id; public Bullet(float x, float y, ITextureRegion texture, VertexBufferObjectManager vertexBufferObjectManager) { super(x,y,texture,vertexBufferObjectManager); _bullet = this; id = bulletId++; body = PhysicsFactory.createCircleBody(mPhysicsWorld, this, BodyDef.BodyType.DynamicBody, bulletFixture); physicsConnector = new PhysicsConnector(this,body,true,false) { @Override public void onUpdate(final float pSecondsElapsed) { super.onUpdate(pSecondsElapsed); if (!camera.isRectangularShapeVisible(_bullet)) { Log.d("bulletDie","Dead?"); Log.d("bulletDie",id+""); _bullet.die(); } } }; mPhysicsWorld.registerPhysicsConnector(physicsConnector); $this.getParent().attachChild(this); } public void reset() { final float angle = canon.getRotation(); final float x = (float) ((Math.cos(MathUtils.degToRad(angle))*radius) + centerX) / PIXEL_TO_METER_RATIO_DEFAULT; final float y = (float) ((Math.sin(MathUtils.degToRad(angle))*radius) + centerY) / PIXEL_TO_METER_RATIO_DEFAULT; this.setVisible(true); this.setIgnoreUpdate(false); body.setActive(true); mPhysicsWorld.registerPhysicsConnector(physicsConnector); body.setTransform(new Vector2(x,y),0); } public Body getBody() { return body; } public void setLinearVelocity(Vector2 velocity) { body.setLinearVelocity(velocity); } public void die() { Log.d("bulletDie", "See you in hell!"); if (this.isVisible()) { this.setVisible(false); mPhysicsWorld.unregisterPhysicsConnector(physicsConnector); physicsConnector.setUpdatePosition(false); body.setActive(false); this.setIgnoreUpdate(true); bulletsPool.recyclePoolItem(this); } } }

    Read the article

  • Proper Usage of Arrays and Functions [closed]

    - by Ssegawa Victor
    Can some one help me write a C code that solves the following problem. PROBLEM Consider the faculty registrar who has to process results for 1st year 1st semester students. Students offer five courses CSC 1100, CSK 1101, CSC 1104, CSC 1105 and CSC 1106. The courses have credit units 4,4,4,3 and 3 respectively. Lecturers provide course work and exam marks. For each course, course work constitutes 40% of the final mark while the exam constitutes 60% of the final mark. The role of the registrar is to Compute the final mark for each student for each course. The final mark must be a whole number Compute the grade and grade point of the students for each course they offered. According to senate regulations, grades and grade points are awarded to final marks according to the following criteria Range Grade Grade Point 90 – 100 A+ 5.0 80 – 89 A 5.0 75 – 79 B+ 4.5 70 – 74 B 4.0 65 – 69 C+ 3.5 60 – 64 C 3.0 55 – 59 D+ 2.5 50 – 54 D 2.0 45 – 49 E 1.5 40 – 44 E- 1.0 0 – 39 F 0.0 Put a comment ‘Retake’ to a student for every course where the Grade Point is less than 2.0 Compute the cumulative grade point average CGPA for each student. The senate formula for CGPA is GGPA =(?_(i=1)^(i=N)¦?CU _i×GP _i ?)/(?_(i=1)^(i=N)¦CU i) Put a comment “Progress” for any student whose GGPA is greater than 2 and “Stay Put” on a student whose CGPA is less than 2 You are required to create a c program that considers a class of 25 students and: 1.Initializes an array ‘student’ which stores student names 2.Initializes arrays for course work and exam for each course. ‘cw_csc_1100’ and ‘ex_csc_1100’ store course work and exam marks (respectively) for CSC 1100. The same approach is considered for all other courses 3.Initializes the coursework and exam marks arrays with marks between 0 and 99 4.Write appropriate functions that will generate the final marks, generate grades, generate grade points, generate cumulative grade points, generate comments for students and comments for courses per student 5.Create appropriate arrays for final marks and insert the data there using the appropriate functions 6.Without having to create any extra arrays, use the functions created to generate a report per student that looks like the one bellow. Student Name: Ngubiri Course Unit Final mark Grade Grade Point Course Comment CSC 1100 43 E- 1.0 Retake CSK 1101 50 D 2.0 CSC 1104 59 D+ 2.5 CSC 1105 70 B 4.0 CSC 1106 65 C+ 3.5 CGPA 2.47 Overall Comment Progress NB It is advisable that the indices are used to identify the owners. Eg if student[x] is John, then cs_csc_100[x] should be a mark for John since the index is the same

    Read the article

  • Box2D Difference Between WorldCenter and Position

    - by Free Lancer
    So this problem has been brothering for a couple of days now. First off, what is the difference between say Body.getWorldCenter() and Body.getPosition(). I heard that WorldCenter might have to do with the center of gravity or something. Second, When I create a Box2D Body for a sprite the Body is always at the lower left corner. I check it by printing a Rectangle of 1 pixel around the box.getWorldCenter(). From what I understand the Body should be in the center of the Sprite and its bounding box should wrap around the Sprite, correct? Here's an image of what I mean (The Sprite is Red, Body Blue): Here's some code: Body Creator: public static Body createBoxBody( final World pPhysicsWorld, final BodyType pBodyType, final FixtureDef pFixtureDef, Sprite pSprite ) { float pRotation = 0; float pCenterX = pSprite.getX() + pSprite.getWidth() / 2; float pCenterY = pSprite.getY() + pSprite.getHeight() / 2; float pWidth = pSprite.getWidth(); float pHeight = pSprite.getHeight(); final BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = pBodyType; //boxBodyDef.position.x = pCenterX / Constants.PIXEL_METER_RATIO; //boxBodyDef.position.y = pCenterY / Constants.PIXEL_METER_RATIO; boxBodyDef.position.x = pSprite.getX() / Constants.PIXEL_METER_RATIO; boxBodyDef.position.y = pSprite.getY() / Constants.PIXEL_METER_RATIO; Vector2 v = new Vector2( boxBodyDef.position.x * Constants.PIXEL_METER_RATIO, boxBodyDef.position.y * Constants.PIXEL_METER_RATIO ); Gdx.app.log("@Physics", "createBoxBody():: Box Position: " + v); // Temporary Box shape of the Body final PolygonShape boxPoly = new PolygonShape(); final float halfWidth = pWidth * 0.5f / Constants.PIXEL_METER_RATIO; final float halfHeight = pHeight * 0.5f / Constants.PIXEL_METER_RATIO; boxPoly.setAsBox( halfWidth, halfHeight ); // set the anchor point to be the center of the sprite pFixtureDef.shape = boxPoly; final Body boxBody = pPhysicsWorld.createBody(boxBodyDef); Gdx.app.log("@Physics", "createBoxBody():: Box Center: " + boxBody.getPosition().mul(Constants.PIXEL_METER_RATIO)); boxBody.createFixture(pFixtureDef); boxBody.setTransform( boxBody.getWorldCenter(), MathUtils.degreesToRadians * pRotation ); boxPoly.dispose(); return boxBody; } Making the Sprite: public Car( Texture texture, float pX, float pY, World world ) { super( "Car" ); mSprite = new Sprite( texture ); mSprite.setSize( mSprite.getWidth() / 6, mSprite.getHeight() / 6 ); mSprite.setPosition( pX, pY ); mSprite.setOrigin( mSprite.getWidth()/2, mSprite.getHeight()/2); FixtureDef carFixtureDef = new FixtureDef(); // Set the Fixture's properties, like friction, using the car's shape carFixtureDef.restitution = 1f; carFixtureDef.friction = 1f; carFixtureDef.density = 1f; // needed to rotate body using applyTorque mBody = Physics.createBoxBody( world, BodyDef.BodyType.DynamicBody, carFixtureDef, mSprite ); }

    Read the article

  • Andengine. Put bullet to pool, when it leaves screen

    - by Ashot
    i'm creating a bullet with physics body. Bullet class (extends Sprite class) has die() method, which unregister physics connector, hide sprite and put it in pool public void die() { Log.d("bulletDie", "See you in hell!"); if (this.isVisible()) { this.setVisible(false); mPhysicsWorld.unregisterPhysicsConnector(physicsConnector); physicsConnector.setUpdatePosition(false); body.setActive(false); this.setIgnoreUpdate(true); bulletsPool.recyclePoolItem(this); } } in onUpdate method of PhysicsConnector i executes die method, when sprite leaves screen physicsConnector = new PhysicsConnector(this,body,true,false) { @Override public void onUpdate(final float pSecondsElapsed) { super.onUpdate(pSecondsElapsed); if (!camera.isRectangularShapeVisible(_bullet)) { Log.d("bulletDie","Dead?"); _bullet.die(); } } }; it works as i expected, but _bullet.die() executes TWICE. what i`m doing wrong and is it right way to hide sprites? here is full code of Bullet class (it is inner class of class that represents player) private class Bullet extends Sprite implements PhysicsConstants { private final Body body; private final PhysicsConnector physicsConnector; private final Bullet _bullet; private int id; public Bullet(float x, float y, ITextureRegion texture, VertexBufferObjectManager vertexBufferObjectManager) { super(x,y,texture,vertexBufferObjectManager); _bullet = this; id = bulletId++; body = PhysicsFactory.createCircleBody(mPhysicsWorld, this, BodyDef.BodyType.DynamicBody, bulletFixture); physicsConnector = new PhysicsConnector(this,body,true,false) { @Override public void onUpdate(final float pSecondsElapsed) { super.onUpdate(pSecondsElapsed); if (!camera.isRectangularShapeVisible(_bullet)) { Log.d("bulletDie","Dead?"); Log.d("bulletDie",id+""); _bullet.die(); } } }; mPhysicsWorld.registerPhysicsConnector(physicsConnector); $this.getParent().attachChild(this); } public void reset() { final float angle = canon.getRotation(); final float x = (float) ((Math.cos(MathUtils.degToRad(angle))*radius) + centerX) / PIXEL_TO_METER_RATIO_DEFAULT; final float y = (float) ((Math.sin(MathUtils.degToRad(angle))*radius) + centerY) / PIXEL_TO_METER_RATIO_DEFAULT; this.setVisible(true); this.setIgnoreUpdate(false); body.setActive(true); mPhysicsWorld.registerPhysicsConnector(physicsConnector); body.setTransform(new Vector2(x,y),0); } public Body getBody() { return body; } public void setLinearVelocity(Vector2 velocity) { body.setLinearVelocity(velocity); } public void die() { Log.d("bulletDie", "See you in hell!"); if (this.isVisible()) { this.setVisible(false); mPhysicsWorld.unregisterPhysicsConnector(physicsConnector); physicsConnector.setUpdatePosition(false); body.setActive(false); this.setIgnoreUpdate(true); bulletsPool.recyclePoolItem(this); } } }

    Read the article

  • CLR: Multi Param Aggregate, Argument not in Final Output?

    - by OMG Ponies
    Why is my delimiter not appearing in the final output? It's initialized to be a comma, but I only get ~5 white spaces between each attribute using: SELECT [article_id] , dbo.GROUP_CONCAT(0, t.tag_name, ',') AS col FROM [AdventureWorks].[dbo].[ARTICLE_TAG_XREF] atx JOIN [AdventureWorks].[dbo].[TAGS] t ON t.tag_id = atx.tag_id GROUP BY article_id The bit for DISTINCT works fine, but it operates within the Accumulate scope... Output: article_id | col ------------------------------------------------- 1 | a a b c I only have rudimentary C# API knowledge... C# Code: using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using System.Xml.Serialization; using System.Xml; using System.IO; using System.Collections; using System.Text; [Serializable] [SqlUserDefinedAggregate(Format.UserDefined, MaxByteSize = 8000)] public struct GROUP_CONCAT : IBinarySerialize { ArrayList list; string delimiter; public void Init() { list = new ArrayList(); delimiter = ","; } public void Accumulate(SqlBoolean isDistinct, SqlString Value, SqlString separator) { delimiter = (separator.IsNull) ? "," : separator.Value ; if (!Value.IsNull) { if (isDistinct) { if (!list.Contains(Value.Value)) { list.Add(Value.Value); } } else { list.Add(Value.Value); } } } public void Merge(GROUP_CONCAT Group) { list.AddRange(Group.list); } public SqlString Terminate() { string[] strings = new string[list.Count]; for (int i = 0; i < list.Count; i++) { strings[i] = list[i].ToString(); } return new SqlString(string.Join(delimiter, strings)); } #region IBinarySerialize Members public void Read(BinaryReader r) { int itemCount = r.ReadInt32(); list = new ArrayList(itemCount); for (int i = 0; i < itemCount; i++) { this.list.Add(r.ReadString()); } } public void Write(BinaryWriter w) { w.Write(list.Count); foreach (string s in list) { w.Write(s); } } #endregion }

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >