Is there a good reason to put
parent::__construct($config)
in the construct of a CakePHP data source I am developing? I see it being used in some of the data sources found in https://github.com/cakephp/datasources/blob/master/models/datasources/amazon_associates_source.php but not sure why. I could just do
private $_config = array();
function construct($config){
$this->_config = $config;
}
and access my $config the same way.
is it not possible to define a static const array? i would like to have an optional parameter to a function that is an array of colors,
private static const DEFAULT_COLORS:Array = new Array(0x000000, 0xFFFFFF);
public function myConstructor(colorsArray:Array = DEFAULT_COLORS)
{
}
i know i can use ...args but i actually wanting to supply the constructor with 2 separate arrays as option arguments.
I'm looking into updating LoopJ's autocomplete plug-in. I want to override one of the methods (highlight_term to be exact) however it looks like that method is private.
I got a simple form and it works fine in ie but not working in firefox
onclick="login('loginuser','../private/loginuser.php?username='+email.value+'&pass='+passw.value,'loginresult');"
Any help appreciated.
android uses sqlite database to store data, I need to encrypt the sqlite database, how can this be done? I understand that application data is private. However I need to explictly encrypt the sqlite database that my app is using.
I'm doing a code review and I noticed such a code:
@Entity
@Table(name = "SOME_TABLE")
public class SomeReportClass {
@Column(name = "REPORT_NUMBER", length = 6, nullable = false)
private String reportNumber;
.....
public String getReportNumber() {
return reportNumber;
}
public void setReportNumber(String reportNumber) {
this.reportNumber = StringUtils.trimToNull(reportNumber);
}
}
Every time I see trimming inside of a setter I feel that its not the clearest solution - what is the general practice with that issue?
how can i evaluate weather my test array is equal to my static constant DEFAULT_ARRAY? shouldn't my output be returning true?
public class myClass extends Sprite
{
private static const DEFAULT_ARRAY:Array = new Array(1, 2, 3);
public function myClass()
{
var test:Array = new Array(1, 2, 3);
trace (test == DEFAULT_ARRAY);
}
//traces false
Is is bad practice to pass the Context to a constructor and save it as a private variable for internal use? The other option is to pass the Context as a parameter to methods that need it.
Which is the better option?
I have a feeling that passing to the constructor might result in memory leaks accidentally.
I have a class definition of the form
class X
{
public:
//class functions
private:
A_type *A;
//other class variables
};
and struct A_type is defined as
struct A_type
{
string s1,s2,s3;
};
Inside the constructor, I allocate appropriate memory for A and try A[0].s1="somestring";
It shows segmentation fault.
Is this kind of declaration invalid, or am I missing something
After finishing my C++ class it seemed to me the structs/classes are virtually identical except with a few minor differences.
I've never programmed in C before; but I do know that it has structs. In C is it possible to inherit other structs and set a modifier of public/private?
If you can do this in regular C why in the world do we need C++? What makes classes different from a struct?
I'm just messing around with some C++ at the moment trying to make a simple tic-tac-toe game and I'm running into a bit of a problem. This is my code:
#include <iostream>
using namespace std;
class Square {
public:
char getState() const;
void setState(char);
Square();
~Square();
private:
char * pState;
};
class Board {
public:
Board();
~Board();
void printBoard() const;
Square getSquare(short x, short y) const;
private:
Square board[3][3];
};
int main() {
Board board;
board.getSquare(1,2).setState('1');
board.printBoard();
return 0;
}
Square::Square() {
pState = new char;
*pState = ' ';
}
Square::~Square() {
delete pState;
}
char Square::getState() const {
return *pState;
}
void Square::setState(char set) {
*pState = set;
}
Board::~Board() {
}
Board::Board() {
}
void Board::printBoard() const {
for (int x = 0; x < 3; x++) {
cout << "|";
for (int y = 0; y < 3; y++) {
cout << board[x][y].getState();
}
cout << "|" << endl;
}
}
Square Board::getSquare(short x, short y) const {
return board[x][y];
}
Forgive me if there are blatantly obvious problems with it or it's stupidly written, this is my first program in C++ :p However, the problem is that when I try and set the square 1,2 to the char '1', it doesn't print out as a 1, it prints out as some strange character I didn't recognise.
Can anyone tell me why? :)
Thanks in advance.
Is it possible to have a static collection as a member of a hibernate entity?
Say I have an object Question:
public class Question {
private String category;
...
}
Would it be possible to populate a static Set<String> that is a distinct set of all categories in the Database? I know I could just query this, but I was wondering if there was a more elegant solution, as it seems like something that other people may have come across.
some of code, has below line.
readonly private string
TARGET_BTN_IMG_URL =
@"\ad1-sunglim\Test\";
in this line, why does @ need to be attatched ?
and even in javascript too.
Let's say I have a background worker like this:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while(true)
{
//Kill zombies
}
}
How can I make this background worker start and stop using a button on a WinForm?
I mean, won;t it be more specific and appropriate if i "only" keep "protected","internal" and "private" members (field,method,property,event) in a class which is declared as "internal" ?
I have seen this practice ( having "public" members in an "internal" class) in various code so just wanted to know is it a bad practice or does it has some benefit or advantage.
[Only concerned about C#]
Thanks for your interest.
I'm looking for a script/tool that can be customized to check and enforce coding/naming conventions on a C/C++ code.
It should check for example:
Code lines are wrapped at some length.
Private variables have prefix _
Code is indented properly.
All functions are documented.
Here are what I think are the relevant parts of the code of these two classes. First, TreePointer (original source here):
public abstract class TreePointer<T extends TreeNode>
implements Iterable<TokenResolver<T>>
{
//...
/**
* What this tree can see as a missing node (may be {@code null})
*/
private final T missing;
/**
* The list of token resolvers
*/
protected final List<TokenResolver<T>> tokenResolvers;
/**
* Main protected constructor
*
* <p>This constructor makes an immutable copy of the list it receives as
* an argument.</p>
*
* @param missing the representation of a missing node (may be null)
* @param tokenResolvers the list of reference token resolvers
*/
protected TreePointer(final T missing,
final List<TokenResolver<T>> tokenResolvers)
{
this.missing = missing;
this.tokenResolvers = ImmutableList.copyOf(tokenResolvers);
}
/**
* Alternate constructor
*
* <p>This is the same as calling {@link #TreePointer(TreeNode, List)} with
* {@code null} as the missing node.</p>
*
* @param tokenResolvers the list of token resolvers
*/
protected TreePointer(final List<TokenResolver<T>> tokenResolvers)
{
this(null, tokenResolvers);
}
//...
/**
* Tell whether this pointer is empty
*
* @return true if the reference token list is empty
*/
public final boolean isEmpty()
{
return tokenResolvers.isEmpty();
}
@Override
public final Iterator<TokenResolver<T>> iterator()
{
return tokenResolvers.iterator();
}
// .equals(), .hashCode(), .toString() follow
}
Then, JsonPointer, which contains this .parent() method which I'd like to factorize here (original source here:
public final class JsonPointer
extends TreePointer<JsonNode>
{
/**
* The empty JSON Pointer
*/
private static final JsonPointer EMPTY
= new JsonPointer(ImmutableList.<TokenResolver<JsonNode>>of());
/**
* Return an empty JSON Pointer
*
* @return an empty, statically allocated JSON Pointer
*/
public static JsonPointer empty()
{
return EMPTY;
}
//...
/**
* Return the immediate parent of this JSON Pointer
*
* <p>The parent of the empty pointer is itself.</p>
*
* @return a new JSON Pointer representing the parent of the current one
*/
public JsonPointer parent()
{
final int size = tokenResolvers.size();
return size <= 1 ? EMPTY
: new JsonPointer(tokenResolvers.subList(0, size - 1));
}
// ...
}
As mentioned in the subject, the problem I have here is with JsonPointer's .parent() method. In fact, the logic behind this method applies to TreeNode all the same, and therefore to its future implementations. Except that I have to use a constructor, and of course such a constructor is implementation dependent :/
Is there a way to make that .parent() method available to each and every implementation of TreeNode or is it just a pipe dream?
So after a few hours of workaround the limitation of Reflection being currently disabled on the Google App Engine, I was wondering if someone could help me understand why object reflection can be a threat. Is it because I can inspect the private variables of a class or are there any other deeper reasons?
say suppose I have class as :
public class Age {
private int age;
public int getAge() {
return this.age;
}
}
In my Main class I am calling the getAge() method many times.
So I wanted to know is it advisable to call so many times or call once and assign it to some variable and use that variable.
Which is best and why?
Not real information:
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Tekkub/.ssh/id_rsa):
ssh.txt
I entered a file name here. Not sure if i should have,
Enter passphrase (empty for no passphrase):
I am stuck here. I type and it doesnt work
I have this but it always returns null
private static String getParameters(Method aMethod) {
Class<?>[] parameterTypes = aMethod.getParameterTypes();
for (Class<?> aParam : parameterTypes) {
System.out.print(aParam.getName());
}
return null;
}