Search Results

Search found 456 results on 19 pages for 'getter'.

Page 11/19 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • How to do pointer work with accessor methods in Objective-C

    - by Jasconius
    Basic problem statement: I have a very good reason for doing some pointer fanciness in an app where I need to pass a decimal by reference. So I have a class which stores many a decimal, so let's say is has a property as such: @property (nonatomic) double myDecimalValue; I want to pass it by reference to some other class. [someOtherObject sendMyDecimalByReference:&myDecimalValue]; But, a problem emerges! The way that actually has to be written (because it's a property) is [someOtherObject sendMyDecimalByReference:&decimalOrigin.myDecimalValue]; This fails to compile in objective-c I get around it by writing the following - (double *) myDecimalValueRef; [someOtherObject sendMyDecimalByReference:[decimalOrigin myDecimalValue]]; Except I have dozens of these decimals and I don't want to write that stupid wrapper function for every value. Is there a shorthand way to do this in Objective-C using just the Getter functions? Let's just assume I have a great reason for not using NSNumber. Thanks!

    Read the article

  • OOP Design Question - Where/When do you Validate properties?

    - by JW
    I have read a few books on OOP DDD/PoEAA/Gang of Four and none of them seem to cover the topic of validation - it seems to be always assumed that data is valid. I gather from the answers to this post (http://stackoverflow.com/questions/1651964/oop-design-question-validating-properties) that a client should only attempt to set a valid property value on a domain object. This person has asked a similar question that remains unanswered: http://bytes.com/topic/php/answers/789086-php-oop-setters-getters-data-validation#post3136182 So how do you ensure it is valid? Do you have a 'validator method' alongside every getter and setter? isValidName() setName() getName() I seem to be missing some key basic knowledge about OOP data validation - can you point me to a book that covers this topic in detail? - ie. covering different types of validation / invariants/ handling feedback / to use Exceptions or not etc

    Read the article

  • How to add a property to a module in boost::python?

    - by Checkers
    You can add a property to a class using a getter and a setter (in a simplistic case): class<X>("X") .add_property("foo", &X::get_foo, &X::set_foo); But how to add a property to a module itself (not a class)? There is scope().attr("globalAttr") = ??? something ??? and def("globalAttr", ??? something ???); I can add global functions and objects of my class using the above two ways, but can't seem to add properties the same way as in classes.

    Read the article

  • Difference between normal and magic setters and getters

    - by Saif Bechan
    I am using a magic getter/setter class for my session variables, but I don't see any difference between normal setters and getters. The code: class session { public function __set($name, $value) { $_SESSION[$name] = $value; } public function __unset($name) { unset($_SESSION[$name]); } public function __get($name) { if(isset($_SESSION[$name])) { return $_SESSION[$name]; } } } Now the first thing I noticed is that I have to call $session->_unset('var_name') to remove the variable, nothing 'magical' about that. Secondly when I try to use $session->some_var this does not work. I can only get the session variable using $_SESSION['some_var']. I have looked at the PHP manual but the functions look the same as mine. Am I doing something wrong, or is there not really anything magic about these functions.

    Read the article

  • How do I memoize expensive calculations on Django model objects?

    - by David Eyk
    I have several TextField columns on my UserProfile object which contain JSON objects. I've also defined a setter/getter property for each column which encapsulates the logic for serializing and deserializing the JSON into python datastructures. The nature of this data ensures that it will be accessed many times by view and template logic within a single Request. To save on deserialization costs, I would like to memoize the python datastructures on read, invalidating on direct write to the property or save signal from the model object. Where/How do I store the memo? I'm nervous about using instance variables, as I don't understand the magic behind how any particular UserProfile is instantiated by a query. Is __init__ safe to use, or do I need to check the existence of the memo attribute via hasattr() at each read? Here's an example of my current implementation: class UserProfile(Model): text_json = models.TextField(default=text_defaults) @property def text(self): if not hasattr(self, "text_memo"): self.text_memo = None self.text_memo = self.text_memo or simplejson.loads(self.text_json) return self.text_memo @text.setter def text(self, value=None): self.text_memo = None self.text_json = simplejson.dumps(value)

    Read the article

  • Is it possible to build a JPA entity by extending a POJO?

    - by Freiheit
    Lets say I have the following POJO: public class MyThing { private int myNumber; private String myData; //assume getter/setter methods } Is it now possible to extend this POJO as a JPA entity? @Entity @Table(name = "my_thing") public class MyThingEntity extends MyThing implements Serializable { @Column(name = "my_number") //????????? @Column(name = "my_data") //???????? } I want to keep the POJO separate from the JPA entity. The POJO lives in a different project and is often used without a persistence layer, my project wants to persist it in a database and do so without the overhead of mapping from a POJO to an entity and back. I understand that JPA entities are POJOs, but in order to use it I would have to include a library that implements javax.persistence and the other projects using the same base object have no use for a persistence layer. Is this possible? Is this a good idea?

    Read the article

  • Is it possible to set properties on a Mock Object in Simpletest

    - by JW
    I normally use getter and setter methods on my objects and I am fine with testing them as mock objects in SimpleTest by manipulating them with code like: Mock::generate('MyObj'); $MockMyObj->setReturnValue('getPropName', 'value') However, I have recently started to use magic interceptors (__set() __get()) and access properties like so: $MyObj->propName = 'blah'; But I am having difficulty making a mock object have a particular property accessed by using that technique. So is there some special way of setting properties on MockObjects. I have tried doing: $MockMyObj->propName = 'test Value'; but this does not seem to work. Not sure if it is my test Subject, Mock, magic Interceptors, or SimpleTest that is causing the property to be unaccessable. Any advice welcome.

    Read the article

  • Multithreading and booleans

    - by Ikaso
    Hi Everyone, I have a class that contains a boolean field like this one: public class MyClass { private boolean boolVal; public boolean BoolVal { get { return boolVal; } set { boolVal = value; } } } The field can be read and written from many threads using the property. My question is if I should fence the getter and setter with a lock statement? Or should I simply use the volatile keyword and save the locking? Or should I totally ignore multithreading since getting and setting boolean values atomic? regards,

    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

  • F#: Define an abstract class that inherits an infterface, but does not implement it

    - by akaphenom
    I owuld like to define an abstract class that inerhits from UserControl and my own Interface IUriProvider, but doesn't implement it. The goal is to be able to define pages (for silverlight) that implement UserControl but also provide their own Uri's (and then stick them in a list / array and deal with them as a set: type IUriProvider = interface abstract member uriString: String ; abstract member Uri : unit -> System.Uri ; end type UriUserControl() as this = inherit IUriProvider with abstract member uriString: String ; inherit UserControl() Also the Uri in the definition - I would like to implement as a property getter - and am having issues with that as well. this does not compile type IUriProvider = interface abstract member uriString: String with get; end Thank you...

    Read the article

  • Problem regarding listShuttle component in richFaces ?

    - by Hari
    I am a newbee for Richfaces components, When i am using the <rich:listShuttle> the Arraylist specified in the targetValue is now getting updated with the latest data? Kindly help MyJSF File <a4j:region> <rich:listShuttle sourceValue="#{bean.selectItems}" id="one" targetValue="#{bean.selectItemsone}" var="items" listsHeight="150" sourceListWidth="130" targetListWidth="130" sourceCaptionLabel="Intial Items" targetCaptionLabel="Selected Items" converter="Listconverter"> <rich:column> <h:outputText value="#{items.value}"></h:outputText> </rich:column> </rich:listShuttle> </a4j:region> <a4j:region> <a4j:commandButton value="Submit" action="#{bean.action}" /> </a4j:region> My Managed Bean enter code here private List<String> selectedData; private List<BeanItems> selectItems; private List<BeanItems> selectItemsone; public String action() { System.out.println(selectItems); System.out.println(selectItemsone); System.out.println("Select Item List"); Iterator<BeanItems> iterator = selectItems.iterator(); while (iterator.hasNext()) { BeanItems item = (BeanItems) iterator.next(); System.out.println(item.getValue()); } System.out.println("/nSelect Item one list "); Iterator<BeanItems> iterator2 = selectItemsone.iterator(); while (iterator2.hasNext()) { BeanItems item = (BeanItems) iterator2.next(); System.out.println(item.getValue()); } return ""; } public void setSelectedData(List<String> selectedData) { this.selectedData = selectedData; } public List<String> getSelectedData() { return selectedData; } /** * @return the selectItems */ public List<BeanItems> getSelectItems() { if (selectItems == null) { selectItems = new ArrayList<BeanItems>(); selectItems.add(new BeanItems("value4", "label4")); selectItems.add(new BeanItems("value5", "label5")); selectItems.add(new BeanItems("value6", "label6")); selectItems.add(new BeanItems("value7", "label7")); selectItems.add(new BeanItems("value8", "label8")); selectItems.add(new BeanItems("value9", "label9")); selectItems.add(new BeanItems("value10", "label10")); } return selectItems; } /** * @return the selectItemsone */ public List<BeanItems> getSelectItemsone() { if (selectItemsone == null) { selectItemsone = new ArrayList<BeanItems>(); selectItemsone.add(new BeanItems("value1", "label1")); selectItemsone.add(new BeanItems("value2", "label2")); selectItemsone.add(new BeanItems("value3", "label3")); } return selectItemsone; } My Converter Class enter code here public Object getAsObject(FacesContext context, UIComponent component,String value) { int index = value.indexOf(':'); return new BeanItems(value.substring(0, index), value.substring(index + 1)); } public String getAsString(FacesContext context, UIComponent component,Object value) { BeanItems beanItems = (BeanItems) value; return beanItems.getValue() + ":" + beanItems.getData(); } My BeanItems Class enter code here private String data; //Getter & setter private String value; //Getter & setter public BeanItems() { } public BeanItems(String value, String data) { this.value = value; this.data = data; } public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((data == null) ? 0 : data.hashCode()); result = prime * result + ((value == null) ? 0 : value.hashCode()); return result; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final BeanItems other = (BeanItems) obj; if (data == null) { if (other.data != null) return false; } else if (!data.equals(other.data)) return false; if (value == null) { if (other.value != null) return false; } else if (!value.equals(other.value)) return false; return true; }

    Read the article

  • Changing the value of an NSImageView when it is edited via the control

    - by Septih
    Hello, I have an NSImageView which is set to editable. I would like to be able to revert to a default image when the user deletes the image. I've tried changing the value that the NSImageView is bound to in the setter, but the getter is not called afterwards, so the NSImageView is blank, despite the bound value being set to another image. Here is the setter code: -(void)setCurrentDeviceIcon:(NSImage *)newIcon { [self willChangeValueForKey:@"currentDeviceIcon"]; if(newIcon == nil) newIcon = [currentDevice defaultHeadsetIcon]; currentDeviceIcon = newIcon; [self setDeviceChangesMade:YES]; [self didChangeValueForKey:@"currentDeviceIcon"]; } How should I make the NSImageView update it's value? Thank You.

    Read the article

  • Hibernate - moving annotations from property (method) level to field level

    - by kan
    How do I generate hibernate domain classes from tables with annotations at field level? I used Hibernate Tools project and generated domain classes from the tables in the database. The generated classes have annotations on the getter methods rather than at the field level. Kindly advice a way to generate domain classes that have the fields annotated. Is there any refactoring facility available in eclipse/IDEA etc.. to move the annotations from method level to field level? Appreciate your help and time.

    Read the article

  • Setting a value into a object using reflection

    - by marionmaiden
    Hello I have an object that has a lot of attributes, each one with it's getter and setter. Each attribute has a non primitive type, that I don't know at runtime. For example, what I have is this: public class a{ private typeA attr1; private typeB attr2; public typeA getAttr1(){ return attr1; } public typeB getAttr2(){ return attr2; } public void setAttr1(typeA at){ attr1 = at; } public void setAttr2(typeB at){ attr2 = at; } } public class typeA{ public typeA(){ // doesn't matter } } public class typeB{ public typeB(){ // doesn't matter } } So, using reflection, I obtained the setter method for an attribute. Setting a value in the standard way is something like this: a test = new a(); a.setAttr1(new typeA()); But how can I do this using reflection? I already got the setAttr1() method using reflection, but I don't know how to create a new typeA object to be inserted in the setter.

    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

  • Using Session Bean provided data on JSF welcome page

    - by takachgeza
    I use JSF managed beans calling EJB methods that are provide data from database. I want to use some data already on the welcome page of the application. What is the best solution for it? EJBs are injected into JSF managed beans and it looks like the injection is done after executing the constructor. So I am not able to call EJB methods in the constructor. The normal place for EJB call is in the JSF action methods but how to call such a method prior to loding the first page of the application? A possible solution would be to call the EJB method conditionally in a getter that is used on the welcome page, for example: public List getProductList(){ if (this.productList == null) this.productList = myEJB.getProductList(); return this.productList; } Is there any better solution? For example, in some config file?

    Read the article

  • Formatting a string in Java using class attributes

    - by Jason R. Coombs
    I have a class with an attribute and getter method: public Class MyClass { private String myValue = "foo"; public String getMyValue(); } I would like to be able to use the value of foo in a formatted string as such: String someString = "Your value is {myValue}." String result = Formatter.format(someString, new MyClass()); // result is now "Your value is foo." That is, I would like to have some function like .format above which takes a format string specifying properties on some object, and an instance with those properties, and formats the string accordingly. Is it possible to do accomplish this feat in Java?

    Read the article

  • Problem updating blog with hibernate?

    - by johnsmith51
    hi, i am having problem updating a blob with hibernate. my model have these getters/setters for hibernate, i.e. internally i deal with byte[] so any getter/setter convert the byte[] to blog. I can create an initial object without problem, but if I try to change the content of the blob, the database column is not updated. I do not get any error message, everything looks fine, except that the database is not updated. /** do not use, for hibernate only */ public Blob getLogoBinaryBlob() { if(logoBinary == null){ return null; } return Hibernate.createBlob(logoBinary); } /** do not use, for hibernate only */ public void setLogoBinaryBlob(Blob logoBinaryBlob) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { logoBinary = toByteArrayImpl(logoBinaryBlob, baos); } catch (Exception e) { } }

    Read the article

  • GWT and Mock the view in MVP pattern

    - by Yannick Eurin
    Hello, i dunno if the question is already ask, but i couldn't find it... i'm searching a way to mock my view in order to test my presenter ? i try to use mockito for the view, and set it in the presenter, but in result in presenter, when i call presenter.getDisplay() (the getter for the view) all of my widget is null ? as i believe it's normal mockito will not mock the widget. i'm 100% sure i mistaken something but i couldnt find it. thanks for your enlightement :)

    Read the article

  • What do you use for recurring payments in a Rails Application?

    - by Chance
    I'm fairly new to rails so I'm definitely not up to speed on the community's best practices, tools, etc. So I figure this may be the best place to ask. What do you use for recurring billing in a rails app? From what I can tell, there are a number of options including rolling my own with ActiveMerchant or using one of the SaaS out there. As far as the SaaS recurring billing systems, I've only stumbled upon one thus far (chedder getter) and I'm hoping there are alternatives (if, for nothing else, so I can compare). Additionally, I've seen a few invoice systems but they either do not handle the payment portion, do not seem to fit well with the intention, or are extremely outdated. Thanks in advance!

    Read the article

  • Multiple Submit Buttons problem in Struts2

    - by umesh awasthi
    Hi All, Trying to work with multiple submit buttons within a single form in struts2 application but not able to work. here is the jsp code i am using <tr> <td class="button"><input type="submit" value="Import" name="destinationImport" class="button"></td> <td class="button"><input type="submit" value="Export" name="destinationExport" class="button"></td> </tr> here is the java part private boolean destinationImport; private boolean destinationExport; and there respective setter and getter but i am sure is that Struts2 type convertor is having problem converting the String value to boolean do any one have idea how to achieve this Thanks in advance

    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

  • Querying and ordering results of a database in grails using transient fields

    - by Azder
    I'm trying to display paged data out of a grails domain object. For example: I have a domain object Employee with the properties firstName and lastName which are transient, and when invoking their setter/getter methods they encrypt/decrypt the data. The data is saved in the database in encrypted binary format, thus not sortable by those fields. And yet again, not sortable by transient ones either, as noted in: http://www.grails.org/GSP+Tag+-+sortableColumn . So now I'm trying to find a way to use the transients in a way similar to: Employee.withCriteria( max: 10, offset: 30 ){ order 'lastName', 'asc' order 'firstName', 'asc' } The class is: class Employee { byte[] encryptedFirstName byte[] encryptedLastName static transients = [ 'firstName', 'lastName' ] String getFirstName(){ decrypt("encryptedFirstName") } void setFirstName(String item){ encrypt("encryptedFirstName",item) } String getLastName(){ decrypt("encryptedLastName") } void setLastName(String item){ encrypt("encryptedLastName",item) } }

    Read the article

  • HttpRequestValidationexception on Asp.Net MVC

    - by elranu
    I’m getting an HttpRequestValidationexception with this error message: “A potentially dangerous Request.Form value was detected from the client”. But I have AllowHtml on the property that I’m getting the error. The problem is that later in my code I’m getting the following property to know in witch format I will show my view ControllerContext.HttpContext.Request.Params.AllKeys.Contains("format"). And on this “Param Getter” I’m getting the error. Let’s say my code is similar to the following: public class House { [AllowHtml] public string Text { get; set; } public string Name { get; set; } } [HttpPost, ValidateAntiForgeryToken] public ActionResult CreateTopic(House h) { //business code if(ControllerContext.HttpContext.Request.Params.AllKeys.Contains("format")) { Return view; } } How can I solve this? I already try with the ValidateInput(false) attribute on the controller action method. Any idea?

    Read the article

  • Catching constraint violations in JPA 2.0.

    - by Dennetik
    Consider the following entity class, used with, for example, EclipseLink 2.0.2 - where the link attribute is not the primary key, but unique nontheless. @Entity public class Profile { @Id private Long id; @Column(unique = true) private String link; // Some more attributes and getter and setter methods } When I insert records with a duplicate value for the link attribute, EclipseLink does not throw a EntityExistsException, but throws a DatabaseException, with the message explaining that the unique constraint was violated. This doesn't seem very usefull, as there would not be a simple, database independent, way to catch this exception. What would be the advised way to deal with this? A few things that I have considered are: Checking the error code on the DatabaseException - I fear that this error code, though, is the native error code for the database; Checking the existence of a Profile with the specific value for link beforehand - this obviously would result in an enormous amount of superfluous queries.

    Read the article

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