/**
* Returns the amount of free memory.
* @return {@code long} - Free space.
*/
public long getFreeInternalMemory() {
return getFreeMemory(Environment.getDataDirectory());
}
/**
* Returns the free amount in SDCARD.
* @return {@code long} - Free space.
*/
public long getFreeExternalMemory() {
return getFreeMemory(Environment.getExternalStorageDirectory());
}
/**
* Returns the free amount in OS.
* @return {@code long} - Free space.
*/
public long getFreeSystemMemory() {
return getFreeMemory(Environment.getRootDirectory());
}
/**
* Returns the free amount in mounted path
* @param path {@link File} - Mounted path.
* @return {@code long} - Free space.
*/
public long getFreeMemory(File path) {
if ((null != path) && (path.exists()) && (path.isDirectory())) {
StatFs stats = new StatFs(path.getAbsolutePath());
return stats.getAvailableBlocksLong() * stats.getBlockSizeLong();
}
return -1;
}
/**
* Convert bytes to human format.
* @param totalBytes {@code long} - Total of bytes.
* @return {@link String} - Converted size.
*/
public String bytesToHuman(long totalBytes) {
String[] simbols = new String[] {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"};
long scale = 1L;
for (String simbol : simbols) {
if (totalBytes < (scale * 1024L)) {
return String.format("%s %s", new DecimalFormat("#.##").format((double)totalBytes / scale), simbol);
}
scale *= 1024L;
}
return "-1 B";
}
Maybe
* [local-name () = 'A', а не (потомок :: * [local-name () = 'B'])]
?
Также должен быть только один корневой элемент , поэтому для / A [...]
вы либо получаете обратно весь свой XML, либо ничего. Может быть // A [not (B)]
или / * / A [not (B)]
?
Я действительно не понимаю, почему / A [ not (B)]
не работает для вас.
~/xml% xmllint ab.xml
<?xml version="1.0"?>
<root>
<A id="1">
<B/>
</A>
<A id="2">
</A>
<A id="3">
<B/>
<B/>
</A>
<A id="4"/>
</root>
~/xml% xpath ab.xml '/root/A[not(B)]'
Found 2 nodes:
-- NODE --
<A id="2">
</A>
-- NODE --
<A id="4" />
Первый / вызывает XPath Чтобы начать с корня документа, я сомневаюсь, что вы это хотели.
Если вы пытаетесь получить A в любом месте иерархии из корня, это работает (для xslt 1.0, а также для 2.0, если он используется в xslt)
//descendant-or-self::node()[local-name(.) = 'a' and not(count(b))]
ИЛИ вы также можете сделать
//descendant-or-self::node()[local-name(.) = 'a' and not(b)]
ИЛИ также
//descendant-or-self::node()[local-name(.) = 'a' and not(child::b)]
В xslt нет способов достичь того же самого.
Примечание: XPath чувствительны к регистру, поэтому, если имена ваших узлов разные (я уверен, что никто не будет использовать A, B), убедитесь, что регистр совпадает.