Example usage for java.util ArrayList toString

List of usage examples for java.util ArrayList toString

Introduction

In this page you can find the example usage for java.util ArrayList toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.talk.demo.util.NetworkUtilities.java

public static List<RawFriend> syncFriends(Account account, String authtoken, long serverSyncState,
        List<RawFriend> dirtyFriends)
        throws JSONException, ParseException, IOException, AuthenticationException {
    // Convert our list of User objects into a list of JSONObject
    List<JSONObject> jsonRecords = new ArrayList<JSONObject>();
    for (RawFriend rawFriend : dirtyFriends) {
        jsonRecords.add(rawFriend.toJSONObject());
    }// ww  w . j a v  a  2 s.c o m

    // Create a special JSONArray of our JSON contacts
    JSONArray buffer = new JSONArray(jsonRecords);

    // Create an array that will hold the server-side records
    // that have been changed (returned by the server).
    final ArrayList<RawFriend> serverDirtyList = new ArrayList<RawFriend>();

    // Prepare our POST data
    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, account.name));
    //params.add(new BasicNameValuePair(PARAM_AUTH_TOKEN, authtoken));
    params.add(new BasicNameValuePair(PARAM_RECORDS_DATA, buffer.toString()));
    String tempBuffer = null;
    if (authtoken.split(";").length > 1) {
        tempBuffer = authtoken.split(";")[1];
    }
    if (tempBuffer.length() > 10) {
        params.add(new BasicNameValuePair("csrfmiddlewaretoken", tempBuffer.substring(10)));
    }
    Log.d(TAG, "auth toke: " + authtoken);

    if (serverSyncState > 0) {
        params.add(new BasicNameValuePair(PARAM_SYNC_STATE, Long.toString(serverSyncState)));
    }
    Log.i(TAG, params.toString());
    HttpEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);

    // Send the updated friends data to the server
    Log.i(TAG, "Syncing to: " + SYNC_FRIENDS_URI);
    final HttpPost post = new HttpPost(SYNC_FRIENDS_URI);
    post.addHeader(entity.getContentType());
    post.addHeader("Cookie", authtoken);
    post.setEntity(entity);
    final HttpResponse resp = getHttpClient().execute(post);
    final String response = EntityUtils.toString(resp.getEntity());
    if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        // Our request to the server was successful - so we assume
        // that they accepted all the changes we sent up, and
        // that the response includes the contacts that we need
        // to update on our side...
        final JSONArray serverRecords = new JSONArray(response);
        Log.d(TAG, serverRecords.toString());
        for (int i = 0; i < serverRecords.length(); i++) {
            RawFriend rawRecord = RawFriend.valueOf(serverRecords.getJSONObject(i));
            if (rawRecord != null) {
                serverDirtyList.add(rawRecord);
            }
        }
    } else {
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            Log.e(TAG, "Authentication exception in sending dirty contacts");
            throw new AuthenticationException();
        } else {
            Log.e(TAG, "Server error in sending dirty friends: " + resp.getStatusLine());
            throw new IOException();
        }
    }

    return serverDirtyList;
}

From source file:com.talk.demo.util.NetworkUtilities.java

/**
 * Perform 2-way sync with the server-side contacts. We send a request that
 * includes all the locally-dirty contacts so that the server can process
 * those changes, and we receive (and return) a list of contacts that were
 * updated on the server-side that need to be updated locally.
 *
 * @param account The account being synced
 * @param authtoken The authtoken stored in the AccountManager for this
 *            account// www  .j  av  a 2s  .  c  o m
 * @param serverSyncState A token returned from the server on the last sync
 * @param dirtyContacts A list of the contacts to send to the server
 * @return A list of contacts that we need to update locally
 */
