I'm trying to add a field to a FeatureLayer, this is the code I'm using to do this:
IMxDocument mxd = (IMxDocument) app.getDocument();
FeatureLayer flayer = ((FeatureLayer)mxd.getSelectedLayer());
IField newField = null;
newField = new Field();
IFieldEdit newFieldEdit = (IFieldEdit) newField;
newFieldEdit.setAliasName("Id2");
newFieldEdit.setName("Id2");
newFieldEdit.setType(esriFieldType.esriFieldTypeString);
newFieldEdit.setLength(100);
flayer.addField(newFieldEdit);
However it raises an exception, according the documentation I should to get an ISchemaLock but I have no idea how to get a schemalock from a FeatureLayer, Does anyone have any idea?
Related
How to initialize a field that is generated. Or in the code example below, where can the AssignExpr object be added for the code to work?
private void addConfigField(ClassOrInterfaceDeclaration clazz) {
var className = "BlaConfig";
var configField = clazz.addField(className, "blaConfig", Modifier.PRIVATE);
var configFieldExpr = new NameExpr("blaConfig");
var newConfigObj = new ObjectCreationExpr(null, JavaParser.parseClassOrInterfaceType(className), new NodeList<>());
var assign = new AssignExpr(configFieldExpr, newConfigObj, Operator.ASSIGN);
}
Using com.github.javaparser:javaparser-core:3.2.4
You can get the variable declared in the 'configField'. That variable may be initialized.
configField.getVariable(0).setInitializer(/* Your code */);
I create nattable the following way. But I can get access to the cells only through getters and setters in my Student class. How else can I access cells? Should I create my own BodyDataProvider or use IDataProvider? If it is true, could someone give some examples of implementing such providers?
final ColumnGroupModel columnGroupModel = new ColumnGroupModel();
ColumnHeaderLayer columnHeaderLayer;
String[] propertyNames = { "name", "groupNumber", "examName", "examMark" };
Map<String, String> propertyToLabelMap = new HashMap<String, String>();
propertyToLabelMap.put("name", "Full Name");
propertyToLabelMap.put("groupNumber", "Group");
propertyToLabelMap.put("examName", "Name");
propertyToLabelMap.put("examMark", "Mark");
DefaultBodyDataProvider<Student> bodyDataProvider = new DefaultBodyDataProvider<Student>(students,
propertyNames);
ColumnGroupBodyLayerStack bodyLayer = new ColumnGroupBodyLayerStack(new DataLayer(bodyDataProvider),
columnGroupModel);
DefaultColumnHeaderDataProvider defaultColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
propertyNames, propertyToLabelMap);
DefaultColumnHeaderDataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(
defaultColumnHeaderDataProvider);
columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer,
bodyLayer.getSelectionLayer(), columnGroupModel);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Exams", 2, 3);
columnGroupHeaderLayer.setGroupUnbreakable(2);
final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(
defaultColumnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnGroupHeaderLayer);
GridLayer gridLayer = new GridLayer(bodyLayer, columnGroupHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable table = new NatTable(shell, gridLayer, true);
As answered in your previous question How do I fix NullPointerException and putting data into NatTable, this is explained in the NatTable Getting Started Tutorial.
If you need some sample code try the NatTable Examples Application
And from knowing your previous question, your data structure does not work in a table, as you have nested objects where the child objects are stored in an array. So this is more a tree and not a table.
Mongodb has an update function, where it can increment pre-existing fields. However, I found that it could only update flat JSON. Whenever there's a JSONObject inside of a JSONObject, with a value I want to increment, I can't actually seem to do it. It will return this error:
com.mongodb.WriteConcernException: Write failed with error code 14 and error message
'Cannot increment with non-numeric argument: {laneQty: { BOTTOM: 1 }}'
As you can see, I tried update incrementing laneQty.BOTTOM by 1. I don't want to write an algorithm to change every single layered json field into dot notation(like laneQty.BOTTOM), so is there a way to either turn the JSON into dot notation pre-upsert?
For now my general upsert function looks like this:
public boolean incrementJson(BasicDBObject json, String colName, ArrayList<String> queryParams, ArrayList<String> removeParams){
/*make sure the game id AND the main player id can't both be the same.
If either/or, it's fine. We don't want duplicates.
*/
BasicDBObject query = new BasicDBObject();
DBCollection collection = db.getCollection(colName);
for(int i = 0; i < queryParams.size(); i++){
String param = queryParams.get(i);
query.put(param, json.get(param));
}
for(String param : removeParams){
json.remove(param);
}
return collection.update(query, new BasicDBObject("$inc", json), true, false).isUpdateOfExisting();
}
Is there any suggested upgrades to this code that could make it easily update layered json as well? Thank you!
By the way, it'll be very hard for me to hardcode this. There are a ton of layered objects and that would take me forever. Also, I am not in complete control of which fields are populated in the layers, so I can't just say laneQty.BOTTOM every single time because it will not always exist. Prior to upserting, the BasicDBObject json was actually a java bean parsed into BasicDBObject. This is its constructor if it's of any help:
public ChampionBean(int rank, int division, int assists, int deaths, int kills, int qty, int championId,
HashMap<String, Integer> laneQty, HashMap<String, Integer> roleQty,
ParticipantTimelineDataBean assistedLaneDeathsPerMinDeltas,
ParticipantTimelineDataBean assistedLaneKillsPerMinDeltas, ParticipantTimelineDataBean creepsPerMinDeltas,
ParticipantTimelineDataBean csDiffPerMinDeltas, ParticipantTimelineDataBean damageTakenDiffPerMinDeltas,
ParticipantTimelineDataBean damageTakenPerMinDeltas, ParticipantTimelineDataBean goldPerMinDeltas,
ParticipantTimelineDataBean xpDiffPerMinDeltas, ParticipantTimelineDataBean xpPerMinDeltas, int wins,
int weekDate, int yearDate) {
super();
this.rank = rank;
this.division = division;
this.assists = assists;
this.deaths = deaths;
this.kills = kills;
this.qty = qty;
this.championId = championId;
this.laneQty = laneQty;
this.roleQty = roleQty;
this.assistedLaneDeathsPerMinDeltas = assistedLaneDeathsPerMinDeltas;
this.assistedLaneKillsPerMinDeltas = assistedLaneKillsPerMinDeltas;
this.creepsPerMinDeltas = creepsPerMinDeltas;
this.csDiffPerMinDeltas = csDiffPerMinDeltas;
this.damageTakenDiffPerMinDeltas = damageTakenDiffPerMinDeltas;
this.damageTakenPerMinDeltas = damageTakenPerMinDeltas;
this.goldPerMinDeltas = goldPerMinDeltas;
this.xpDiffPerMinDeltas = xpDiffPerMinDeltas;
this.xpPerMinDeltas = xpPerMinDeltas;
this.wins = wins;
this.weekDate = weekDate;
this.yearDate = yearDate;
}
The participantTimelineDataBean is another bean with 4 int fields inside of it. I want to increment those fields (so yes it's only 2 layers deep, so if there's a solution with 2 layers deep availability I'll take that too).
Use the dot-notation:
new BasicDBObject("$inc", new BasicDBObject("laneQty.BOTTOM", 1) )
Alternative quick&dirty solution: Just collection.save the whole document under the same _id.
Use this library:
https://github.com/rhalff/dot-object
For example if you have an object like this:
var jsonObject = {
info : {
firstName : 'aamir',
lastName : 'ryu'
email : 'aamiryu#gmail.com'
},
}
then your node.js code would be like this:
var dot = require('dot-object');
var jsonObject = // as above ;-);
var convertJsonObjectToDot = dot.dot(jsonObject);
console.log(convertJsonObjectToDot);
Output will be as shown below:
{
info.firstName : 'aamir',
info.lastName : 'ryu',
info.email : 'aamiryu#gmail.com
}
Please bear with me, this is my first answer on stackoverflow ever, since i was searching for the same thing and i found one solution to it, hope it helps you out.
Currently I'm doing a task that involves HashMap. And what I'm doing right now is to insert 3 variable in the HashMap. I succeed to make it but there is the error regarding the syntax or declaration (I don't know which one). Can someone help me detect what wrong with my syntax/declaration and come up with a solution? Below is my code:
public static void showAVMode(Context context, String AVMode) {
mContext = context;
spotText = getAvModeText(AVMode);
spotType= "";
call_Spot=3000;
if(mContext != null) {
spotType=mContext.getString(R.string.AVM_name);
currentSpot=5;
show();
} else {
TvLog.d(TAG, "context is null");
}
}
.............................
private static String getAvModeText(String mode){
String avMode = mContext.getString(R.string.AVM_stand);
HashMap<String,Drawable> AvModeIconTHX = new HashMap<String,Drawable>();
AvModeIconTHX.put(mContext.getString(R.string.AVM_movTHX), mContext.getDrawable(R.drawable.set_thx));
HashMap<String,Drawable> AvModeIconES = new HashMap<String,Drawable>();
AvModeIconES.put(mContext.getString(R.string.AVM_stand), mContext.getDrawable(R.drawable.set_es));
HashMap<String,Drawable> AvModeMovie = new HashMap<String,Drawable>();
AvModeMovie.put(mContext.getString(R.string.AVM_mov), null);
HashMap<String,Drawable> AvModeGame = new HashMap<String,Drawable>();
AvModeGame.put(mContext.getString(R.string.AVM_game), null);
HashMap<String,Drawable> AvModePC = new HashMap<String,Drawable>();
AvModePC.put(mContext.getString(R.string.AVM_PC), null);
HashMap<String,Drawable> AvModeUser = new HashMap<String,Drawable>();
AvModeUser.put(mContext.getString(R.string.AVM_user), null);
HashMap<String,Drawable> AvModeDyn = new HashMap<String,Drawable>();
AvModeDyn.put(mContext.getString(R.string.AVM_dyn), null);
HashMap<String,Drawable> AvModeDynFix = new HashMap<String,Drawable>();
AvModeDynFix.put(mContext.getString(R.string.AVM_dynFix), null);
HashMap<String,HashMap<String,Drawable>> mapAvMode = new HashMap<String,HashMap<String,Drawable>>();
mapAvMode.put(TvFunctionID.AVMode.AVMODE_STANDARD, AvModeIconES);
mapAvMode.put(TvFunctionID.AVMode.AVMODE_MOVIE, AvModeMovie);
mapAvMode.put(TvFunctionID.AVMode.AVMODE_MOVIE_THX, AvModeIconTHX);
mapAvMode.put(TvFunctionID.AVMode.AVMODE_GAME, AvModeGame);
mapAvMode.put(TvFunctionID.AVMode.AVMODE_PC, AvModePC);
mapAvMode.put(TvFunctionID.AVMode.AVMODE_CUSTOM, AvModeUser);
mapAvMode.put(TvFunctionID.AVMode.AVMODE_DYNAMIC, AvModeDyn);
mapAvMode.put(TvFunctionID.AVMode.AVMODE_DYNAMIC_FIXED, AvModeDynFix);
if(mapAvMode.containsKey(mode)) {
avMode = mapAvMode.get(mode);
}
return avMode;
}
the error is at the code mapAvMode.get(mode); where it says Type mismatch: cannot convert from HashMap<String,Drawable> to String. There is the quickfix but it didn't solve the error. Can someone help me with this? And I think my code can be much shorter than this. Any suggestion would greatly appreciate.
Your avMode variable is a type String while the object return by mapAvMode is HashMap<String,Drawable>. In a HashMap, the first parameter is the key (here String) and the second is the value (here Drawable). If you want to get the String value from this HashMap, you should do : avMode = mapAvMode.get(mode).get(yourParam);
Update : sorry, I gave a wrong information. So I'm correcting my answer. mapAvMode.get(mode) will return a HashMap<String, Drawable> and if you write this :
mapAvMode.get(mode).get(yourParam);.
It will return a Drawable. So your avMode variable must be either a HashMap and this line will work :
avMode = mapAvMode.get(mode)
or it must be a Drawable and this line will work:
avMode = mapAvMode.get(mode).get(yourParam);
`mapAvMode.get(mode)`
returns a drawable that you are type casting to String change your avMode to drawable it will solve your problem,HashMap.get(key)is used to get the value on the basis of the key you passed,here our value is drawable.
As the lucene migration guide mentioned, to set document level boost we should multiply all fields boost by boosting value. here is my code :
StringField nameField = new StringField("name", name, Field.Store.YES) ;
StringField linkField = new StringField("link", link, Field.Store.YES);
Field descField;
TextField reviewsField = new TextField("reviews", reviews_str, Field.Store.YES);
TextField authorsField = new TextField("authors", authors_str, Field.Store.YES);
FloatField scoreField = new FloatField("score", origScore,Field.Store.YES);
if (desc != null) {
descField = new TextField("desc", desc, Field.Store.YES);
} else {
descField = new TextField("desc", "", Field.Store.YES);
}
doc.add(nameField);
doc.add(linkField);
doc.add(descField);
doc.add(reviewsField);
doc.add(authorsField);
doc.add(scoreField);
nameField.setBoost(score);
linkField.setBoost(score);
descField.setBoost(score);
reviewsField.setBoost(score);
authorsField.setBoost(score);
scoreField.setBoost(score);
but I've got this exception when running code :
Exception in thread "main" java.lang.IllegalArgumentException: You cannot set an index-time boost on an unindexed field, or one that omits norms
I've searched google. but I've got no answers. would you please help me?
Index-time boosts are stored in the field's norm, and both StringField and FloatField omit norms by default. So, you'll need to turn them on before you set the boosts.
To turn norms on, you'll need to define your own field types:
//Start with a copy of the standard field type
FieldType myStringType = new FieldType(StringField.TYPE_STORED);
myStringType.setOmitNorms(false);
//StringField doesn't do anything special except have a customized fieldtype, so just use Field.
Field nameField = new Field("name", name, myStringType);
FieldType myFloatType = new FieldType(FloatField.TYPE_STORED);
myFloatType.setOmitNorms(false);
//For FloatField, use the appropriate FloatField ctor, instead of Field (similar for other numerics)
Field scoreField = new FloatField("score", origScore, myFloatType);