Function bodies 269 total
parseRuleSet function · java · L222-L262 (41 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private RuleSet parseRuleSet(JSONObject json) {
if (json == null) {
return new RuleSet(Collections.emptyList(), Collections.emptyList());
}
// Parse variants
List<Variant> variants = new ArrayList<>();
JSONArray variantsJson = json.optJSONArray("variants");
if (variantsJson != null) {
for (int i = 0; i < variantsJson.length(); i++) {
variants.add(parseVariant(variantsJson.getJSONObject(i)));
}
}
// Sort variants by key for consistent ordering
variants.sort(Comparator.comparing(Variant::getKey));
// Parse rollouts
List<Rollout> rollouts = new ArrayList<>();
JSONArray rolloutsJson = json.optJSONArray("rollout");
if (rolloutsJson != null) {
for (int i = 0; i < rolloutsJson.length(); i++) {
rollouts.add(parseRollout(rolloutsJson.getJSONObject(i)));
}
}
// Parse test user ovparseVariant function · java · L267-L274 (8 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private Variant parseVariant(JSONObject json) {
String key = json.optString("key", "");
Object value = json.opt("value");
boolean isControl = json.optBoolean("is_control", false);
float split = (float) json.optDouble("split", 0.0);
return new Variant(key, value, isControl, split);
}parseRollout function · java · L279-L315 (37 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private Rollout parseRollout(JSONObject json) {
float rolloutPercentage = (float) json.optDouble("rollout_percentage", 0.0);
VariantOverride variantOverride = null;
if (json.has("variant_override") && !json.isNull("variant_override")) {
JSONObject variantObj = json.optJSONObject("variant_override");
if (variantObj != null) {
String key = variantObj.optString("key", "");
if (!key.isEmpty()) {
variantOverride = new VariantOverride(key);
}
}
}
// Parse legacy runtime evaluation (simple key-value format)
Map<String, Object> legacyRuntimeEval = null;
JSONObject legacyRuntimeEvalJson = json.optJSONObject("runtime_evaluation_definition");
if (legacyRuntimeEvalJson != null) {
legacyRuntimeEval = new HashMap<>();
for (String key : legacyRuntimeEvalJson.keySet()) {
legacyRuntimeEval.pugetVariant function · java · L331-L412 (82 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
public <T> SelectedVariant<T> getVariant(String flagKey, SelectedVariant<T> fallback, Map<String, Object> context, boolean reportExposure) {
long startTime = System.currentTimeMillis();
try {
// Get flag definition
Map<String, ExperimentationFlag> definitions = flagDefinitions.get();
ExperimentationFlag flag = definitions.get(flagKey);
if (flag == null) {
logger.log(Level.WARNING, "Flag not found: " + flagKey);
return fallback;
}
// Extract context value
String contextProperty = flag.getContext();
Object contextValueObj = context.get(contextProperty);
if (contextValueObj == null) {
logger.log(Level.WARNING, "Variant assignment key property '" + contextProperty + "' not found for flag: " + flagKey);
return fallback;
}
String contextValue = contextValueObj.toString();
buildResult function · java · L418-L433 (16 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private <T> SelectedVariant<T> buildResult(Variant variant, ExperimentationFlag flag, boolean isQaTester,
String flagKey, Map<String, Object> context,
long startTime, boolean reportExposure) {
SelectedVariant<T> result = new SelectedVariant<>(
variant.getKey(),
(T) variant.getValue(),
flag.getExperimentId(),
flag.getIsExperimentActive(),
isQaTester
);
if (reportExposure) {
trackLocalExposure(context, flagKey, variant.getKey(), System.currentTimeMillis() - startTime,
flag.getExperimentId(), flag.getIsExperimentActive(), isQaTester);
}
return result;
}matchesRuntimeConditions function · java · L435-L438 (4 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private boolean matchesRuntimeConditions(Rollout rollout, Map<String,Object> context) {
Map<String, Object> customProperties = getCustomProperties(context);
return JsonLogicEngine.evaluate(rollout.getRuntimeEvaluationRule(), customProperties);
}matchesLegacyRuntimeConditions function · java · L445-L464 (20 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private boolean matchesLegacyRuntimeConditions(Rollout rollout, Map<String, Object> context) {
Map<String, Object> customProperties = getCustomProperties(context);
if (customProperties == null) {
return false;
}
Map<String, Object> runtimeEval = rollout.getLegacyRuntimeEvaluationDefinition();
for (Map.Entry<String, Object> entry : runtimeEval.entrySet()) {
String key = entry.getKey();
Object expectedValue = entry.getValue();
Object actualValue = customProperties.get(key);
// Case-insensitive comparison for strings
if (!valuesEqual(expectedValue, actualValue)) {
return false;
}
}
return true;
}Repobility (the analyzer behind this table) · https://repobility.com
getCustomProperties function · java · L470-L476 (7 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private Map<String, Object> getCustomProperties(Map<String, Object> context) {
Object customPropsObj = context.get("custom_properties");
if (customPropsObj instanceof Map) {
return (Map<String, Object>) customPropsObj;
}
return null;
}valuesEqual function · java · L481-L492 (12 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private boolean valuesEqual(Object expected, Object actual) {
if (expected == null || actual == null) {
return expected == actual;
}
// Case-insensitive comparison for strings
if (expected instanceof String && actual instanceof String) {
return ((String) expected).equalsIgnoreCase((String) actual);
}
return expected.equals(actual);
}findVariantByKey function · java · L497-L504 (8 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private Variant findVariantByKey(List<Variant> variants, String key) {
for (Variant variant : variants) {
if (variant.getKey().equals(key)) {
return variant;
}
}
return null;
}applyVariantSplitOverrides function · java · L517-L538 (22 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private List<Variant> applyVariantSplitOverrides(List<Variant> variants, Map<String, Float> variantSplits) {
List<Variant> result = new ArrayList<>(variants.size());
for (Variant variant : variants) {
if (variantSplits.containsKey(variant.getKey())) {
// Create new variant with overridden split value
float overriddenSplit = variantSplits.get(variant.getKey());
Variant updatedVariant = new Variant(
variant.getKey(),
variant.getValue(),
variant.isControl(),
overriddenSplit
);
result.add(updatedVariant);
} else {
// Keep original variant with its original split
result.add(variant);
}
}
return result;
}selectVariantBySplit function · java · L552-L570 (19 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private Variant selectVariantBySplit(List<Variant> variants, float hash, Rollout rollout) {
// Apply variant split overrides if the rollout specifies them
List<Variant> variantsToUse = variants;
if (rollout != null && rollout.hasVariantSplits()) {
variantsToUse = applyVariantSplitOverrides(variants, rollout.getVariantSplits());
}
// Select variant using cumulative split percentages
float cumulative = 0.0f;
for (Variant variant : variantsToUse) {
cumulative += variant.getSplit();
if (hash < cumulative) {
return variant;
}
}
// If no variant selected (due to rounding), return last variant
return variantsToUse.isEmpty() ? null : variantsToUse.get(variantsToUse.size() - 1);
}calculateRolloutHash function · java · L584-L591 (8 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
protected float calculateRolloutHash(String contextValue, String flagKey,
String hashSalt, int rolloutIndex) {
if (hashSalt != null && !hashSalt.isEmpty()) {
return HashUtils.normalizedHash(contextValue + flagKey, hashSalt + rolloutIndex);
} else {
return HashUtils.normalizedHash(contextValue + flagKey, "rollout");
}
}calculateVariantHash function · java · L604-L610 (7 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
protected float calculateVariantHash(String contextValue, String flagKey, String hashSalt) {
if (hashSalt != null && !hashSalt.isEmpty()) {
return HashUtils.normalizedHash(contextValue + flagKey, hashSalt + "variant");
} else {
return HashUtils.normalizedHash(contextValue + flagKey, "variant");
}
}getAllVariants function · java · L623-L638 (16 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
public List<SelectedVariant<Object>> getAllVariants(Map<String, Object> context, boolean reportExposure) {
List<SelectedVariant<Object>> results = new ArrayList<>();
Map<String, ExperimentationFlag> definitions = flagDefinitions.get();
for (ExperimentationFlag flag : definitions.values()) {
SelectedVariant<Object> fallback = new SelectedVariant<>(null);
SelectedVariant<Object> result = getVariant(flag.getKey(), fallback, context, reportExposure);
// Only include successfully selected variants (not fallbacks)
if (result.isSuccess()) {
results.add(result);
}
}
return results;
}Repobility · severity-and-effort ranking · https://repobility.com
trackLocalExposure function · java · L643-L656 (14 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
private void trackLocalExposure(Map<String, Object> context, String flagKey, String variantKey, long latencyMs, UUID experimentId, Boolean isExperimentActive, Boolean isQaTester) {
if (eventSender == null) {
return;
}
Object distinctIdObj = context.get("distinct_id");
if (distinctIdObj == null) {
return;
}
trackExposure(distinctIdObj.toString(), flagKey, variantKey, "local", properties -> {
properties.put("Variant fetch latency (ms)", latencyMs);
}, experimentId, isExperimentActive, isQaTester);
}getLogger function · java · L661-L663 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
protected Logger getLogger() {
return logger;
}close function · java · L666-L670 (5 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
public void close() {
if (closed.compareAndSet(false, true)) {
stopPollingForDefinitions();
}
}shutdown function · java · L673-L675 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java
public void shutdown() {
close();
}RemoteFlagsProvider function · java · L39-L41 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/RemoteFlagsProvider.java
public RemoteFlagsProvider(RemoteFlagsConfig config, String sdkVersion, EventSender eventSender) {
super(config.getProjectToken(), config, sdkVersion, eventSender);
}getVariant function · java · L55-L114 (60 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/RemoteFlagsProvider.java
public <T> SelectedVariant<T> getVariant(String flagKey, SelectedVariant<T> fallback, Map<String, Object> context, boolean reportExposure) {
String startTime = getCurrentIso8601Timestamp();
try {
String endpoint = buildFlagsUrl(flagKey, context);
String response = httpGet(endpoint);
JSONObject root = new JSONObject(response);
JSONObject flags = root.optJSONObject("flags");
if (flags == null || !flags.has(flagKey)) {
logger.log(Level.WARNING, "Flag not found in response: " + flagKey);
return fallback;
}
JSONObject flagData = flags.getJSONObject(flagKey);
String variantKey = flagData.optString("variant_key", null);
Object variantValue = flagData.opt("variant_value");
if (variantKey == null) {
return fallback;
}
// Parse experiment metadata
UUID experimentId = ngetCurrentIso8601Timestamp function · java · L140-L144 (5 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/RemoteFlagsProvider.java
private String getCurrentIso8601Timestamp() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.format(new Date());
}trackRemoteExposure function · java · L151-L165 (15 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/RemoteFlagsProvider.java
private void trackRemoteExposure(Map<String, Object> context, String flagKey, String variantKey, String startTime, String completeTime, UUID experimentId, Boolean isExperimentActive, Boolean isQaTester) {
if (eventSender == null) {
return;
}
Object distinctIdObj = context.get("distinct_id");
if (distinctIdObj == null) {
return;
}
trackExposure(distinctIdObj.toString(), flagKey, variantKey, "remote", properties -> {
properties.put("Variant fetch start time", startTime);
properties.put("Variant fetch complete time", completeTime);
}, experimentId, isExperimentActive, isQaTester);
}Source: Repobility analyzer · https://repobility.com
getLogger function · java · L168-L170 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/RemoteFlagsProvider.java
protected Logger getLogger() {
return logger;
}HashUtils class · java · L15-L91 (77 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/HashUtils.java
public final class HashUtils {
/**
* FNV-1a 64-bit offset basis constant.
*/
private static final long FNV_OFFSET_BASIS_64 = 0xcbf29ce484222325L;
/**
* FNV-1a 64-bit prime constant.
*/
private static final long FNV_PRIME_64 = 0x100000001b3L;
// Private constructor to prevent instantiation
private HashUtils() {
throw new AssertionError("HashUtils should not be instantiated");
}
/**
* Generates a normalized hash value in the range [0.0, 1.0) using the FNV-1a algorithm.
*
* @param key the input string to hash (typically user identifier + flag key)
* @param salt the salt to append to the input (e.g., "rollout" or "variant")
* @return a float value in the range [0.0, 1.0)
* @throws IllegalArgumentException if key or salt is null
*/
public static float normalizedHash(String key, String salt) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
HashUtils method · java · L28-L30 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/HashUtils.java
private HashUtils() {
throw new AssertionError("HashUtils should not be instantiated");
}normalizedHash method · java · L40-L64 (25 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/HashUtils.java
public static float normalizedHash(String key, String salt) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
if (salt == null) {
throw new IllegalArgumentException("Salt cannot be null");
}
// Combine key and salt
String combined = key + salt;
byte[] bytes = combined.getBytes(StandardCharsets.UTF_8);
// FNV-1a 64-bit hash
long hash = FNV_OFFSET_BASIS_64;
for (byte b : bytes) {
// XOR with byte (converting to unsigned)
hash ^= (b & 0xff);
// Multiply by FNV prime
hash *= FNV_PRIME_64;
}
// Normalize to [0.0, 1.0) matching Python's approach
// Use Long.remainderUnsigned to handle negative values correctly
return (float) (Long.remainderUnsigned(hash, 100) / 100.0);
}rolloutHash method · java · L75-L77 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/HashUtils.java
public static float rolloutHash(String input) {
return normalizedHash(input, "rollout");
}variantHash method · java · L88-L90 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/HashUtils.java
public static float variantHash(String input) {
return normalizedHash(input, "variant");
}JsonCaseDesensitizer class · java · L8-L60 (53 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/JsonCaseDesensitizer.java
public class JsonCaseDesensitizer {
public static Object lowercaseLeafNodes(Object object) {
if (object == null) {
return null;
}
else if (object instanceof String){
return ((String) object).toLowerCase();
} else if (object instanceof org.json.JSONObject) {
org.json.JSONObject jsonObject = (org.json.JSONObject) object;
org.json.JSONObject result = new org.json.JSONObject();
for (String key : jsonObject.keySet()) {
result.put(key, lowercaseLeafNodes(jsonObject.get(key)));
}
return result;
} else if (object instanceof org.json.JSONArray) {
org.json.JSONArray jsonArray = (org.json.JSONArray) object;
org.json.JSONArray result = new org.json.JSONArray();
for (int i = 0; i < jsonArray.length(); i++) {
result.put(lowercaseLeafNodes(jsonArray.get(i)));
}
return result;
lowercaseLeafNodes method · java · L9-L32 (24 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/JsonCaseDesensitizer.java
public static Object lowercaseLeafNodes(Object object) {
if (object == null) {
return null;
}
else if (object instanceof String){
return ((String) object).toLowerCase();
} else if (object instanceof org.json.JSONObject) {
org.json.JSONObject jsonObject = (org.json.JSONObject) object;
org.json.JSONObject result = new org.json.JSONObject();
for (String key : jsonObject.keySet()) {
result.put(key, lowercaseLeafNodes(jsonObject.get(key)));
}
return result;
} else if (object instanceof org.json.JSONArray) {
org.json.JSONArray jsonArray = (org.json.JSONArray) object;
org.json.JSONArray result = new org.json.JSONArray();
for (int i = 0; i < jsonArray.length(); i++) {
result.put(lowercaseLeafNodes(jsonArray.get(i)));
}
return result;
} else {
return object;
Repobility · code-quality intelligence · https://repobility.com
lowercaseAllNodes method · java · L33-L59 (27 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/JsonCaseDesensitizer.java
public static Object lowercaseAllNodes(Object object) {
if (object == null) {
return null;
}
else if (object instanceof String){
return ((String) object).toLowerCase();
} else if (object instanceof Map) {
Map<?, ?> map = (Map<?, ?>) object;
Map<Object, Object> result = new java.util.HashMap<>();
for (Map.Entry<?, ?> entry : map.entrySet()) {
Object lowerKey = entry.getKey() instanceof String
? ((String) entry.getKey()).toLowerCase()
: entry.getKey();
result.put(lowerKey, lowercaseAllNodes(entry.getValue()));
}
return result;
} else if( object instanceof Iterable) {
Iterable<?> iterable = (Iterable<?>) object;
java.util.List<Object> result = new java.util.ArrayList<>();
for (Object item : iterable) {
result.add(lowercaseAllNodes(item));
JsonLogicEngine class · java · L14-L34 (21 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/JsonLogicEngine.java
public class JsonLogicEngine {
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(JsonLogicEngine.class.getName());
private static final JsonLogic jsonLogic = new JsonLogic();
public static boolean evaluate(JSONObject rule, Map<String, Object> data) {
if (data == null) {
data = new HashMap<>();
}
Map<String, Object> lowercasedData = (Map<String, Object>) JsonCaseDesensitizer.lowercaseAllNodes(data);
try {
String ruleJson = JsonCaseDesensitizer.lowercaseLeafNodes(rule).toString();
logger.log(Level.FINE, () -> "Evaluating JsonLogic rule: " + ruleJson + " with data: " + lowercasedData.toString());
Object result = jsonLogic.apply(ruleJson, lowercasedData);
return JsonLogic.truthy(result);
} catch (Exception e) {
logger.log(Level.WARNING, "Error evaluating runtime rule", e);
return false;
}
}
}evaluate method · java · L19-L33 (15 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/JsonLogicEngine.java
public static boolean evaluate(JSONObject rule, Map<String, Object> data) {
if (data == null) {
data = new HashMap<>();
}
Map<String, Object> lowercasedData = (Map<String, Object>) JsonCaseDesensitizer.lowercaseAllNodes(data);
try {
String ruleJson = JsonCaseDesensitizer.lowercaseLeafNodes(rule).toString();
logger.log(Level.FINE, () -> "Evaluating JsonLogic rule: " + ruleJson + " with data: " + lowercasedData.toString());
Object result = jsonLogic.apply(ruleJson, lowercasedData);
return JsonLogic.truthy(result);
} catch (Exception e) {
logger.log(Level.WARNING, "Error evaluating runtime rule", e);
return false;
}
} TraceparentUtil class · java · L17-L41 (25 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/TraceparentUtil.java
public final class TraceparentUtil {
/**
* Private constructor to prevent instantiation.
*/
private TraceparentUtil() {
throw new AssertionError("TraceparentUtil should not be instantiated");
}
/**
* Generates a W3C traceparent header value.
* <p>
* Format: 00-{trace_id}-{span_id}-01
* Uses two separate UUIDs with dashes removed - one for trace_id (32 chars)
* and one for span_id (16 chars).
* </p>
*
* @return a traceparent header value
*/
public static String generateTraceparent() {
String traceId = UUID.randomUUID().toString().replace("-", "");
String spanId = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
return "00-" + traceId + "-" + spanId + "-01";
}
}TraceparentUtil method · java · L22-L24 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/TraceparentUtil.java
private TraceparentUtil() {
throw new AssertionError("TraceparentUtil should not be instantiated");
}generateTraceparent method · java · L36-L40 (5 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/TraceparentUtil.java
public static String generateTraceparent() {
String traceId = UUID.randomUUID().toString().replace("-", "");
String spanId = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
return "00-" + traceId + "-" + spanId + "-01";
}VersionUtil class · java · L16-L69 (54 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/VersionUtil.java
public class VersionUtil {
private static final Logger logger = Logger.getLogger(VersionUtil.class.getName());
private static final String VERSION_FILE = "mixpanel-version.properties";
private static final String VERSION_KEY = "version";
private static final String UNKNOWN_VERSION = "unknown";
private static String cachedVersion = null;
private VersionUtil() {
// Utility class - prevent instantiation
}
/**
* Gets the SDK version.
* <p>
* The version is loaded from the properties file on first access and cached.
* Returns "unknown" if the version cannot be determined (e.g., running in IDE without build).
* </p>
*
* @return the SDK version string
*/
public static String getVersion() {
if (cachedVersion == null) {
cachedVersion = loadVersion();
}
return cachedVersion;
}
/**
* Loads the version from the properties file.
*/
private static String lVersionUtil method · java · L24-L26 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/VersionUtil.java
private VersionUtil() {
// Utility class - prevent instantiation
}Repobility (the analyzer behind this table) · https://repobility.com
getVersion method · java · L37-L42 (6 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/VersionUtil.java
public static String getVersion() {
if (cachedVersion == null) {
cachedVersion = loadVersion();
}
return cachedVersion;
}loadVersion method · java · L47-L68 (22 LOC)src/main/java/com/mixpanel/mixpanelapi/featureflags/util/VersionUtil.java
private static String loadVersion() {
try (InputStream input = VersionUtil.class.getClassLoader().getResourceAsStream(VERSION_FILE)) {
if (input == null) {
logger.log(Level.WARNING, "Version file not found: " + VERSION_FILE + " (using fallback version)");
return UNKNOWN_VERSION;
}
Properties props = new Properties();
props.load(input);
String version = props.getProperty(VERSION_KEY);
if (version == null || version.isEmpty()) {
logger.log(Level.WARNING, "Version property not found in " + VERSION_FILE);
return UNKNOWN_VERSION;
}
return version;
} catch (IOException e) {
logger.log(Level.WARNING, "Failed to load version from " + VERSION_FILE, e);
return UNKNOWN_VERSION;
}
}OrgJsonSerializer class · java · L13-L27 (15 LOC)src/main/java/com/mixpanel/mixpanelapi/internal/OrgJsonSerializer.java
public class OrgJsonSerializer implements JsonSerializer {
@Override
public String serializeArray(List<JSONObject> messages) {
if (messages == null || messages.isEmpty()) {
return "[]";
}
JSONArray array = new JSONArray();
for (JSONObject message : messages) {
array.put(message);
}
return array.toString();
}
}serializeArray method · java · L16-L26 (11 LOC)src/main/java/com/mixpanel/mixpanelapi/internal/OrgJsonSerializer.java
public String serializeArray(List<JSONObject> messages) {
if (messages == null || messages.isEmpty()) {
return "[]";
}
JSONArray array = new JSONArray();
for (JSONObject message : messages) {
array.put(message);
}
return array.toString();
}MessageBuilder method · java · L29-L31 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/MessageBuilder.java
public MessageBuilder(String token) {
mToken = token;
}event method · java · L52-L85 (34 LOC)src/main/java/com/mixpanel/mixpanelapi/MessageBuilder.java
public JSONObject event(String distinctId, String eventName, JSONObject properties) {
long time = System.currentTimeMillis();
// Nothing below should EVER throw a JSONException.
try {
JSONObject dataObj = new JSONObject();
dataObj.put("event", eventName);
JSONObject propertiesObj = null;
if (properties == null) {
propertiesObj = new JSONObject();
}
else {
propertiesObj = new JSONObject(properties.toString());
}
if (! propertiesObj.has("token")) propertiesObj.put("token", mToken);
if (! propertiesObj.has("time")) propertiesObj.put("time", time);
if (! propertiesObj.has("mp_lib")) propertiesObj.put("mp_lib", "jdk");
if (distinctId != null)
propertiesObj.put("distinct_id", distinctId);
dataObj.put("properties", propertiesObj);
JSONObject envelope = new JSimportEvent method · java · L104-L147 (44 LOC)src/main/java/com/mixpanel/mixpanelapi/MessageBuilder.java
public JSONObject importEvent(String distinctId, String eventName, JSONObject properties) {
long time = System.currentTimeMillis();
// Nothing below should EVER throw a JSONException.
try {
JSONObject dataObj = new JSONObject();
dataObj.put("event", eventName);
JSONObject propertiesObj = null;
if (properties == null) {
propertiesObj = new JSONObject();
}
else {
propertiesObj = new JSONObject(properties.toString());
}
// no need to add $import true property as this is added by the backend for any event imported.
if (! propertiesObj.has("token")) propertiesObj.put("token", mToken);
// Set default time to current time if not provided
if (! propertiesObj.has("time")) propertiesObj.put("time", time);
// Generate default $insert_id if not provided (to prevset method · java · L170-L172 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/MessageBuilder.java
public JSONObject set(String distinctId, JSONObject properties) {
return set(distinctId, properties, null);
}Repobility · severity-and-effort ranking · https://repobility.com
set method · java · L198-L200 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/MessageBuilder.java
public JSONObject set(String distinctId, JSONObject properties, JSONObject modifiers) {
return peopleMessage(distinctId, "$set", properties, modifiers);
}setOnce method · java · L226-L228 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/MessageBuilder.java
public JSONObject setOnce(String distinctId, JSONObject properties) {
return setOnce(distinctId, properties, null);
}setOnce method · java · L257-L259 (3 LOC)src/main/java/com/mixpanel/mixpanelapi/MessageBuilder.java
public JSONObject setOnce(String distinctId, JSONObject properties, JSONObject modifiers) {
return peopleMessage(distinctId, "$set_once", properties, modifiers);
}