public static List<RawRecord> syncRecords(Account account, String authtoken, long serverSyncState,
        List<RawRecord> dirtyRecords)
        throws JSONException, ParseException, IOException, AuthenticationException {
    // Convert our list of User objects into a list of JSONObject
    List<JSONObject> jsonRecords = new ArrayList<JSONObject>();
    for (RawRecord rawRecord : dirtyRecords) {
        jsonRecords.add(rawRecord.toJSONObject());
    }

    // Create a special JSONArray of our JSON contacts
    JSONArray buffer = new JSONArray(jsonRecords);

    // Create an array that will hold the server-side records
    // that have been changed (returned by the server).
    final ArrayList<RawRecord> serverDirtyList = new ArrayList<RawRecord>();

    // Prepare our POST data
    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, account.name));
    //params.add(new BasicNameValuePair(PARAM_AUTH_TOKEN, authtoken));
    params.add(new BasicNameValuePair(PARAM_RECORDS_DATA, buffer.toString()));
    String tempBuffer = null;
    if (authtoken.split(";").length > 1) {
        tempBuffer = authtoken.split(";")[1];
    }
    if (tempBuffer.length() > 10) {
        params.add(new BasicNameValuePair("csrfmiddlewaretoken", tempBuffer.substring(10)));
    }
    Log.d(TAG, "auth toke: " + authtoken);

    if (serverSyncState > 0) {
        params.add(new BasicNameValuePair(PARAM_SYNC_STATE, Long.toString(serverSyncState)));
    }
    Log.i(TAG, params.toString());
    HttpEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);

    // Send the updated friends data to the server
    Log.i(TAG, "Syncing to: " + SYNC_RECORDS_URI);
    final HttpPost post = new HttpPost(SYNC_RECORDS_URI);
    post.addHeader(entity.getContentType());
    post.addHeader("Cookie", authtoken);
    post.setEntity(entity);
    final HttpResponse resp = getHttpClient().execute(post);
    final String response = EntityUtils.toString(resp.getEntity());
    if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        // Our request to the server was successful - so we assume
        // that they accepted all the changes we sent up, and
        // that the response includes the contacts that we need
        // to update on our side...
        final JSONArray serverRecords = new JSONArray(response);
        Log.d(TAG, serverRecords.toString());
        for (int i = 0; i < serverRecords.length(); i++) {
            RawRecord rawRecord = RawRecord.valueOf(serverRecords.getJSONObject(i));
            if (rawRecord != null) {
                serverDirtyList.add(rawRecord);
            }
        }
    } else {
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            Log.e(TAG, "Authentication exception in sending dirty contacts");
            throw new AuthenticationException();
        } else {
            Log.e(TAG, "Server error in sending dirty contacts: " + resp.getStatusLine());
            throw new IOException();
        }
    }

    return serverDirtyList;
}

From source file:ch.hesso.master.sweetcity.activity.report.ReportActivity.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);

    bitmapPicture = savedInstanceState.getParcelable("image");
    ArrayList<Integer> positionList = savedInstanceState.getIntegerArrayList("tagList");
    CurrentTagList.getInstance().putAllFromPositions(tagList, positionList);

    Log.d(Constants.PROJECT_NAME, "positionList " + positionList.toString());

    showTagList();/*from  w w  w.ja v  a2 s . co m*/
    showPicture();
}

From source file:eu.eexcess.federatedrecommender.decomposer.PseudoRelevanceWikipediaDecomposer.java

@Override
public SecureUserProfile decompose(SecureUserProfile inputSecureUserProfile) {

    TermSet<TypedTerm> terms = new TermSet<TypedTerm>(new TypedTerm.AddingWeightTermMerger());
    StringBuilder builder = new StringBuilder();
    for (ContextKeyword keyword : inputSecureUserProfile.contextKeywords) {
        if (builder.length() > 0) {
            builder.append(" ");
        }//from   w  w w . j a  v a  2s  .  c  o m
        builder.append(keyword.text);
        terms.add(new TypedTerm(keyword.text, null, 1));
    }
    String query = builder.toString();

    String localeName = null;
    // first, pick up the language specified by the user
    if (inputSecureUserProfile.languages != null && !inputSecureUserProfile.languages.isEmpty()) {
        Language firstLanguage = inputSecureUserProfile.languages.iterator().next();
        localeName = firstLanguage.iso2;
    } else {
        // then try to detect the language from the query
        String guessedLanguage = LanguageGuesser.getInstance().guessLanguage(query);
        if (guessedLanguage != null) {
            localeName = guessedLanguage;
        }
    }

    WikipediaQueryExpansion wikipediaQueryExpansion = localeToQueryExpansion.get(localeName);
    if (wikipediaQueryExpansion == null) {
        // no query expansion for the current locale, fall back to the first supported locale
        wikipediaQueryExpansion = localeToQueryExpansion.get(supportedLocales[0]);
    }

    try {
        TermSet<TypedTerm> queryExpansionTerms;
        queryExpansionTerms = wikipediaQueryExpansion.expandQuery(query);
        //         for (TypedTerm typedTerm : queryExpansionTerms.getTopTerms(100)) {
        //            System.out.println("TypedTerm: "+ typedTerm.getText() +" Type: "+typedTerm.getType() +" Weight: " +typedTerm.getWeight());
        //         }
        //         System.out.println(query  +" query #############################");
        terms.addAll(queryExpansionTerms.getTopTerms(5));
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Cannot expand the query using Wikipedia", e);
    }

    ArrayList<ContextKeyword> newContextKeywords = new ArrayList<ContextKeyword>();
    for (TypedTerm typedTerm : terms.getTopTerms(5)) {
        newContextKeywords.add(new ContextKeyword(typedTerm.getText(), ExpansionType.EXPANSION));
    }
    inputSecureUserProfile.contextKeywords.addAll(newContextKeywords);
    logger.log(Level.INFO, "Wikipedia Expansion: " + newContextKeywords.toString());
    return inputSecureUserProfile;

    //return null;
}

