Thursday, 22 August 2013

How to add elements in List when used Arrays.asList()

How to add elements in List when used Arrays.asList()

We cannot perform <Collection>.add or <Collection>.addAll operation on
collections we have obtained from Arrays.asList .. only remove operation
is permitted.
So What if I come across a scenario where I require to add new Element in
List without deleting previous elements in List?. How can I achieve this?

gradle building: class, interface, or enum expected

gradle building: class, interface, or enum expected

I need to build apk file by using Gradle. Here's build.gradle code:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
buildToolsVersion "17.0"
compileSdkVersion 10
testBuildType = "debug"
defaultConfig {
versionCode = 1
versionName = "0.1"
minSdkVersion = 9
targetSdkVersion = 10
buildConfig "private final static boolean DEFAULT = true;", \
"private final static String FOO = \"foo\";"
}
buildTypes {
debug {
packageNameSuffix = ".debug"
buildConfig "private final static boolean DEBUG2 = false;"
}
}
aaptOptions {
noCompress "txt"
}
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res {
srcDir 'res'
}
assets {
srcDir 'assets'
}
resources {
srcDir 'src'
}
}
}
}
And here's class code:
final package com.tecomgroup.handifox.bin;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.View;
import android.widget.AdapterView;
import com.tecomgroup.handifox.ActivityHandifox;
import com.tecomgroup.handifox.Datastore;
import com.tecomgroup.handifox.GeneralFunc;
import com.tecomgroup.handifox.R;
public abstract class BinEditWindow extends ActivityHandifox {
public static Datastore idw_items;
public static Datastore ids_id_changed_items;
public static Datastore dw_bin;
protected final List<String> deletedItems = new LinkedList<String>();
protected void deleteItem(final String idColumnName) {
if (DS.Rowcount() > 1) {
if (!GeneralFunc.Empty(DS.get(DS.CurrentRow, "Parent"))) {
removeItem(idColumnName);
} else {
removeItem(idColumnName);
setParentForItems(chooseNewParentAndGetLineId());
}
}
}
public abstract String getItemLineId(final int row);
private String chooseNewParentAndGetLineId() {
DS.set(0, "Parent", "");
return getItemLineId(0);
}
private void removeItem(final String idColumnName) {
final String listId = DS.get(DS.CurrentRow, idColumnName);
deletedItems.add(listId);
DS.DeleteRow(DS.CurrentRow);
ib_changed = true;
}
private void setParentForItems(final String lineId) {
final int rowCount = DS.RowCount();
for (int row = 0; row < rowCount; row++) {
if (!GeneralFunc.Empty(DS.get(row, "Parent"))) {
DS.set(row, "Parent", lineId);
}
}
}
@Override
protected boolean onPostCreate() {
deletedItems.clear();
return super.onPostCreate();
}
@Override
protected void onPause() {
super.onPause();
if (isFinishing()) {
removeStaticDatastores();
}
}
@Override
protected void onDestroy() {
removeStaticDatastores();
super.onDestroy();
}
protected void removeStaticDatastores() {
idw_items = null;
ids_id_changed_items = null;
dw_bin = null;
}
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v,
final ContextMenuInfo menuInfo) {
clearFocusEditText();
final AdapterView.AdapterContextMenuInfo info =
(AdapterView.AdapterContextMenuInfo) menuInfo;
if (info.position != DS.CurrentRow) {
DS.isClicked = true;
DS.ScrolltoRow(info.position);
}
final MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.salesreceipt_edit_menu, menu);
menu.getItem(1).setVisible(DS.RowCount() > 1);
super.onCreateContextMenu(menu, v, menuInfo);
}
protected ArrayList<String> getParentRow() {
ArrayList<String> result = null;
final int rowCount = DS.RowCount();
for (int row = 0; row < rowCount; row++) {
if (GeneralFunc.Empty(DS.get(DS.CurrentRow, "Parent"))) {
result = DS.getRow(row);
break;
}
}
return result;
}
protected void removeDeletedItems(final Datastore removeItemsFrom,
final String idColumnName) {
for (final String deletedItemId : deletedItems) {
final int deletedRowIndex =
removeItemsFrom.Find(idColumnName,
deletedItemId, "equal", false);
if (deletedRowIndex >= 0) {
removeItemsFrom.DeleteRow(deletedRowIndex);
}
}
}
}
While building i get the following error:
...src\com\tecomgroup\handifox\bin\BinEditWindow.java :1: error: class,
interface, or enum expected final package com.tecomgroup.handifox.bin;
Where was I wrong?

How can i if function with value?

How can i if function with value?

My function
function Random() {
var length = 6,
charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
I want like this if but does not work I want to make them equal but i
couldn't thanks
$('#rand').bind('keypress keyup change', function () {
if ($(this).val() !== Random()) { //etc }
});

generate SOAP classes for iPhone from WSDL

generate SOAP classes for iPhone from WSDL

in my application I need to communicate with server and I have an WSDL
file, how can I generate SOAP classes for iPhone?

Wednesday, 21 August 2013

Error when enterting this command ALTER TABLE `report` AUTO_INCREMENT = 1

Error when enterting this command ALTER TABLE `report` AUTO_INCREMENT = 1

I get an error when using this command to alter my SQL table
Error message: #1064 - You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax
to use near 'ALTER TABLEreportAUTO_INCREMENT = 1, 30' at line 2 Any idea
of that?

Hey guys, i'm new to javascript I hope you can help me out

Hey guys, i'm new to javascript I hope you can help me out

I looked up to google on this one but no luck I hope you can help me out,
I got no codes to present here or something I just would like to ask what
is the use of Calc.Input.value function in JavaScript? I'm kinda confused
of what's the use of that one. Thank you in advance guys! Much love :))

When overriding Object.Equals, is it appropriate to use the passed in object's Equals(MyType)?

When overriding Object.Equals, is it appropriate to use the passed in
object's Equals(MyType)?

For a simple example, assume you have two classes that are different in
many ways, but can still be considered "equateable":
class WholeNumber: IEquatable<WholeNumber> {
int value;
public override bool Equals(object obj) {
if (obj is IEquatable<WholeNumber>) {
IEquatable<WholeNumber> other = (IEquatable<WholeNumber>) obj;
return other.Equals(this);
} else {
return false;
}
}
public bool Equals(WholeNumber other) {
return this.value == other.value;
}
}
class Fraction : IEquateable<WholeNumber > {
WholeNumber numerator;
WholeNumber denominator;
public bool Equals(WholeNumber other) {
if (denominator != 1) {
// Assume fraction is already reduced
return false;
} else {
return this.numerator.Equals(other);
}
}
}
This will allow any object that claims to be equateable to WholeNumber to
be passed into the WholeNumber's Equals(object) function and get the
desired result without WholeNumber needed to know about any other class.
Is this pattern a good idea? Is using IEquatable with other classes a
common (where it makes sence) thing to do?