I want to remove entrys out of an attribute map. The problem is that the remove method can't match the key I search for:
final Attributes attributes = manifest.getMainAttributes();
symbolicName = getAttributeValue(attributes, "Bundle-SymbolicName");
attributes.remove("Bundle-SymbolicName");
When i run that code, the entry with the key "Bundle-SymbolicName" (and every other i try to remove) is still in attributes.
In the debugger i can evaluate the following expressions:
attributes.getValue("Bundle-Version") = 0.1.0.qualifier
attributes.containsKey("Bundle-Version") = false
attributes.remove("Bundle-Version") returns null (Returns the previous attribute value, or null if none.)
Is this a problem with typecasting?
RealSkeptic did answer my question: The keys of Attributes are not strings. I need to use the type Attributes.Name
Related
I want to add new key to a map. memberFees is a field of a document under collection named Faculty
I want to store only the key of each member fee inside the memberFees map.
Here is an example of my memberFees map:
I only added that keys in the example manually.
This is what I did:
writeBatches.get(batchIndex).update(db.collection("Faculty")
.document(faculty.getId()), "memberFees/" + memberFeeId, true);
This code throws an error:
java.lang.IllegalArgumentException: Invalid document reference. Document references must have an even number of segments, but Faculty/7DEj7mlTPBf3cVSCtQO3/memberFees has 3
at com.google.firebase.firestore.DocumentReference.forPath(DocumentReference.java:81)
When updating a nested field, use . to separate the field names. Your code uses /, which Firestore interprets as a subcollection.
So:
writeBatches.get(batchIndex).update(db.collection("Faculty")
.document(faculty.getId()), "memberFees." + memberFeeId, true)
// 👆
I got a Hashmap parsed from the XML document and wanted to check if a list/set of entries exist.
hashMap.entrySet() -> returns set of entry and I want to assert "key1":"value1" exist in this set.
How can this be done?
Reference from stack overflow show containsKey and containsValue but not containsEntry.
References:
Search if specified key and value exists
An Entry is nothing more then the Key and the Value associated with it.
So if you want to check if an specfic Key has an Specific Value associated with it just do this:
SomeObject actualValue = map.get(key)
if(!expectedValue.equals(actualValue))
{
//Key has other Value associated with it
}
else
{
//Key has the expected Value
}
In a jsff file a component has been designed and the values are being fetched from a Static VO. There are only two values in the static Vo. I need the first option to be set as default. But there is a empty value that is being set. I have written a condition to disable it. And when it is disabled the value must be set to the first one.
I have tried the List UI Hints and tried to enable the Include No selection item: Labeled Item first of list, I tried creating a new vo which only has one value and rendered it in Jsff(But it will make the code more complex for the future development) I have tried creating the switcher. But none of them worked as they should.
Can anyone suggest me a alternative where the code complexity does not increase and by default there is a first value selected. And disable if there is condition for disable tag in jsff is true.
PS: Once the field is disabled the first value must be the default value to be set by default.
There don't seem to be any default way to do this with Oracle ADF without adding code to your view Object. Here's how to automatically select First value in your ADF LOV (detail from here https://cedricleruth.com/autoselect-first-value-in-adf-lov-inside-a-table/) :
Generate the RowImpl Java class of your View Object and Static VO
In this RowImpl.java add the following function to return the first value if no value is already selected
public String defaultNextStatus() {
String value = (String) getAttributeInternal(AttributesEnum.NextStatus.index());
if (value == null) {
XxcrWorkflowUvVORowImpl nextStatut = (XxcrWorkflowUvVORowImpl) getWfkVA().first();
//Wkfva is the VO of the LOV
if (nextStatut != null) {
return nextStatut.getTxtValeur();
}
}
return value;
}
In the Detail panel of the attribute add the following Default Value Expression: adf.object.defaultNextStatus()
In the Detail panel of the attribute set the refresh Expression Value to false to avoid picking the first value again in case of ppr/refresh
I trying to find a key in some Subspace at FoundationDB with getKey and KeySelector. In case if result exists in Subspace it works pretty well.
val key = new Tuple().add(3)
val subspace = new Subspace(new Tuple().add("test-subspace"))
tr.set(key.pack(), new Tuple().pack())
tr.set(subspace.pack(key), new Tuple().pack())
tr.getKey(KeySelector.firstGreaterOrEqual(subspace.pack(key)))
.thenApply[Tuple] { result =>
println(Tuple.fromBytes(result)) // ("test-subspace", 3)
subspace.unpack(result) // (3)
}
In the same time, if key does not exist in target subspace, it returns me key that was found in default subspace. Which is not what I expected...
val key = new Tuple().add(3)
val subspace = new Subspace(new Tuple().add("test-subspace"))
tr.set(key.pack(), new Tuple().pack())
tr.getKey(KeySelector.firstGreaterOrEqual(subspace.pack(key)))
.thenApply[Tuple] { result =>
println(Tuple.fromBytes(result)) // (3)
subspace.unpack(result) // Cannot unpack key that is not contained in subspace.
}
Also, if db empty, getKey instead of returning null, returns some weird byte array which cannot be parsed by Tuple.fromBytes.
val key = new Tuple().add("my-key")
tr.getKey(KeySelector.firstGreaterOrEqual(key.pack()))
.thenApply[Tuple] { result =>
println(result == null) // false
Tuple.fromBytes(result) // throws java.lang.IllegalArgumentException: Unknown tuple data type -1 at index 0
}
How should I handle situations when target subspaces do not contain the search result?
To add on to what Guarav said, when a key selector resolves to a key before the beginning of the database, it returns the empty key (''). If the key resolves past the end of the database, you'll get '\xff' in a normal transaction or '\xff\xff' if your transaction is allowed to read system keys. This is mentioned briefly at the end of the key selector documentation here.
As for not returning a result outside of your subspace, to do so would probably require getKey accepting a bound key parameter that restricts searches beyond that key. It doesn't currently have that parameter, but getRange does and can be used to perform the same query if you use a limit of 1. For example, you could do:
tr.getRange(KeySelector.firstGreaterOrEqual(subspace.pack(key)), subspace.range().end, 1)
In this case, the result will either have a key if one could be found in the subspace matching your key selector or will be empty if one could not. Of course, you'll also get back the value in this query.
This is expected behavior. Keyselector returns you the key that matches the condition - in this case first key that is greater or equal to the passed byte[]. You would need to check if returned key is valid as per your subspace requirement - by using subspace.contains() or any other validation on the returned key.
Same explanation for the second question- the returned key could be some special pre-existing row in the db, that is not created using tuple layer. Hence it cannot be parsed using tuple layer. You need to check for key validity by using subspace.contains or some similar check.
In a Java program, i am processing an xml using dom4j.
Now, I want to update an attribute of an element.
This is the code I am using to obtain that element--
SAXReader reader = new SAXReader();
doc = reader.read(new StringReader(xmlinput));
Element root = doc.getRootElement();
for ( Iterator i = root.elementIterator( "cloudwhile" ); i.hasNext(); ) {
Element foo = (Element) i.next();
Now, I want to update the value of an attribute of element 'foo'--
For this I am trying to use the following code--
foo.setAttributeValue("indexstart", (String) newstart );
However the above method is deprecated... how do I update the attribute now? Also, I want to take the string representation of the modified xml, immediately after updating the attribute of element 'foo'- how do I do that?
JavaDoc says to use addAttribute(...) instead. The name is somewhat misleading, as it will replace the content of an existing attribute - what is equal to updating a value.
Adds the attribute value of the given fully qualified name. If an attribute already exists for the given name it will be replaced. Attributes with null values are silently ignored. If the value of the attribute is null then this method call will remove any attributes with the given name.
As it says in the docs, use addAttribute(String attributeName, String value) instead.