From source file:com.iggroup.oss.restdoclet.plugin.mojo.RestDocumentationMojo.java

/**
 * Generates services from the documentation of controllers and
 * data-binders.//ww w. j a v  a 2  s .  co  m
 * 
 * @throws BeansNotFoundException if a bean with an identifier or Java type
 *            can't be found.
 * @throws IOException if services can't be marshaled.
 * @throws JavadocNotFoundException if a controller's documentation can't be
 *            found.
 * @throws JiBXException if a JiBX exception occurs.
 */
private void services() throws IOException, JavadocNotFoundException, JiBXException {
    LOG.info("Generating services");
    DirectoryBuilder dirs = new DirectoryBuilder(baseDirectory, outputDirectory);

    int identifier = 1;
    List<Service> services = new ArrayList<Service>();

    LOG.info("Looking for mappings");
    HashMap<String, ArrayList<Method>> uriMethodMappings = new HashMap<String, ArrayList<Method>>();
    HashMap<String, Controller> uriControllerMappings = new HashMap<String, Controller>();
    HashMap<String, Collection<Uri>> multiUriMappings = new HashMap<String, Collection<Uri>>();
    for (Controller controller : controllers) {
        LOG.info(new StringBuilder().append("- Controller ").append(controller.getType()).toString());
        for (Method method : controller.getMethods()) {
            LOG.info(new StringBuilder().append("... for Method ").append(method.toString()));

            if (excludeMethod(method)) {
                continue;
            }

            // Collate multiple uris into one string key.
            Collection<Uri> uris = method.getUris();
            if (!uris.isEmpty()) {
                String multiUri = "";
                for (Uri uri : uris) {
                    multiUri = multiUri + ", " + uri;
                }

                multiUriMappings.put(multiUri, uris);
                ArrayList<Method> methodList = uriMethodMappings.get(multiUri);
                if (methodList == null) {
                    methodList = new ArrayList<Method>();
                    uriMethodMappings.put(multiUri, methodList);
                }
                methodList.add(method);
                uriControllerMappings.put(multiUri, controller);
            }
        }

    }

    LOG.info("Processing controllers...");
    for (String uri : uriControllerMappings.keySet()) {
        LOG.info(new StringBuilder().append("Processing controllers for ").append(uri).toString());
        Controller controller = uriControllerMappings.get(uri);
        LOG.info(new StringBuilder().append("Found controller ")
                .append(uriControllerMappings.get(uri).getType()).toString());
        ArrayList<Method> matches = uriMethodMappings.get(uri);
        LOG.info(new StringBuilder().append("Found methods ").append(matches.toString()).append(" ")
                .append(matches.size()).toString());

        Service service = new Service(identifier, multiUriMappings.get(uri),
                new Controller(controller.getType(), controller.getJavadoc(), matches));
        services.add(service);
        service.assertValid();
        JiBXUtils.marshallService(service, ServiceUtils.serviceFile(dirs, identifier));
        identifier++;
    }

    LOG.info("Processing services...");
    Services list = new Services();
    for (Service service : services) {
        org.apache.commons.collections.Predicate predicate = new ControllerTypePredicate(
                service.getController().getType());
        if (CollectionUtils.exists(list.getControllers(), predicate)) {
            ControllerSummary controller = (ControllerSummary) CollectionUtils.find(list.getControllers(),
                    predicate);
            controller.addService(service);
        } else {
            ControllerSummary controller = new ControllerSummary(service.getController().getType(),
                    service.getController().getJavadoc());
            controller.addService(service);
            list.addController(controller);
        }
    }

    LOG.info("Marshalling services...");
    list.assertValid();
    JiBXUtils.marshallServices(list, ServiceUtils.servicesFile(dirs));
}

