← back to mixpanel__mixpanel-java

Function bodies 269 total

All specs Real LLM only Function bodies
JacksonSerializer class · java · L20-L139 (120 LOC)
mixpanel-java-extension-jackson/src/main/java/com/mixpanel/mixpanelapi/internal/JacksonSerializer.java
public class JacksonSerializer implements JsonSerializer {

    private final JsonFactory jsonFactory;

    /**
     * Constructs a new JacksonSerializer with default settings.
     */
    public JacksonSerializer() {
        this.jsonFactory = new JsonFactory();
    }

    @Override
    public String serializeArray(List<JSONObject> messages) throws IOException {
        if (messages == null || messages.isEmpty()) {
            return "[]";
        }

        StringWriter writer = new StringWriter();
        try (JsonGenerator generator = jsonFactory.createGenerator(writer)) {
            writeJsonArray(generator, messages);
        }
        return writer.toString();
    }

    /**
     * Writes a JSON array of messages using the Jackson streaming API.
     */
    private void writeJsonArray(JsonGenerator generator, List<JSONObject> messages) throws IOException {
        generator.writeStartArray();
        for (JSONObject message : messages) {
            writeJsonObject(generator, m
JacksonSerializer method · java · L27-L29 (3 LOC)
mixpanel-java-extension-jackson/src/main/java/com/mixpanel/mixpanelapi/internal/JacksonSerializer.java
    public JacksonSerializer() {
        this.jsonFactory = new JsonFactory();
    }
serializeArray method · java · L32-L42 (11 LOC)
mixpanel-java-extension-jackson/src/main/java/com/mixpanel/mixpanelapi/internal/JacksonSerializer.java
    public String serializeArray(List<JSONObject> messages) throws IOException {
        if (messages == null || messages.isEmpty()) {
            return "[]";
        }

        StringWriter writer = new StringWriter();
        try (JsonGenerator generator = jsonFactory.createGenerator(writer)) {
            writeJsonArray(generator, messages);
        }
        return writer.toString();
    }
writeJsonArray method · java · L47-L53 (7 LOC)
mixpanel-java-extension-jackson/src/main/java/com/mixpanel/mixpanelapi/internal/JacksonSerializer.java
    private void writeJsonArray(JsonGenerator generator, List<JSONObject> messages) throws IOException {
        generator.writeStartArray();
        for (JSONObject message : messages) {
            writeJsonObject(generator, message);
        }
        generator.writeEndArray();
    }
writeJsonObject method · java · L59-L99 (41 LOC)
mixpanel-java-extension-jackson/src/main/java/com/mixpanel/mixpanelapi/internal/JacksonSerializer.java
    private void writeJsonObject(JsonGenerator generator, JSONObject jsonObject) throws IOException {
        generator.writeStartObject();

        Iterator<String> keys = jsonObject.keys();
        while (keys.hasNext()) {
            String key = keys.next();
            Object value = jsonObject.opt(key);

            if (value == null || value == JSONObject.NULL) {
                generator.writeNullField(key);
            } else if (value instanceof String) {
                generator.writeStringField(key, (String) value);
            } else if (value instanceof Number) {
                if (value instanceof Integer) {
                    generator.writeNumberField(key, (Integer) value);
                } else if (value instanceof Long) {
                    generator.writeNumberField(key, (Long) value);
                } else if (value instanceof Double) {
                    generator.writeNumberField(key, (Double) value);
                } else if (value instanceof Float) {
  
writeJsonArray method · java · L104-L138 (35 LOC)
mixpanel-java-extension-jackson/src/main/java/com/mixpanel/mixpanelapi/internal/JacksonSerializer.java
    private void writeJsonArray(JsonGenerator generator, JSONArray jsonArray) throws IOException {
        generator.writeStartArray();

        for (int i = 0; i < jsonArray.length(); i++) {
            Object value = jsonArray.opt(i);

            if (value == null || value == JSONObject.NULL) {
                generator.writeNull();
            } else if (value instanceof String) {
                generator.writeString((String) value);
            } else if (value instanceof Number) {
                if (value instanceof Integer) {
                    generator.writeNumber((Integer) value);
                } else if (value instanceof Long) {
                    generator.writeNumber((Long) value);
                } else if (value instanceof Double) {
                    generator.writeNumber((Double) value);
                } else if (value instanceof Float) {
                    generator.writeNumber((Float) value);
                } else {
                    generator.writeNumber
MixpanelProvider class · java · L20-L315 (296 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
public class MixpanelProvider implements FeatureProvider {

    private static final Logger logger = Logger.getLogger(MixpanelProvider.class.getName());
    private final BaseFlagsProvider<?> flagsProvider;
    private final MixpanelAPI mixpanel;

    public MixpanelProvider(BaseFlagsProvider<?> flagsProvider) {
        this.flagsProvider = flagsProvider;
        this.mixpanel = null;
    }

    /**
     * Constructs a MixpanelProvider with local feature flags evaluation.
     * Creates a MixpanelAPI instance, extracts the local flags provider,
     * and automatically starts polling for flag definitions.
     *
     * @param token the Mixpanel project token (unused, token is read from config)
     * @param config configuration for local feature flags evaluation
     */
    public MixpanelProvider(String token, LocalFlagsConfig config) {
        MixpanelAPI api = new MixpanelAPI(config);
        this.mixpanel = api;
        LocalFlagsProvider localFlags = api.getLocalFlags();
        l
Repobility · severity-and-effort ranking · https://repobility.com
MixpanelProvider method · java · L26-L29 (4 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public MixpanelProvider(BaseFlagsProvider<?> flagsProvider) {
        this.flagsProvider = flagsProvider;
        this.mixpanel = null;
    }
MixpanelProvider method · java · L39-L45 (7 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public MixpanelProvider(String token, LocalFlagsConfig config) {
        MixpanelAPI api = new MixpanelAPI(config);
        this.mixpanel = api;
        LocalFlagsProvider localFlags = api.getLocalFlags();
        localFlags.startPollingForDefinitions();
        this.flagsProvider = localFlags;
    }
MixpanelProvider method · java · L54-L58 (5 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public MixpanelProvider(String token, RemoteFlagsConfig config) {
        MixpanelAPI api = new MixpanelAPI(config);
        this.mixpanel = api;
        this.flagsProvider = api.getRemoteFlags();
    }
getMixpanel method · java · L66-L68 (3 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public MixpanelAPI getMixpanel() {
        return mixpanel;
    }
getMetadata method · java · L71-L73 (3 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public Metadata getMetadata() {
        return () -> "mixpanel-provider";
    }
getBooleanEvaluation method · java · L76-L78 (3 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) {
        return evaluate(key, defaultValue, Boolean.class, ctx);
    }
getStringEvaluation method · java · L81-L83 (3 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx) {
        return evaluate(key, defaultValue, String.class, ctx);
    }
getIntegerEvaluation method · java · L86-L88 (3 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx) {
        return evaluate(key, defaultValue, Integer.class, ctx);
    }
Provenance: Repobility (https://repobility.com) — every score reproducible from /scan/
getDoubleEvaluation method · java · L91-L93 (3 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) {
        return evaluate(key, defaultValue, Double.class, ctx);
    }
getObjectEvaluation method · java · L96-L100 (5 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext ctx) {
        return evaluate(key, defaultValue, ctx,
                result -> objectToValue(result.getVariantValue()),
                "Expected Value");
    }
shutdown method · java · L103-L109 (7 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    public void shutdown() {
        try {
            flagsProvider.shutdown();
        } catch (Exception e) {
            logger.log(Level.WARNING, "Error shutting down Mixpanel flags provider", e);
        }
    }
evaluate method · java · L111-L115 (5 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    private <T> ProviderEvaluation<T> evaluate(String key, T defaultValue, Class<T> expectedType, EvaluationContext ctx) {
        return evaluate(key, defaultValue, ctx,
                result -> coerce(result.getVariantValue(), expectedType),
                "Expected " + expectedType.getSimpleName());
    }
evaluate method · java · L117-L143 (27 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    private <T> ProviderEvaluation<T> evaluate(String key, T defaultValue, EvaluationContext ctx,
                                                java.util.function.Function<SelectedVariant<Object>, T> mapper,
                                                String typeDescription) {
        ProviderEvaluation<T> notReadyResult = checkNotReady(defaultValue);
        if (notReadyResult != null) {
            return notReadyResult;
        }

        SelectedVariant<Object> result;
        try {
            result = fetchVariant(key, ctx);
        } catch (Exception e) {
            return errorResult(defaultValue, ErrorCode.GENERAL, e.getMessage());
        }

        if (result.isFallback()) {
            return errorResult(defaultValue, ErrorCode.FLAG_NOT_FOUND, "Flag not found: " + key);
        }

        T value = mapper.apply(result);
        if (value == null) {
            return errorResult(defaultValue, ErrorCode.TYPE_MISMATCH,
                    typeDescription + " but got " 
fetchVariant method · java · L145-L148 (4 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    private SelectedVariant<Object> fetchVariant(String key, EvaluationContext ctx) {
        SelectedVariant<Object> fallback = new SelectedVariant<>(null);
        return flagsProvider.getVariant(key, fallback, convertContext(ctx), true);
    }
errorResult method · java · L150-L158 (9 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    private <T> ProviderEvaluation<T> errorResult(T defaultValue, ErrorCode errorCode, String errorMessage) {
        String reason = errorCode == ErrorCode.FLAG_NOT_FOUND ? "DEFAULT" : "ERROR";
        return ProviderEvaluation.<T>builder()
                .value(defaultValue)
                .reason(reason)
                .errorCode(errorCode)
                .errorMessage(errorMessage)
                .build();
    }
successResult method · java · L160-L166 (7 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    private <T> ProviderEvaluation<T> successResult(T value, String variantKey) {
        return ProviderEvaluation.<T>builder()
                .value(value)
                .variant(variantKey)
                .reason("TARGETING_MATCH")
                .build();
    }
Repobility · code-quality intelligence platform · https://repobility.com
checkNotReady method · java · L168-L176 (9 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    private <T> ProviderEvaluation<T> checkNotReady(T defaultValue) {
        if (flagsProvider instanceof LocalFlagsProvider) {
            LocalFlagsProvider localProvider = (LocalFlagsProvider) flagsProvider;
            if (!localProvider.areFlagsReady()) {
                return errorResult(defaultValue, ErrorCode.PROVIDER_NOT_READY, "Provider not ready");
            }
        }
        return null;
    }
coerce method · java · L179-L203 (25 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    private <T> T coerce(Object value, Class<T> targetType) {
        if (value == null) {
            return null;
        }
        if (targetType.isInstance(value)) {
            return targetType.cast(value);
        }
        if (targetType == Integer.class && value instanceof Number) {
            if (value instanceof Double || value instanceof Float) {
                double doubleVal = ((Number) value).doubleValue();
                if (doubleVal != Math.floor(doubleVal)) {
                    return null;
                }
            }
            long longVal = ((Number) value).longValue();
            if (longVal < Integer.MIN_VALUE || longVal > Integer.MAX_VALUE) {
                return null;
            }
            return (T) Integer.valueOf((int) longVal);
        }
        if (targetType == Double.class && value instanceof Number) {
            return (T) Double.valueOf(((Number) value).doubleValue());
        }
        return null;
    }
convertContext method · java · L205-L219 (15 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    static Map<String, Object> convertContext(EvaluationContext ctx) {
        Map<String, Object> context = new HashMap<>();
        if (ctx == null) {
            return context;
        }
        String targetingKey = ctx.getTargetingKey();
        if (targetingKey != null && !targetingKey.isEmpty()) {
            context.put("targetingKey", targetingKey);
        }
        for (String key : ctx.keySet()) {
            Value val = ctx.getValue(key);
            context.put(key, unwrapValue(val));
        }
        return context;
    }
unwrapValue method · java · L221-L260 (40 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    private static Object unwrapValue(Value value) {
        if (value == null || value.isNull()) {
            return null;
        }
        if (value.isBoolean()) {
            return value.asBoolean();
        }
        if (value.isNumber()) {
            double d = value.asDouble();
            if (d == Math.floor(d) && !Double.isInfinite(d)) {
                if (d >= Integer.MIN_VALUE && d <= Integer.MAX_VALUE) {
                    return (int) d;
                }
                if (d >= Long.MIN_VALUE && d <= Long.MAX_VALUE) {
                    return (long) d;
                }
            }
            return d;
        }
        if (value.isString()) {
            return value.asString();
        }
        if (value.isList()) {
            List<Value> list = value.asList();
            Object[] arr = new Object[list.size()];
            for (int i = 0; i < list.size(); i++) {
                arr[i] = unwrapValue(list.get(i));
            }
            return Arrays.asLi
objectToValue method · java · L262-L314 (53 LOC)
openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java
    private static Value objectToValue(Object obj) {
        if (obj == null) {
            return new Value();
        }
        if (obj instanceof Boolean) {
            return new Value((Boolean) obj);
        }
        if (obj instanceof Integer) {
            return new Value((Integer) obj);
        }
        if (obj instanceof Long) {
            long l = (Long) obj;
            if (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE) {
                return new Value((int) l);
            }
            return new Value((double) l);
        }
        if (obj instanceof Double) {
            return new Value((Double) obj);
        }
        if (obj instanceof Float) {
            return new Value(((Float) obj).doubleValue());
        }
        if (obj instanceof String) {
            return new Value((String) obj);
        }
        if (obj instanceof Map) {
            @SuppressWarnings("unchecked")
            Map<String, Object> map = (Map<String, Object>) obj;
            Map<St
MixpanelAPIDemo class · java · L22-L187 (166 LOC)
src/demo/java/com/mixpanel/mixpanelapi/demo/MixpanelAPIDemo.java
public class MixpanelAPIDemo {
    

    public static String PROJECT_TOKEN = "bf2a25faaefdeed4aecde6e177d111bf"; // "YOUR TOKEN";
    public static long MILLIS_TO_WAIT = 10 * 1000;

    private static class DeliveryThread extends Thread {
        public DeliveryThread(Queue<JSONObject> messages, boolean useGzipCompression) {
            mMixpanel = new MixpanelAPI(useGzipCompression);
            mMessageQueue = messages;
            mUseGzipCompression = useGzipCompression;
        }

        @Override
        public void run() {
            try {
                while(true) {
                    int messageCount = 0;
                    ClientDelivery delivery = new ClientDelivery();
                    JSONObject message = null;
                    do {
                        message = mMessageQueue.poll();
                        if (message != null) {
                            System.out.println("WILL SEND MESSAGE" + (mUseGzipCompression ? " (with gzip compression)" : "") + ":
DeliveryThread class · java · L28-L68 (41 LOC)
src/demo/java/com/mixpanel/mixpanelapi/demo/MixpanelAPIDemo.java
    private static class DeliveryThread extends Thread {
        public DeliveryThread(Queue<JSONObject> messages, boolean useGzipCompression) {
            mMixpanel = new MixpanelAPI(useGzipCompression);
            mMessageQueue = messages;
            mUseGzipCompression = useGzipCompression;
        }

        @Override
        public void run() {
            try {
                while(true) {
                    int messageCount = 0;
                    ClientDelivery delivery = new ClientDelivery();
                    JSONObject message = null;
                    do {
                        message = mMessageQueue.poll();
                        if (message != null) {
                            System.out.println("WILL SEND MESSAGE" + (mUseGzipCompression ? " (with gzip compression)" : "") + ":\n" + message.toString());

                            messageCount = messageCount + 1;
                            delivery.addMessage(message);
                        }

         
DeliveryThread method · java · L29-L33 (5 LOC)
src/demo/java/com/mixpanel/mixpanelapi/demo/MixpanelAPIDemo.java
        public DeliveryThread(Queue<JSONObject> messages, boolean useGzipCompression) {
            mMixpanel = new MixpanelAPI(useGzipCompression);
            mMessageQueue = messages;
            mUseGzipCompression = useGzipCompression;
        }
Generated by Repobility's multi-pass static-analysis pipeline (https://repobility.com)
run method · java · L36-L63 (28 LOC)
src/demo/java/com/mixpanel/mixpanelapi/demo/MixpanelAPIDemo.java
        public void run() {
            try {
                while(true) {
                    int messageCount = 0;
                    ClientDelivery delivery = new ClientDelivery();
                    JSONObject message = null;
                    do {
                        message = mMessageQueue.poll();
                        if (message != null) {
                            System.out.println("WILL SEND MESSAGE" + (mUseGzipCompression ? " (with gzip compression)" : "") + ":\n" + message.toString());

                            messageCount = messageCount + 1;
                            delivery.addMessage(message);
                        }

                    } while(message != null);

                    mMixpanel.deliver(delivery);

                    System.out.println("Sent " + messageCount + " messages" + (mUseGzipCompression ? " with gzip compression" : "") + ".");
                    Thread.sleep(MILLIS_TO_WAIT);
                }
            } catch (IOExceptio
printUsage method · java · L70-L82 (13 LOC)
src/demo/java/com/mixpanel/mixpanelapi/demo/MixpanelAPIDemo.java
    public static void printUsage() {
        System.out.println("USAGE: java com.mixpanel.mixpanelapi.demo.MixpanelAPIDemo distinct_id");
        System.out.println("");
        System.out.println("This is a simple program demonstrating Mixpanel's Java library.");
        System.out.println("It reads lines from standard input and sends them to Mixpanel as events.");
        System.out.println("");
        System.out.println("The demo also shows:");
        System.out.println("  - Setting user properties");
        System.out.println("  - Tracking charges");
        System.out.println("  - Importing historical events");
        System.out.println("  - Incrementing user properties");
        System.out.println("  - Using gzip compression");
    }
main method · java · L87-L186 (100 LOC)
src/demo/java/com/mixpanel/mixpanelapi/demo/MixpanelAPIDemo.java
    public static void main(String[] args)
        throws IOException, InterruptedException {
        Queue<JSONObject> messages = new ConcurrentLinkedQueue<JSONObject>();
        Queue<JSONObject> messagesWithGzip = new ConcurrentLinkedQueue<JSONObject>();
        
        // Create two delivery threads - one without gzip and one with gzip compression
        DeliveryThread worker = new DeliveryThread(messages, false);
        DeliveryThread workerWithGzip = new DeliveryThread(messagesWithGzip, true);
        
        MessageBuilder messageBuilder = new MessageBuilder(PROJECT_TOKEN);

        if (args.length != 1) {
            printUsage();
            System.exit(1);
        }

        worker.start();
        workerWithGzip.start();
        
        String distinctId = args[0];
        BufferedReader inputLines = new BufferedReader(new InputStreamReader(System.in));
        String line = inputLines.readLine();

        // Set the first name of the associated user (to distinct id)
  
LocalEvaluationExample class · java · L19-L128 (110 LOC)
src/demo/java/com/mixpanel/mixpanelapi/featureflags/demo/LocalEvaluationExample.java
public class LocalEvaluationExample {

    public static void main(String[] args) throws Exception {
        // Replace with your actual Mixpanel project token
        String projectToken = "YOUR_PROJECT_TOKEN";

        // 1. Configure local evaluation
        LocalFlagsConfig config = LocalFlagsConfig.builder()
            .projectToken(projectToken)
            .apiHost("api.mixpanel.com")       // Use "api-eu.mixpanel.com" for EU
            .pollingIntervalSeconds(60)        // Poll every 60 seconds
            .enablePolling(true)               // Enable background polling
            .requestTimeoutSeconds(10)         // 10 second timeout for HTTP requests
            .build();

        try (MixpanelAPI mixpanel = new MixpanelAPI(config)) {

            // 2. Start polling for flag definitions
            System.out.println("Starting flag polling...");
            mixpanel.getLocalFlags().startPollingForDefinitions();

            System.out.println("Waiting for flags to be read
main method · java · L21-L127 (107 LOC)
src/demo/java/com/mixpanel/mixpanelapi/featureflags/demo/LocalEvaluationExample.java
    public static void main(String[] args) throws Exception {
        // Replace with your actual Mixpanel project token
        String projectToken = "YOUR_PROJECT_TOKEN";

        // 1. Configure local evaluation
        LocalFlagsConfig config = LocalFlagsConfig.builder()
            .projectToken(projectToken)
            .apiHost("api.mixpanel.com")       // Use "api-eu.mixpanel.com" for EU
            .pollingIntervalSeconds(60)        // Poll every 60 seconds
            .enablePolling(true)               // Enable background polling
            .requestTimeoutSeconds(10)         // 10 second timeout for HTTP requests
            .build();

        try (MixpanelAPI mixpanel = new MixpanelAPI(config)) {

            // 2. Start polling for flag definitions
            System.out.println("Starting flag polling...");
            mixpanel.getLocalFlags().startPollingForDefinitions();

            System.out.println("Waiting for flags to be ready...");
            int retries = 0;
  
RemoteEvaluationExample class · java · L16-L125 (110 LOC)
src/demo/java/com/mixpanel/mixpanelapi/featureflags/demo/RemoteEvaluationExample.java
public class RemoteEvaluationExample {

    public static void main(String[] args) {
        // Replace with your actual Mixpanel project token
        String projectToken = "YOUR_PROJECT_TOKEN";

        // 1. Configure remote evaluation
        RemoteFlagsConfig config = RemoteFlagsConfig.builder()
            .projectToken(projectToken)
            .apiHost("api.mixpanel.com")       // Use "api-eu.mixpanel.com" for EU
            .requestTimeoutSeconds(5)          // 5 second timeout
            .build();

        // 2. Create MixpanelAPI with flags support
        try (MixpanelAPI mixpanel = new MixpanelAPI(config)) {

            System.out.println("Remote flags initialized");

            // 3. Example 1: Simple flag check
            System.out.println("\n=== Example 1: Simple Flag Check ===");
            Map<String, Object> context1 = new HashMap<>();
            context1.put("distinct_id", "user-789");

            // Each call makes an API request
            boolean feature
main method · java · L18-L124 (107 LOC)
src/demo/java/com/mixpanel/mixpanelapi/featureflags/demo/RemoteEvaluationExample.java
    public static void main(String[] args) {
        // Replace with your actual Mixpanel project token
        String projectToken = "YOUR_PROJECT_TOKEN";

        // 1. Configure remote evaluation
        RemoteFlagsConfig config = RemoteFlagsConfig.builder()
            .projectToken(projectToken)
            .apiHost("api.mixpanel.com")       // Use "api-eu.mixpanel.com" for EU
            .requestTimeoutSeconds(5)          // 5 second timeout
            .build();

        // 2. Create MixpanelAPI with flags support
        try (MixpanelAPI mixpanel = new MixpanelAPI(config)) {

            System.out.println("Remote flags initialized");

            // 3. Example 1: Simple flag check
            System.out.println("\n=== Example 1: Simple Flag Check ===");
            Map<String, Object> context1 = new HashMap<>();
            context1.put("distinct_id", "user-789");

            // Each call makes an API request
            boolean featureEnabled = mixpanel.getRemoteFlags().isEn
encode function · java · L62-L80 (19 LOC)
src/main/java/com/mixpanel/mixpanelapi/Base64Coder.java
    public static char[] encode (byte[] in, int iLen) {
       int oDataLen = (iLen*4+2)/3;       // output length without padding
       int oLen = ((iLen+2)/3)*4;         // output length including padding
       char[] out = new char[oLen];
       int ip = 0;
       int op = 0;
       while (ip < iLen) {
          int i0 = in[ip++] & 0xff;
          int i1 = ip < iLen ? in[ip++] & 0xff : 0;
          int i2 = ip < iLen ? in[ip++] & 0xff : 0;
          int o0 = i0 >>> 2;
          int o1 = ((i0 &   3) << 4) | (i1 >>> 4);
          int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
          int o3 = i2 & 0x3F;
          out[op++] = map1[o0];
          out[op++] = map1[o1];
          out[op] = op < oDataLen ? map1[o2] : '='; op++;
          out[op] = op < oDataLen ? map1[o3] : '='; op++; }
       return out; }
Repobility · severity-and-effort ranking · https://repobility.com
decode function · java · L107-L134 (28 LOC)
src/main/java/com/mixpanel/mixpanelapi/Base64Coder.java
    public static byte[] decode (char[] in) {
       int iLen = in.length;
       if (iLen%4 != 0) throw new IllegalArgumentException ("Length of Base64 encoded input string is not a multiple of 4.");
       while (iLen > 0 && in[iLen-1] == '=') iLen--;
       int oLen = (iLen*3) / 4;
       byte[] out = new byte[oLen];
       int ip = 0;
       int op = 0;
       while (ip < iLen) {
          int i0 = in[ip++];
          int i1 = in[ip++];
          int i2 = ip < iLen ? in[ip++] : 'A';
          int i3 = ip < iLen ? in[ip++] : 'A';
          if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
             throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
          int b0 = map2[i0];
          int b1 = map2[i1];
          int b2 = map2[i2];
          int b3 = map2[i3];
          if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
             throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
          int o0 = ( b0       <<2) | (b1>>>
ClientDelivery class · java · L12-L97 (86 LOC)
src/main/java/com/mixpanel/mixpanelapi/ClientDelivery.java
public class ClientDelivery {

    private final List<JSONObject> mEventsMessages = new ArrayList<JSONObject>();
    private final List<JSONObject> mPeopleMessages = new ArrayList<JSONObject>();
    private final List<JSONObject> mGroupMessages = new ArrayList<JSONObject>();
    private final List<JSONObject> mImportMessages = new ArrayList<JSONObject>();

    /**
     * Adds an individual message to this delivery. Messages to Mixpanel are often more efficient when sent in batches.
     *
     * @param message a JSONObject produced by #{@link MessageBuilder}. Arguments not from MessageBuilder will throw an exception.
     * @throws MixpanelMessageException if the given JSONObject is not formatted appropriately.
     * @see MessageBuilder
     */
    public void addMessage(JSONObject message) {
        if (! isValidMessage(message)) {
            throw new MixpanelMessageException("Given JSONObject was not a valid Mixpanel message", message);
        }
        // ELSE message is valid

addMessage method · java · L26-L51 (26 LOC)
src/main/java/com/mixpanel/mixpanelapi/ClientDelivery.java
    public void addMessage(JSONObject message) {
        if (! isValidMessage(message)) {
            throw new MixpanelMessageException("Given JSONObject was not a valid Mixpanel message", message);
        }
        // ELSE message is valid

        try {
            String messageType = message.getString("message_type");
            JSONObject messageContent = message.getJSONObject("message");

            if (messageType.equals("event")) {
                mEventsMessages.add(messageContent);
            }
            else if (messageType.equals("people")) {
                mPeopleMessages.add(messageContent);
            }
            else if (messageType.equals("group")) {
                mGroupMessages.add(messageContent);
            }
            else if (messageType.equals("import")) {
                mImportMessages.add(messageContent);
            }
        } catch (JSONException e) {
            throw new RuntimeException("Apparently valid mixpanel message could not be inte
isValidMessage method · java · L58-L79 (22 LOC)
src/main/java/com/mixpanel/mixpanelapi/ClientDelivery.java
    public boolean isValidMessage(JSONObject message) {
        // See MessageBuilder for how these messages are formatted.
        boolean ret = true;
        try {
            int envelopeVersion = message.getInt("envelope_version");
            if (envelopeVersion > 0) {
                String messageType = message.getString("message_type");
                JSONObject messageContents = message.getJSONObject("message");

                if (messageContents == null) {
                    ret = false;
                }
                else if (!messageType.equals("event") && !messageType.equals("people") && !messageType.equals("group") && !messageType.equals("import")) {
                    ret = false;
                }
            }
        } catch (JSONException e) {
            ret = false;
        }

        return ret;
    }
DeliveryOptions class · java · L23-L114 (92 LOC)
src/main/java/com/mixpanel/mixpanelapi/DeliveryOptions.java
public class DeliveryOptions {

    private final boolean mImportStrictMode;
    private final boolean mUseIpAddress;

    private DeliveryOptions(Builder builder) {
        mImportStrictMode = builder.importStrictMode;
        mUseIpAddress = builder.useIpAddress;
    }

    /**
     * Returns whether strict mode is enabled for import messages.
     *
     * <p><strong>Note:</strong> This option only applies to import messages (historical events).
     * It has no effect on regular events, people, or groups messages.
     *
     * <p>When strict mode is enabled (default), the /import endpoint validates each event
     * and returns a 400 error if any event has issues. Correctly formed events are still
     * ingested, and problematic events are returned in the response with error messages.
     *
     * <p>When strict mode is disabled, validation is bypassed and all events are imported
     * regardless of their validity.
     *
     * @return true if strict mode is enabled for import
DeliveryOptions method · java · L28-L31 (4 LOC)
src/main/java/com/mixpanel/mixpanelapi/DeliveryOptions.java
    private DeliveryOptions(Builder builder) {
        mImportStrictMode = builder.importStrictMode;
        mUseIpAddress = builder.useIpAddress;
    }
isImportStrictMode method · java · L48-L50 (3 LOC)
src/main/java/com/mixpanel/mixpanelapi/DeliveryOptions.java
    public boolean isImportStrictMode() {
        return mImportStrictMode;
    }
useIpAddress method · java · L60-L62 (3 LOC)
src/main/java/com/mixpanel/mixpanelapi/DeliveryOptions.java
    public boolean useIpAddress() {
        return mUseIpAddress;
    }
Provenance: Repobility (https://repobility.com) — every score reproducible from /scan/
Builder class · java · L67-L113 (47 LOC)
src/main/java/com/mixpanel/mixpanelapi/DeliveryOptions.java
    public static class Builder {
        private boolean importStrictMode = true;
        private boolean useIpAddress = false;

        /**
         * Sets whether to use strict mode for import messages.
         *
         * will validate the supplied events and return a 400 status code if any of the events fail validation with details of the error
         *
         * <p>Setting this value to true (default) will validate the supplied events and return 
         * a 400 status code if any of the events fail validation with details of the error.
         * Setting this value to false disables validation.
         *
         * @param importStrictMode true to enable strict validation (default), false to disable
         * @return this Builder instance for method chaining
         */
        public Builder importStrictMode(boolean importStrictMode) {
            this.importStrictMode = importStrictMode;
            return this;
        }

        /**
         * Sets whether to use the 
importStrictMode method · java · L83-L86 (4 LOC)
src/main/java/com/mixpanel/mixpanelapi/DeliveryOptions.java
        public Builder importStrictMode(boolean importStrictMode) {
            this.importStrictMode = importStrictMode;
            return this;
        }
useIpAddress method · java · L100-L103 (4 LOC)
src/main/java/com/mixpanel/mixpanelapi/DeliveryOptions.java
        public Builder useIpAddress(boolean useIpAddress) {
            this.useIpAddress = useIpAddress;
            return this;
        }
page 1 / 6next ›