/*
 * Copyright 2011 Splunk, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"): you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

import com.splunk.EntityCollection;
import com.splunk.Service;
import com.splunk.Index;
import com.splunk.Entity;

import java.io.DataOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Map;

import java.util.Date;
import java.text.SimpleDateFormat;


public class Program extends com.splunk.sdk.Program {
    public static void main(String[] args) {
        Program program = new Program();
        try {
            program.init(args).run();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public void run() throws Exception {
        Service service = new Service(this.host, this.port, this.scheme);
        service.login(this.username, this.password);

        EntityCollection indexes = service.getIndexes();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

        Map<String, Entity> all = indexes.getEntities();
        for (String name: all.keySet()) {
            Entity entity = all.get(name);
            System.out.println(
                entity.getTitle() +
                " (" + entity.getContent().get("totalEventCount") + ")");
        }

        Index idx = new Index(service, "sdk-tests");
        String date = sdf.format(new Date());

        // submit method

        idx.submit(date + " 1");
        idx.submit(date + " 2");
        idx.submit(date + " 3");

        // stream method
        Socket sock = idx.attach();
        OutputStream ostream = sock.getOutputStream();
        DataOutputStream ds = new DataOutputStream(ostream);

        ds.writeBytes(date + " ONE\r\n");
        ds.writeBytes(date + " TWO\r\n");
        ds.writeBytes(date + " THREE\r\n");
        sock.close();
    }
}

@@ -808,19 +808,53 @@
 va.util.
-Map
+Collection;%0Aimport java.util.Iterator
 ;%0A%0Aimpor
@@ -1536,20 +1536,19 @@
     
-Map%3CString, 
+Collection%3C
 Enti
@@ -1569,17 +1569,12 @@
 xes.
-getEntiti
+valu
 es()
@@ -1587,41 +1587,47 @@
     
-for (String name: all.keySet()) %7B
+Iterator%3CEntity%3E itr = all.iterator();%0A
 %0A   
@@ -1627,28 +1627,29 @@
 );%0A%0A        
-    
+for (
 Entity entit
@@ -1653,25 +1653,29 @@
 tity
- = all.get(name);
+: indexes.values()) %7B
 %0A   
@@ -1949,17 +1949,16 @@
  method%0A
-%0A
         

update to use newer collection paradigm