From source file:com.example.research.whatis.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    Log.e("CLicked Menu", String.valueOf(id));
    Log.e("CLicked action", String.valueOf(R.id.action_settings));
    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        TextView view = (TextView) findViewById(R.id.textView);
        view.setVisibility(View.GONE);
        ListView lView = (ListView) findViewById(R.id.listView);
        lView.setVisibility(View.VISIBLE);

        ArrayList<String> storedWords = dbHelper.getAllWords();
        Log.e("SQLite", storedWords.toString());
        ArrayAdapter arrayAdapter = new ArrayAdapter(this, R.layout.activity_listview, R.id.wordsLabel,
                storedWords);/*from www .j ava2  s.com*/

        lView.setAdapter(arrayAdapter);
    }

    return super.onOptionsItemSelected(item);
}

From source file:jsoft.projects.photoclick.Dashboard.java

private void showCart() {
    ArrayList<String> selectedItems = new ArrayList<String>();
    ShoppingCart cart = new ShoppingCart(getApplicationContext());
    selectedItems = cart.getCartImages();
    Log.d("selected Images at Line No 298 on Dashboard", selectedItems.toString());

    Intent i = new Intent(this, Details.class);
    startActivity(i);// www.  j a  v a 2  s .  c  om
}

From source file:com.haulmont.cuba.gui.components.filter.AppliedFilter.java

protected String formatParamValue(Param param) {
    Object value = param.getValue();
    if (value == null)
        return "";

    if (param.isDateInterval()) {
        DateIntervalValue dateIntervalValue = AppBeans.getPrototype(DateIntervalValue.NAME, (String) value);
        return dateIntervalValue.getLocalizedValue();
    }//from www .  ja  v a 2  s .  c o m

    if (value instanceof Instance)
        return ((Instance) value).getInstanceName();

    if (value instanceof Enum)
        return messages.getMessage((Enum) value);

    if (value instanceof ArrayList) {
        ArrayList<String> names = new ArrayList<>();
        ArrayList list = ((ArrayList) value);
        for (Object obj : list) {
            if (obj instanceof Instance)
                names.add(((Instance) obj).getInstanceName());
            else {
                names.add(FilterConditionUtils.formatParamValue(param, obj));
            }
        }
        return names.toString();
    }

    return FilterConditionUtils.formatParamValue(param, value);
}

From source file:com.baochu.androidassignment.login.ProfileFragment.java

/**
 * Build user's info to display on the screen
 *///from   w w  w.j av a 2s . c  o  m
private String buildUserInfoDisplay(GraphUser user) {
    StringBuilder userInfo = new StringBuilder("");

    /**(name) - no special permissions required */
    userInfo.append(String.format("Name: %s\n", user.getName()));

    /** (birthday) - requires user_birthday permission */
    userInfo.append(String.format("Birthday: %s\n", user.getBirthday()));

    /**  (location) - requires user_location permission */
    GraphPlace location = user.getLocation();
    if (location != null) {
        userInfo.append(String.format("Location: %s\n", location.getProperty("name")));
    }

    /** (locale) - no special permissions required */
    userInfo.append(String.format("Locale: %s\n", user.getProperty("locale")));

    /** (languages) - requires user_likes permission. */
    JSONArray languages = (JSONArray) user.getProperty("languages");
    if (languages != null && languages.length() > 0) {
        ArrayList<String> languageNames = new ArrayList<String>();
        for (int i = 0; i < languages.length(); i++) {
            JSONObject language = languages.optJSONObject(i);
            languageNames.add(language.optString("name"));
        }
        userInfo.append(String.format("Languages: %s\n", languageNames.toString()));
    }
    return userInfo.toString();
}