Search Results

Search found 674 results on 27 pages for 'magical getters setters'.

Page 3/27 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • FitNesse doesn't call setters in my fixture

    - by Maurits Rijk
    I have copied a trivial example from the FitNesse Two-Minute example: package com.mrijk; import fit.ColumnFixture; public class Foobar extends ColumnFixture { private double numerator; private double denominator; public void setNumerator(double numerator) {this.numerator = numerator;} public void setDenominator(double denominator) {this.denominator = denominator;} public double quotient() {return numerator/denominator;} } However all test fail with: "Could not find field: denominator.", so obviously the setDenominator is not found/used. When I make the the variables numerator and denominator public instead of private, the tests run successfully. I must be overlooking something, but can't see it yet. Anyone?

    Read the article

  • Using getters/setters in Java

    - by Crystal
    I'm having some trouble with the idea of accessing variables from other classes. I had a post here: http://stackoverflow.com/questions/3011642/having-access-to-a-private-variable-from-other-classes-in-java where I got some useful information, and thought an example would be better show it, and ask a separate question as well. I have a form that I can input data to, and it has a List variable. I didn't make it static at first, but I thought if I needed to get the total size from another class, then I wouldn't create an instance of that class in order to use the function to getTotalContacts. I basically want to update my status bar with the total number of contacts that are in my list. One of the members said in the above post to use the original Foo member to get the contacts, but I'm not sure how that works in this case. Any thoughts would be appreciated. Thanks. import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.List; import java.util.ArrayList; public class AddressBook { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { AddressBookFrame frame = new AddressBookFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); JMenuItem saveItem = new JMenuItem("Save"); JMenuItem saveAsItem = new JMenuItem("Save As"); JMenuItem printItem = new JMenuItem("Print"); JMenuItem exitItem = new JMenuItem("Exit"); fileMenu.add(openItem); fileMenu.add(saveItem); fileMenu.add(saveAsItem); fileMenu.add(printItem); fileMenu.add(exitItem); menuBar.add(fileMenu); JMenu editMenu = new JMenu("Edit"); JMenuItem newItem = new JMenuItem("New"); JMenuItem editItem = new JMenuItem("Edit"); JMenuItem deleteItem = new JMenuItem("Delete"); JMenuItem findItem = new JMenuItem("Find"); JMenuItem firstItem = new JMenuItem("First"); JMenuItem previousItem = new JMenuItem("Previous"); JMenuItem nextItem = new JMenuItem("Next"); JMenuItem lastItem = new JMenuItem("Last"); editMenu.add(newItem); editMenu.add(editItem); editMenu.add(deleteItem); editMenu.add(findItem); editMenu.add(firstItem); editMenu.add(previousItem); editMenu.add(nextItem); editMenu.add(lastItem); menuBar.add(editMenu); JMenu helpMenu = new JMenu("Help"); JMenuItem documentationItem = new JMenuItem("Documentation"); JMenuItem aboutItem = new JMenuItem("About"); helpMenu.add(documentationItem); helpMenu.add(aboutItem); menuBar.add(helpMenu); frame.setVisible(true); } }); } } class AddressBookFrame extends JFrame { public AddressBookFrame() { setLayout(new BorderLayout()); setTitle("Address Book"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); AddressBookToolBar toolBar = new AddressBookToolBar(); add(toolBar, BorderLayout.NORTH); AddressBookStatusBar aStatusBar = new AddressBookStatusBar(); add(aStatusBar, BorderLayout.SOUTH); AddressBookForm form = new AddressBookForm(); add(form, BorderLayout.CENTER); } public static final int DEFAULT_WIDTH = 500; public static final int DEFAULT_HEIGHT = 500; } /* Create toolbar buttons and add buttons to toolbar */ class AddressBookToolBar extends JPanel { public AddressBookToolBar() { setLayout(new FlowLayout(FlowLayout.LEFT)); JToolBar bar = new JToolBar(); JButton newButton = new JButton("New"); JButton editButton = new JButton("Edit"); JButton deleteButton = new JButton("Delete"); JButton findButton = new JButton("Find"); JButton firstButton = new JButton("First"); JButton previousButton = new JButton("Previous"); JButton nextButton = new JButton("Next"); JButton lastButton = new JButton("Last"); bar.add(newButton); bar.add(editButton); bar.add(deleteButton); bar.add(findButton); bar.add(firstButton); bar.add(previousButton); bar.add(nextButton); bar.add(lastButton); add(bar); } } /* Creates the status bar string */ class AddressBookStatusBar extends JPanel { public AddressBookStatusBar() { setLayout(new FlowLayout(FlowLayout.LEFT)); this.statusBarString = new JLabel("Total: " + AddressBookForm.getTotalContacts()); add(this.statusBarString); } public void updateLabel() { contactsLabel.setText(AddressBookForm.getTotalContacts().toString()); } private JLabel statusBarString; private JLabel contactsLabel; } class AddressBookForm extends JPanel { public AddressBookForm() { // create form panel this.setLayout(new GridLayout(2, 1)); JPanel formPanel = new JPanel(); formPanel.setLayout(new GridLayout(4, 2)); firstName = new JTextField(20); lastName = new JTextField(20); telephone = new JTextField(20); email = new JTextField(20); JLabel firstNameLabel = new JLabel("First Name: ", JLabel.LEFT); formPanel.add(firstNameLabel); formPanel.add(firstName); JLabel lastNameLabel = new JLabel("Last Name: ", JLabel.LEFT); formPanel.add(lastNameLabel); formPanel.add(lastName); JLabel telephoneLabel = new JLabel("Telephone: ", JLabel.LEFT); formPanel.add(telephoneLabel); formPanel.add(telephone); JLabel emailLabel = new JLabel("Email: ", JLabel.LEFT); formPanel.add(emailLabel); formPanel.add(email); add(formPanel); // create button panel JPanel buttonPanel = new JPanel(); JButton insertButton = new JButton("Insert"); JButton displayButton = new JButton("Display"); ActionListener insertAction = new AddressBookListener(); ActionListener displayAction = new AddressBookListener(); insertButton.addActionListener(insertAction); displayButton.addActionListener(displayAction); buttonPanel.add(insertButton); buttonPanel.add(displayButton); add(buttonPanel); } public static int getTotalContacts() { return addressList.size(); } //void addContact(Person contact); private JTextField firstName; private JTextField lastName; private JTextField telephone; private JTextField email; private JLabel contacts; private static List<Person> addressList = new ArrayList<Person>(); private class AddressBookListener implements ActionListener { public void actionPerformed(ActionEvent e) { String buttonPressed = e.getActionCommand(); System.out.println(buttonPressed); if (buttonPressed == "Insert") { Person aPerson = new Person(firstName.getText(), lastName.getText(), telephone.getText(), email.getText()); addressList.add(aPerson); } else { for (Person p : addressList) { System.out.println(p); } } } } } My other question is why do I get the error, "int cannot be dereferenced contactsLabel.setText(AddressbookForm.getTotalContacts().toString()); Thanks!

    Read the article

  • .NET Reflector and getters/setters issue

    - by Humberto
    I'm using an up-to-date .NET Reflector to disassemble an internal legacy app whose source code is almost impossible to recover. I need to find the cause of a nasty bug, and then possibly patch it. Reflector did a good job as usual in the re-creation of the project's structure, but soon I discovered that every property call was left "expanded" to its get_() and set_() method signatures, rendering the source code impossible to compile. A quick Visual Studio "Search/Replace" with regex solved these cases, but it's awkward. Is there a way to make Reflector behave correctly?

    Read the article

  • Using setters On Int?

    - by fuzzygoat
    Just curious, given: unsigned int pulseCounter_001; @property(nonatomic, assign)unsigned int pulseCounter_001; @synthesize pulseCounter_001; Is there any reason to use: [self setPulseCounter_001:0]; Or just use: pulseCounter_001 = 0; Style wise I think the latter says "we are setting an int" better, just curious as to any overheads involved in each? gary

    Read the article

  • Java language convention; getters/setters

    - by Skogen
    Public class Example { private int number; public Example(int number){ this.number = number; } public int getNumber(){ return number; } public void setNumber(int number){ this.number = number; } public static void main(String[] args){ Example e = new Example(5); What is preffered when accessing a variable within its own class; "e.number" or "e.getNumber()" ?

    Read the article

  • ASP.NET C# Application Object Getters and Setters

    - by kellax
    I have had a hard time finiding a newbie friendly example of accessing Application Object. I have few things ( arrays ) i would like to store in Application Object to keep as persistant data for about 2h till AppRecycle Anyhow i know how to set an Application Object variable this way: // One way String[] users = new String[1000]; Application["users"] = users; // Another way Application.Add("users", users); However i do not know how to access these variables once in Application Object there is a Getter method Get however it requires int index and other one Contents which get's everything. Here i try to retrive my String[] array but gives me a error that i am trying to convert Object to String. String[] usersTable = Application["users"]; // Since this is an object i also tried Application.users but gives error

    Read the article

  • Packages name conflicting with getters and setters?

    - by MrKishi
    Hello, folks. So, I've came across this compilation error a while ago.. As there's an easy fix and I didn't find anything relevant at the time, I eventually let it go. I just remembered it and I'm now wondering if this is really part of the language grammar (which I highly doubt) or if it's a compiler bug. I'm being purely curious about this -- it doesn't really affect development, but it would be nice to see if any of you have seen this already. package view { import flash.display.Sprite; public class Main extends Sprite { private var _view:Sprite = new Sprite(); public function Main() { this.test(); } private function test():void { trace(this.view.x, this.view.y); //1178: Attempted access of inaccessible property x through a reference with static type view:Main. //1178: Attempted access of inaccessible property y through a reference with static type view:Main. //Note that I got this due to the package name. //It runs just fine if I rename the package or getter. } public function get view():Sprite { return this._view; } } }

    Read the article

  • Doesn't (didn't) Scala have automatically generated setters?

    - by Malvolio
    Google and my failing memory are both giving me hints that it does, but every attempt is coming up dry. class Y { var y = 0 } var m = new Y() m.y_(3) error: value y_ is not a member of Y Please tell me I am doing something wrong. (Also: please tell me what it is I am doing wrong.) EDIT The thing I am not doing wrong, or at least not the only thing I am doing wrong, is the way I am invoking the setter. The following things also fail, all with the same error message: m.y_ // should be a function valued expression m.y_ = (3) // suggested by Google and by Mchl f(m.y_) // where f takes Int => Unit as an argument f(m.y) // complains that I am passing in Int not a function I am doing this all through SimplyScala, because I'm too lazy and impatient to set up Scala on my tiny home machine. Hope it isn't that... And the winner is ... Fabian, who pointed out that I can't have a space between the _ and the =. I thought out why this should be and then it occurred to me: The name of the setter for y is not y_, it is y_= ! Observe: class Y { var y = 0 } var m = new Y() m.y_=(3) m.y res1: Int = 3 m.y_= error: missing arguments for method y_= in class Y; follow this method with `_` if you want to treat it as a partially applied function m.y_= ^ m.y_=_ res2: (Int) => Unit = def four(f : Int => Unit) = f(4) four(m.y_=) m.y res3: Int = 4 Another successful day on StackExchange.

    Read the article

  • How to discover getters and setters on hibernate objects

    - by Michael Jones
    I need to find a way of taking a hibernate object and discovering at runtime all of the getter methods that relate to persistable fields. I'm using annotations in the classes but have previously had difficulties working with them (I ran into a 2 year old bug the java developers still haven't fixed). Does anyone know how I can do this please, ideally without using annotations? Thanks. PS - What I'm trying to do here is to update a new object with values from an existing object dynamically.

    Read the article

  • iPhone : Primitives getters and setters

    - by Burf2000
    I feel a bit miffed at the moment, I done a few iPhone projects that use floats and ints etc and all is fine. I now using OpenGL and GLFloat[] C arrays etc and it seems unless I make methods to set / get them it crashes on the device (not the simulator). Now as these are not setup as properties (I don't think c arrays can) it kind of makes sense. However the project has been working for months without them. It seems something in the code is wiping out anything float / ints to the point that the debugger can see an assigned value but accessing it crashes the phone. As soon as I think I know something for this platform, something changes my mind lol.

    Read the article

  • Java nullPointerException with getter and setters on an object

    - by 12345
    I'm getting a nullPointerException below. Can someone explain why? Thanks! private SpatialPooler spatialPooler; private Region region; private Column column33; public void setUp() { this.spatialPooler = new SpatialPooler(); this.region = new Region(30, 40, 6, 8, 1.0f, 1, 1); this.column33 = this.region.getColumn(3, 3); } public void addActiveColumn(Column activeColumn) { this.activeColumns.add(activeColumn); // nullPointerException here! } public Column getActiveColumn(int x, int y) { for (Column activeColumn : this.activeColumns) { if (activeColumn.getX() == x && activeColumn.getY() == y) { return activeColumn; } } return null; } // in a test class that is in the same package. public void testGetAndAddActiveColumn() { this.spatialPooler.addActiveColumn(this.column33); assertNull(this.spatialPooler.getActiveColumn(3, 3)); this.column33.setActiveState(true); assertEquals(this.column33, this.spatialPooler.getActiveColumn(3, 3)); }

    Read the article

  • Overriding Doctrine_Record (sfDoctrineRecord) instance methods in Doctrine PHP Symfony

    - by notbrain
    My background is in Propel, so I was hoping it would be a simple thing to override a magical getter in a Doctrine_Record (sfDoctrineRecord), but I'm getting either a Segfault or the override method is simply ignored in favor of the one in the superclass. https://gist.github.com/697008eaf4d7b606286a class FaqCategory extends BaseFaqCategory { public function __toString() { return $this->getCategory(); } // doesn't work // override getDisplayName to fall back to category name if getDisplayName doesn't exist public function getDisplayName() { // also tried parent::getDisplayName() but got segfault(!) if(isset($this->display_name)) { $display_name = $this->display_name; } else { $display_name = $this->category; } return $display_name; } } What is the proper Doctrine way to extend/override methods on an instance of Doctrine_Record (via sfDoctrineRecord extends Doctrine_Record)? This has to be doable...or should I be looking at the Template documentation? Thanks, Brian

    Read the article

  • Is it possible to auto generate Getter/Setter from Array Values in PHP?

    - by Phill Pafford
    So I have a couple of arrays $array_1 = Array('one','two','three'); $array_2 = Array('red','blue','green'); Is there a dynamic way to create the Setters and Getters for an array with single value entries? So the class would be something like: class xFromArray() { } So the above if I passed $array_1 it would generate something like this: private $one; setOne($x) { $one = $x; } getOne() { return $one; } if I passed $array_2 it would generate something like this: private $red; setRed($x) { $red = $x; } getRed() { return $red; } So I would call it somehow like this? (My best guess but doesn't seem that this would work) $xFromArray = new xFromArray; foreach($array_1 as $key=>$data) { $xFromArray->create_function(set.ucfirst($data)($data)); echo $xFromArray->create_function(get.ucfirst($data)); }

    Read the article

  • xCode "Property access results unused - getters should not be used for side effects"

    - by David DelMonte
    Hi all, I'm getting this warning when I'm calling a local routine. My code is this: -(void)nextLetter { // NSLog(@"%s", __FUNCTION__); currentLetter ++; if(currentLetter > (letters.count - 1)) { currentLetter = 0; } self.fetchLetter; } I'm getting the warning on the self.fetchLetter statement. That routine looks like this: - (void)fetchLetter { // NSLog(@"%s", __FUNCTION__); NSString *wantedLetter = [[letters objectAtIndex: currentLetter] objectForKey: @"langLetter"]; NSString *wantedUpperCase = [[letters objectAtIndex: currentLetter] objectForKey: @"upperCase"]; ..... } I prefer to fix warning messages, is there a better way to write this? Thanks!

    Read the article

  • Mockito verify no more interactions but omit getters

    - by michael lucas
    Mockito api provides method: Mockito.verifyNoMoreInteractions(someMock); but is it possible in Mockito to declare that I don't want more interactions with a given mock with the exceptions of interactions with its getter methods? The simple scenario is the one in which I test that sut changes only certain properties of a given mock and lefts other properties untapped. In example I want to test that UserActivationService changes property Active on an instance of class User but does't do anything to properties like Role, Password, AccountBalance, etc. I'm open to criticism regarding my approach to the problem.

    Read the article

  • Declaration of struct variables in other class when obtained by getters

    - by liaK
    Hi, I am using Qt 4.5 so do C++. I have a class like this class CClass1 { private: struct stModelDetails { QString name; QString code; ..... // only variables and no functions over here }; QList<stModelDetails> m_ModelDetailsList; public: QList<stModelDetails> getModelDetailsList(); ... }; In this I have functions that will populate the m_ModelDetailsList; I have another class say CClassStructureUsage, where I will call the getModelDetailsList() function. Now my need is that I have to traverse the QList and obtain the name, code from each of the stModelDetails. Now the problem is even the CClass1's header file is included it is not able to identify the type of stModelDetails in CClassStructureUsage. When I get the structure list by QList<stModelDetails> ModelList = obj->getModelInformationList(); it says stModelDetails : undeclared identifier. How I can able to fetch the values from the structure? Am I doing anything wrong over here?

    Read the article

  • Is it a "pattern smell" to put getters like "FullName" or "FormattedPhoneNumber" in your model?

    - by DanM
    I'm working on an ASP.NET MVC app, and I've been getting into the habit of putting what seem like helpful and convenient getters into my model/entity classes. For example: public class Member { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string PhoneNumber { get; set; } public string FullName { get { return FirstName + " " + LastName; } } public string FormattedPhoneNumber { get { return "(" + PhoneNumber.Substring(0, 3) + ") " + PhoneNumber.Substring(3, 3) + "-" + PhoneNumber.Substring(6); } } } I'm wondering people think about the FullName and FormattedPhoneNumber getters. They make it very easy to create standardized data formats throughout the app, and they seem to save a lot of repeated code, but it could definitely be argued that data format is something that should be handled in mapping from model to view-model. In fact, I was originally applying these data formats in my service layer where I do my mapping, but it was becoming a burden to constantly have to write formatters then apply them in many different places. E.g., I use "Full Name" in most views, and having to type something like model.FullName = MappingUtilities.GetFullName(entity.FirstName, entity.LastName); all over the place seemed a lot less elegant than just typing model.FullName = entity.FullName (or, if you use something like AutoMapper, potentially not typing anything at all). So, where do you draw the line when it comes to data formatting. Is it "okay" to do data formatting in your model or is that a "pattern smell"? Note: I definitely do not have any html in my model. I use html helpers for that. I'm strictly talking about formatting or combining data (and especially data that is frequently used).

    Read the article

  • Objective-C member variable assignment?

    - by Alex
    I have an objective-c class with member variables. I am creating getters and setters for each one. Mostly for learning purposes. My setter looks like the following: - (void) setSomething:(NSString *)input { something = input; } However, in C++ and other languages I have worked with in the past, you can reference the member variable by using the this pointer like this->something = input. In objective-c this is known as self. So I was wondering if something like that is possible in objective-c? Something like this: - (void) setSomething:(NSString *)input { [self something] = input; } But that would call the getter for something. So I'm not sure. So my question is: Is there a way I can do assignment utilizing the self pointer? If so, how? Is this good practice or is it evil? Thanks!

    Read the article

  • Getter/setter on javascript array?

    - by Martin Hansen
    Is there a way to get a get/set behaviour on an array? I imagine something like this: var arr = ['one', 'two', 'three']; var _arr = new Array(); for (var i=0; i < arr.length; i++) { arr[i].defineGetter('value', function(index) { //Do something return _arr[index]; }); arr[i].defineSetter('value', function(index, val) { //Do something _arr[index] = val; }); };

    Read the article

  • Value object getter

    - by sarah xia
    Hi, I've got a value object, which stores info for example amount. The getAmount() getter returns amount in cents. However in various places, we need to get amount in dollar. There are 2 approaches I can think of: write a convert method and place it in a utility class. add a getAmountInDollar() getter in the value object. I prefer the second approach. What do you think? What are pros and cons of both approaches?

    Read the article

  • Using .NET XmlSerializer with get properties and setter functions

    - by brone
    I'm trying to use XmlSerializer from C# to save out a class that has some values that are read by properties (the code being just a simple retrieval of field value) but set by setter functions (since there is a delegate called if the value changes). What I'm currently doing is this sort of thing. The intended use is to use the InT property to read the value, and use SetInT to set it. Setting it has side-effects, so a method is more appropriate than a property here. XmlSerializationOnly_InT exists solely for the benefit of the XmlSerializer (hence the name), and shouldn't be used by normal code. class X { public double InT { get { return _inT; } } public void SetInT(double newInT) { if (newInT != _inT) { _inT = newInT; Changed();//includes delegate call; potentially expensive } } private double _inT; // not called by normal code, as the property set is not just a simple // field set or two. [XmlElement(ElementName = "InT")] public double XmlSerializationOnly_InT { get { return InT; } set { SetInT(value); } } } This works, it's easy enough to do, and the XML file looks like you'd expect. It's manual labour though, and a bit ugly, so I'm only somewhat satisfied. What I'd really like is to be able to tell the XML serialization to read the value using the property, and set it using the setter function. Then I wouldn't need XmlSerializationOnly_InT at all. I seem to be following standard practise by distinguishing between property sets and setter functions in this way, so I'm sure I'm not the only person to have encountered this (though google suggests I might be). What have others done in this situation? Is there some easy way to persuade the XmlSerializer to handle this sort of thing better? If not, is there perhaps some other easy way to do it?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >