com.squarespace.cldrengine.internal.VectorArrowImpl Maven / Gradle / Ivy
The newest version!
package com.squarespace.cldrengine.internal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.squarespace.cldrengine.utils.StringUtils;
public abstract class VectorArrowImpl {
private final int offset;
private final List> keysets;
private final int len;
private final int last;
private final int[] factors;
public VectorArrowImpl(int offset, List> keysets) {
this.offset = offset + 1; // skip over header
this.keysets = keysets;
this.len = keysets.size();
this.last = this.len - 1;
this.factors = new int[this.len];
// Pre-compute the address factor for each dimension:
// 1-dim: [ index0 ]
// 2-dim: [ (index0 * size1), index1 ]
// 3-dim: [ (index0 * size1 * size2), (index1 * size), index2 ]
// ...
for (int i = 0; i < this.len; i++) {
int k = 1;
for (int j = i + 1; j < this.len; j++) {
k *= this.keysets.get(j).size;
}
this.factors[i] = k;
}
}
public boolean exists(PrimitiveBundle bundle) {
return "E".equals(bundle.get(this.offset - 1));
}
protected String get(PrimitiveBundle bundle, Object[] keys) {
if (keys.length != this.len) {
throw new RuntimeException("Error: impossible vector lookup with keys " + Arrays.toString(keys));
}
if (!this.exists(bundle)) {
return "";
}
return this._get(bundle, keys, 0, this.offset);
}
protected Object _mapping(PrimitiveBundle bundle, int k, int ix) {
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy