Search Results

Search found 547 results on 22 pages for 'hashmap'.

Page 17/22 | < Previous Page | 13 14 15 16 17 18 19 20 21 22  | Next Page >

  • spring json writes more json then i want

    - by mkoryak
    I am using the json spring view in order to return a simple JSON object from my controller. The problem is that its returning more data then i want. it is returning the validation errors and things inside of my model when all i am doing is this in the controller: Map model = new HashMap() model.put("success", "true"); return new ModelAndView("jsonView", model); If you look at the bottom of this page in the docs it looks like i am getting back data that POST would return. i am not doing a post, i am doing a GET by going directly to the URL with params. How do i get this lib to return just the data in my model?

    Read the article

  • java best way to transfer images

    - by d.raev
    I have a application that reads a PDF, transform the content to collection of TIF files, and send them to Glass Fish Server for saving. Usually there are 1-5 pages and it works nice, but when I got a input file with 100+ pages... it throws error on the transfer. Java heap space at java.util.Arrays.copyOf(Arrays.java:2786) at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94) Putting more resources is not a good option in my case, so I m looking for a way to optimize it somehow. I store the data in: HashMap<TifProfile, List<byte[]> Is there a better way to store or send them ? EDIT I did some tests and the final collections for PDF with 80 pages has size over 280mb (240 tiffs with different settings inside)

    Read the article

  • Digester: Extracting node name for a map<tagname, value>

    - by enguerran
    My question is close to this one: Digester: Extracting node name Even with the answer, I can't find out. Here is my xml file (from smartgwt RestDataSource POST): <data> <isc_OID_14> <attribute1>value1</attribute1> <attribute2>value2</attribute2> </isc_OID_14> </data> I would like to create, with Commons Digester, the following map : {attribute1=value1, attribute2=value2} I already have those lines: digester = new Digester(); digester.addObjectCreate("data", HashMap.class); // some "put" rules matching something like data/* return digester.parse(myFile); I do not know the list nor the name of tags in the <data><sourceId /></data>. isc_OID_14 or attribute1 can be named foobar or id or attribute335...

    Read the article

  • Best datastructure for frequently queried list of objects

    - by panzerschreck
    Hello, I have a list of objects say, List. The Entity class has an equals method,on few attributes ( business rule ) to differentiate one Entity object from the other. The task that we usually carry out on this list is to remove all the duplicates something like this : List<Entity> noDuplicates = new ArrayList<Entity>(); for(Entity entity: lstEntities) { int indexOf = noDuplicates.indexOf(entity); if(indexOf >= 0 ) { noDuplicates.get(indexOf).merge(entity); } else { noDuplicates.add(entity); } } Now, the problem that I have been observing is that this part of the code, is slowing down considerably as soon as the list has objects more than 10000.I understand arraylist is doing a o(N) search. Is there a faster alternative, using HashMap is not an option, because the entity's uniqueness is built upon 4 of its attributes together, it would be tedious to put in the key itself into the map ? will sorted set help in faster querying ? Thanks

    Read the article

  • Android -- Object Creation/Memory Allocation vs. Performance

    - by borg17of20
    Hello all, This is probably an easy one. I have about 20 TextViews/ImageViews in my current project that I access like this: ((TextView)multiLayout.findViewById(R.id.GameBoard_Multi_Answer1_Text)).setText(""); //or ((ImageView)multiLayout.findViewById(R.id.GameBoard_Multi_Answer1_Right)).setVisibility(View.INVISIBLE); My question is this, am I better off, from a performance standpoint, just assigning these object variables? Further, am I losing some performance to the constant "search" process that goes on as a part of the findViewById(...) method? (i.e. Does findsViewById(...) use some sort of hashtable/hashmap for look-ups or does it implement an iterative search over the view hierarchy?) At present, my program never uses more than 2.5MB of RAM, so will assigning 20 or so more object variables drastically affect this? I don't think so, but I figured I'd ask. Thanks.

    Read the article

  • Get first character of each word and its position in a sentence/paragraph

    - by Radhika
    I am trying to create a map by taking the first character of each word and it's position in a sentence/paragraph. I am using regex pattern to achieve this. Regex is a costly operation. Are there are any ways to achieve this? Regex way: public static void getFirstChar(String paragraph) { Pattern pattern = Pattern.compile("(?<=\\b)[a-zA-Z]"); Map newMap = new HashMap(); Matcher fit = pattern.matcher(paragraph); while (fit.find()) { newMap.put((fit.group().toString().charAt(0)), fit.start()); } }

    Read the article

  • Simplest one-to-many Map case in Hibernate doesn't work in MySQL

    - by Malvolio
    I think this is pretty much the simplest case for mapping a Map (that is, an associative array) of entities. @Entity @AccessType("field") class Member { @Id protected long id; @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY) @MapKey(name = "name") private Map<String, Preferences> preferences = new HashMap<String, Preferences>(); } @Entity @AccessType("field") class Preferences { @ManyToOne Member member; @Column String name; @Column String value; } This looks like it should work, and it does, in HSQL. In MySQL, there are two problems: First, it insists that there be a table called Members_Preferences, as if this were a many-to-many relationship. Second, it just doesn't work: since it never populates Members_Preferences, it never retrieves the Preferences. [My theory is, since I only use HSQL in memory-mode, it automatically creates Members_Preferences and never really has to retrieve the preferences map. In any case, either Hibernate has a huge bug in it or I'm doing something wrong.]

    Read the article

  • Some issue with bufferedReader

    - by thetna
    I have a java function as follows: public HashMap<String, ArrayList<Double>> embedWords(BufferedReader buffR1 { ArrayList<String > arrayList = new ArrayList<String>(); arrayList = getWords(buffR1); System.out.println("Word size:"+ arrayList.size()); ArrayList<ArrayList<Double>> arrList = getWordFeature(buffR1); System.out.println("Size of arrList:embedWords:"+arrList.size()); } Here , the problem is , the both of the function getWords and getWordFeatures can't give the size value. When i comment function getWords the function getWordFeature returns non-zero value .But when uncommented , the output is as follows: Word size:15055 Size of arrList:embedWords: 0

    Read the article

  • How to trigger code on two different servers in a WAS cluster?

    - by Dean J
    I have an administrative page in a web application that resets the cache, but it only resets the cache on the current JVM. The web application is deployed as a cluster to two WAS servers. Any way that I can elegantly have the "clear cache" button on each server trigger the method on both JVMs? Edit: The original developer just wrote a singleton holding a HashMap to be the cache in question. Lightweight and (previously) worked just fine for the requirements. It caches content pulled from six or seven web services for specified amounts of time. Edit: The entire application in question is three pages, so the elegant solution might well be the lightest solution.

    Read the article

  • I want to retrieve check items of list view

    - by kamil
    for(int i=0;i < users.size();i++) { map = new HashMap<String, String>(); map.put("id",String.valueOf(i)); map.put("userID", String.valueOf(users.get(i).getUserId())); map.put("emailID", users.get(i).getEmailAddress()); memList.add(map); } ListAdapter adapter = new SimpleAdapter(this, memList , R.layout.member_list_view, new String[] { "emailID" },new int[] { R.id.memTextView}); memberList.setAdapter(adapter); I have to retrieve the checked items on a separate button listener. how can I? I am using a customize list view. Plz help...

    Read the article

  • How do you search through a map?

    - by Jack Null
    I have a map: Map<String, String> ht = new HashMap(); and I would like to know how to search through it and find anything matching a particular string. And if it is a match store it into an arraylist. The map contains strings like this: 1,2,3,4,5,5,5 and the matching string would be 5. So for I have this: String match = "5"; ArrayList<String> result = new ArrayList<String>(); Enumeration num= ht.keys(); while (num.hasMoreElements()) { String number = (String) num.nextElement(); if(number.equals(match)) { result.add(number); } }

    Read the article

  • Android string formatiing from xml

    - by mann
    I am parsing xml from server. One of its node contains data like <distance>16.3432434324354324km</distance> I am putting it into hashmap like for (int i = 0; i < nl.getLength(); i++) { map.put(KEY_DISTANCE, parser.getValue(e, KEY_DISTANCE)); // adding HashList to ArrayList menuItems.add(map); } Everything is nice. But i want it two decimal places for example i want its value should be 16.34km rather then 16.343234324342342km I tried with DecimalFormat twoDForm=new DecimalFormat("##.00"); try{ Double StartVTwo=Double.valueOf(KEY_DISTANCE); Double resultDouble1 = Double.valueOf(twoDForm.format(StartVTwo)); Log.e("check", String.valueOf(resultDouble1)); }catch (NumberFormatException e){ Log.e("error"," This is error "); } But it shows exception and prints this message. Any help would be appreciated!!

    Read the article

  • Scala loop returns as Unit and compiler points to "for" syntax?

    - by DeLongey
    Seems like Unit is the theme of my troubles today. I'm porting a JSON deserializer that uses Gson and when it comes to this for loop: def deserialize(json:JsonElement, typeOfT:Type, context:JsonDeserializationContext) = { var eventData = new EventData(null, null) var jsonObject = json.getAsJsonObject for(entry <- jsonObject.entrySet()) { var key = entry.getKey() var element = entry.getValue() element if("previous_attributes".equals(key)) { var previousAttributes = new scala.collection.mutable.HashMap[String, Object]() populateMapFromJSONObject(previousAttributes, element.getAsJsonObject()) eventData.setPreviousAttributes(previousAttributes) eventData } else if ("object".equals(key)) { val `type` = element.getAsJsonObject().get("object").getAsString() var cl = objectMap.get(`type`).asInstanceOf[StripeObject] var `object` = abstractObject.retrieve(cl, key) eventData.setObject(`object`) eventData } } } The compiler spits out the error type mismatch; found : Unit required: com.stripe.EventData and it points to this line here: for(entry <- jsonObject.entrySet()) Questions Confirm that it is indeed the Gson method entrySet() appearing as unit? If not, what part of the code is creating the issue? I've set return types/values for eventData class methods Is there a workaround for the Gson Unit issue? Thanks!

    Read the article

  • ask. help me to compare two array of integers and the order does not matter.

    - by stdnoit
    [Example] <1 2 3 4 = <3 1 2 4 <1 2 3 4 != <3 4 1 1 and ummm it is in java. cant use hashmap table or anything just pure without library. I know there are two ways. 1. sort them and compare the array index by index 2. use two for loops and compare the outer index with the inner index. ( i have been trying with this but still not working) for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(a[i] != a[j] && j == n) return false; } } return true; anything wrong with the code ? thanks

    Read the article

  • Question About Eclipse Java Debugger Conditional Breakpoints Inefficiency

    - by Personman
    I just set a conditional breakpoint in Eclipse's debugger with a mildly inefficient condition by breakpoint standards - checking whether a HashMap's value list (8 elements) contains Double.NaN. This resulted in an extremely noticeable slowdown in performance - after about five minutes, I gave up. Then I copy pasted the condition into an if statement at the exact same line, put a noop in the if, and set a normal breakpoint there. That breakpoint was reached in the expected 20-30 seconds. Is there something special that conditional breakpoints do that is different from this, or is Eclipse's implementation just kinda stupid? It seems like they could fairly easily just do exactly the same thing behind the scenes.

    Read the article

  • The standard map/associative-array structure to use in flash actionscript 3?

    - by tstyle
    I'm relatively new to flash, and is confused about what I should use to store and retrieve key value pairs. After some googling I've found various map-like things to choose from: 1) Use a Object: var map:Object = new Object(); map["key"] = "value"; The problem is that it seems to lack some very basic features. For example to even get the size of map I'd have to write a util method. 2) Use a Dictionary What does this standard library class provide over the simple object? It seems silly for it to exist if it's functionally identical to Object. 3) Go download some custom HashMap/HashTable implementation from the web. I've used a lot of modern languages, and this is the first time I haven't been able to find a library implementation of an associative array within 5 minutes. So I'd like to get some best-practice advice from an experienced flash developer. Thanks!

    Read the article

  • Find all numbers that appear in each of a set of lists

    - by Ankur
    I have several ArrayLists of Integer objects, stored in a HashMap. I want to get a list (ArrayList) of all the numbers (Integer objects) that appear in each list. My thinking so far is: Iterate through each ArrayList and put all the values into a HashSet This will give us a "listing" of all the values in the lists, but only once Iterate through the HashSet 2.1 With each iteration perform ArrayList.contains() 2.2 If none of the ArrayLists return false for the operation add the number to a "master list" which contains all the final values. If you can come up with something faster or more efficient, funny thing is as I wrote this I came up with a reasonably good solution. But I'll still post it just in case it is useful for someone else. But of course if you have a better way please do let me know.

    Read the article

  • How to debug ConcurrentModificationException?

    - by Dani
    I encountered ConcurrentModificationException and by looking at it I can't see the reason why it's happening; the area throwing the exception and all the places modifying the collection are surrounded by synchronized (this.locks.get(id)) { ... } // locks is a HashMap<String, Object>; I tried to catch the the pesky thread but all I could nail (by setting a breakpoint in the exception) is that the throwing thread owns the monitor while the other thread (there are two threads in the program) sleeps. How should I proceed? What do you usually do when you encounter similar threading issues?

    Read the article

  • out-of-the-box way to get an idmap from hibernate for a given entity?

    - by Geert-Jan
    Over and over again I notive myself getting a list from hibernate, and the first thing next is put it in an idmap like: List<House> entities = s.createCriteria(House.class).list(); Map<String,House> entitymap = new HashMap<String,House>(); for(TA_entity e:entities){ entitymap.put(e.getId(), e); } Is there a way to get this directly out of hibenerate? afterall Hibernate is familiar with the id.

    Read the article

  • In-memory data structure that supports boolean querying

    - by sanity
    I need to store data in memory where I map one or more key strings to an object, as follows: "green", "blue" -> object1 "red", "yellow" -> object2 I need to be able to efficiently receive a list of objects, where the strings match some boolean criteria, such as: ("red" OR "green") AND NOT "blue" I'm working in Java, so the ideal solution would be an off-the-shelf Java library. I am, however, willing to implement something from scratch if necessary. Anyone have any ideas? I'd rather avoid the overhead of an in-memory database if possible, I'm hoping for something comparable in speed to a HashMap (or at least the same order of magnitude).

    Read the article

  • Is map/collection order stable between calls?

    - by John
    If I have a hash map and iterate over the objects repeatedly, is it correct that I'm not guaranteed the same order for every call? For example, could the following print two lines that differ from each other: Map<String,Integer> map = new HashMap<String,Integer>() {{ put("a", 1); put("b", 2); put("c", 3); }}; System.out.println(map); System.out.println(map); And is this the case for sets and collections in general? If so, what's the best way in case you have to iterate twice over the same collection in the same order (regardless of what order that is)? I guess converting to a list.

    Read the article

  • Key that yields multiple Results

    - by SgtStud
    I'm pretty new to programming so I'm sorry if this is a stupid question. I was wondering if there was a type of data that returns (possibly) more than one answer per key. For example: TestType<int,String> test = new TestType<int,String>(); So if you typed, test.getKey(1), you could get {"hello","this","is","a","test"}. Basically, is there a type of data that can return multiple answers, sort of like a HashMap and List combined?

    Read the article

  • Java loop and increment problem

    - by user552961
    Can any one tell me what is the problem in my program? String a[],b[]; int c[] = new int[b.length]; for (int j = 0; j < a.length; j++) { for (int k = 0; k < b.length; k++) { if (b[k].equals(a[j])) { c[k]++; } else { c[k] = 0; } } } I have thousands of words stored in a HashMap. Now I want to check in every file that how many time one word occurred from allWords. Can you point out mistake in my program or give me your idea that how I can do it?

    Read the article

  • Problem decrementing in Java with '-='

    - by hanesjw
    I'm making a scrolling game on Android and am having a hard time figuring out why the code below does not decrement past 0. Objects start at the end of the screen (so the x position is equal to the width of the screen) the objects move accross the screen by decrementing their x positions. I want them to scroll off of the screen, but when the x position hits 0, the objects just stay at 0, they do not move into the negatives. Here is my code to move objects on the screen private void incrementPositions(long delta) { float incrementor = (delta / 1000F) * Globals.MAP_SECTION_SPEED; for(Map.Entry<Integer, HashMap<Integer, MapSection>> column : scrollingMap.entrySet()) { for(Map.Entry<Integer, MapSection> row : column.getValue().entrySet()) { MapSection section = row.getValue(); section.x -= incrementor; } } } It works ok if I change section.x -= incrementor; to section.x = section.x - (int)incrementor; but if i do that the scrolling doesn't appear as smooth.

    Read the article

  • Sort an object by an other one.

    - by kevinb92
    Here's the deal : I have Publication objets in my application. I also have Vote objet. I can add votes on publication. A vote is defined like this, forOrAgainst, LinkedPublication, date, author etc etc... I want to sort Publication list by number of vote. What is the best way to link them ? Should i return a hashmap ? a treeset ? How do i add votes to publication. It's kinda messy in my brain now...

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22  | Next Page >