Java Code Examples for java.util.LinkedList#get()
The following examples show how to use
java.util.LinkedList#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthCacheImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public synchronized AuthCacheValue get (String pkey, String skey) { AuthenticationInfo result = null; LinkedList<AuthCacheValue> list = hashtable.get (pkey); if (list == null || list.size() == 0) { return null; } if (skey == null) { // list should contain only one element return (AuthenticationInfo)list.get (0); } ListIterator<AuthCacheValue> iter = list.listIterator(); while (iter.hasNext()) { AuthenticationInfo inf = (AuthenticationInfo)iter.next(); if (skey.startsWith (inf.path)) { return inf; } } return null; }
Example 2
Source File: RandomNumberGenerator.java From Neural-Network-Programming-with-Java-SecondEdition with MIT License | 6 votes |
public static int[] hashInt(int start,int end){ LinkedList<Integer> ll = new LinkedList<>(); ArrayList<Integer> al = new ArrayList<>(); for(int i=start;i<=end;i++){ ll.add(i); } int start0=0; for(int end0=end-start;end0>start0;end0--){ int rnd = RandomNumberGenerator.GenerateIntBetween(start0, end0); int value = ll.get(rnd); ll.remove(rnd); al.add(value); } al.add(ll.get(0)); ll.remove(0); return ArrayOperations.arrayListToIntVector(al); }
Example 3
Source File: LastNumberInCircle.java From AtOffer with Apache License 2.0 | 6 votes |
/** * 【法1】: * 经典的环形链表,每次删除第m个结点,直到剩下最后一个 * 这里我们可以用LinkedList来模拟环形链表,然后每次走m步,list.remove(idx); * @param n * @param m * @return */ public int lastRemaining1(int n, int m) { if(n < 1 || m < 1) { return -1; } LinkedList<Integer> nums = new LinkedList<>(); for (int i = 0; i < n; i++) { nums.add(i); } int idx = 0; while(nums.size() > 1) { // 每次从idx移动m-1步就能移动到要删除的元素 for (int i = 0; i < m-1; i++) { idx++; idx %= nums.size(); } nums.remove(idx); } return nums.get(0); }
Example 4
Source File: ConstructiveRegression.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Create pruned versions of all important matrices / vectors so that only rows / columns * matching the indices in basisSet are kept. */ protected void prune(LinkedList<Integer> basisSet) { /** Create PHIt */ double[][] PHI_t_Array = new double[basisSet.size()][]; for (int j = 0; j < basisSet.size(); j++) { PHI_t_Array[j] = phi[basisSet.get(j)]; } PHI_t = new Matrix(PHI_t_Array); /** Create diagonal Matrix A */ A = new Matrix(basisSet.size(), basisSet.size()); for (int j = 0; j < basisSet.size(); j++) { A.set(j, j, alpha[basisSet.get(j)]); } }
Example 5
Source File: DataStorage.java From jmg with GNU General Public License v2.0 | 6 votes |
/** Returns a random pattern from hashMap which has required jumpvalue. * @param jumpValue * @param patternsHashMap * @return New instance of pattern (no needs to wrap into new Pattern()); */ public static Pattern getRandomPatternByJumpValue( int jumpValue, HashMap<Integer, LinkedList<Pattern>> patternsHashMap ) { if(!patternsHashMap.containsKey(jumpValue)) { Log.severe("DataStorage > getRandomPatternByJumpValue > No entries for this jump value! Value = " + jumpValue); return new SNPattern(JMC.D4, JMC.QUARTER_NOTE); // I'm a kind person, I always can give asker a D ;) } LinkedList<Pattern> goodPatterns = patternsHashMap.get(jumpValue); int randomId = (int)(Math.random()*(goodPatterns.size() - 1)); return new Pattern(goodPatterns.get(randomId)); }
Example 6
Source File: AuthCacheImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public synchronized AuthCacheValue get (String pkey, String skey) { AuthenticationInfo result = null; LinkedList<AuthCacheValue> list = hashtable.get (pkey); if (list == null || list.size() == 0) { return null; } if (skey == null) { // list should contain only one element return (AuthenticationInfo)list.get (0); } ListIterator<AuthCacheValue> iter = list.listIterator(); while (iter.hasNext()) { AuthenticationInfo inf = (AuthenticationInfo)iter.next(); if (skey.startsWith (inf.path)) { return inf; } } return null; }
Example 7
Source File: BindBeanSharedPreferences.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueStrinList serialization */ protected String serializeValueStrinList(LinkedList<String> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; jacksonSerializer.writeStartObject(); int fieldCount=0; if (value!=null) { fieldCount++; int n=value.size(); String item; // write wrapper tag jacksonSerializer.writeFieldName("valueStrinList"); jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=value.get(i); if (item==null) { jacksonSerializer.writeNull(); } else { jacksonSerializer.writeString(item); } } jacksonSerializer.writeEndArray(); } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toString(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 8
Source File: size.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void size(String command) throws Exception { LinkedList list = new LinkedList(); gfsh.parseCommand(command, list); String regionPath; if (list.size() == 1) { regionPath = gfsh.getCurrentPath(); } else if (list.size() == 2) { regionPath = (String)list.get(1); } else { regionPath = (String)list.get(2); } regionPath = regionPath.trim(); if (regionPath.equals("/")) { gfsh.println("Error: Invalid path. Root path not allowed."); return; } regionPath = gfsh.getFullPath(regionPath, gfsh.getCurrentPath()); gfsh.println(" Region: " + regionPath); // Local region Cache cache = gfsh.getCache(); Region region = cache.getRegion(regionPath); if (region == null) { gfsh.println("Error: region undefine - " + regionPath); } else { gfsh.println(" Local region size: " + region.size()); } }
Example 9
Source File: WeekTrackerTest.java From vertx-scheduler with Apache License 2.0 | 5 votes |
private boolean checkBack(LinkedList<EventInfo> events, Date d1, Date d2) { print(events); if(events.size() != 2) return false; EventInfo e1 = events.get(0); if(e1.isDstAheadHour != false || e1.isDstBackHour1 != true || e1.isDstBackHour2 != false || !e1.date.equals(d1)) return false; EventInfo e2 = events.get(1); if(e2.isDstAheadHour != false || e2.isDstBackHour1 != false || e2.isDstBackHour2 != true || !e2.date.equals(d2)) return false; return true; }
Example 10
Source File: Path.java From pdfxtk with Apache License 2.0 | 5 votes |
/** Constructs a path from a linked list of GraphNodes. @param path a linked list of GraphNodes representing the path to a node. */ public Path(LinkedList path) { if(path == null || path.size() == 0) throw new IllegalArgumentException("path in Path must be non null and not empty."); lastPathComponent = (GraphNode)path.get(path.size() - 1); if(path.size() > 1) parentPath = new Path(path, path.size() - 1); }
Example 11
Source File: ls.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private String retrievePath(String command){ LinkedList<String> list = new LinkedList<String>(); Gfsh.parseCommand(command, list); String regionPath; if (list.size() == 2) { regionPath = gfsh.getCurrentPath(); } else { regionPath = (String) list.get(2); } return regionPath; }
Example 12
Source File: LinkedListsLongTest.java From SPDS with Eclipse Public License 2.0 | 5 votes |
@Test public void addAndRetrieveByIndex3() { LinkedList<Object> list = new LinkedList<Object>(); Object b = new Object(); Object a = new Alloc(); list.add(a); list.add(b); Object c = list.get(0); queryFor(c); }
Example 13
Source File: ESUtils.java From yuzhouwan with Apache License 2.0 | 5 votes |
public static RestClientBuilder getESHosts() { if (isBlank(ES_HOSTS)) throw new RuntimeException("Cannot get elasticSearch hosts from config! " + "Please check es.hosts config option."); String[] hosts = ES_HOSTS.split(","); int len; if ((len = hosts.length) <= 0) throw new RuntimeException("Cannot get elasticSearch hosts from config! " + "Please check es.hosts config option."); String host; String[] hostAndPort; LinkedList<HttpHost> httpHosts = new LinkedList<>(); for (int i = 0; i < len; i++) { host = hosts[i]; hostAndPort = host.split(":"); if (hostAndPort.length != 2) { LOG.warn("Invalid es host: {}!", host); continue; } httpHosts.add(new HttpHost(hostAndPort[0], Integer.parseInt(hostAndPort[1]), "http")); } int size; HttpHost[] httpHostsArray = new HttpHost[size = httpHosts.size()]; for (int i = 0; i < size; i++) { httpHostsArray[i] = httpHosts.get(i); } return RestClient.builder(httpHostsArray); }
Example 14
Source File: Bean64Table.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute valueCharList serialization */ public static byte[] serializeValueCharList(LinkedList<Character> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; jacksonSerializer.writeStartObject(); int fieldCount=0; if (value!=null) { fieldCount++; int n=value.size(); Character item; // write wrapper tag jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=value.get(i); if (item==null) { jacksonSerializer.writeNull(); } else { jacksonSerializer.writeNumber(item); } } jacksonSerializer.writeEndArray(); } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 15
Source File: rmdir.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void rmdir_s(String command) throws Exception { LinkedList list = new LinkedList(); gfsh.parseCommand(command, list); String regionPath = null; if (list.size() > 2) { regionPath = (String)list.get(2); } else { gfsh.println("Error: must specify a region path to remove"); return; } remove_server(regionPath, false); }
Example 16
Source File: Fusion.java From SPADE with GNU General Public License v3.0 | 5 votes |
private void checkLists(LinkedList sourceList, LinkedList destinationList, boolean compare) { // Comparison and fusion is done if the compare flag is set if (compare) { // Get the most recently added element to the source list. This is // compared to all the elements in the other list Object newElement = sourceList.peekLast(); if (newElement instanceof AbstractVertex) { AbstractVertex newVertex = (AbstractVertex) newElement; for (int i = 0; i < destinationList.size(); i++) { Object otherElement = destinationList.get(i); if (otherElement instanceof AbstractVertex) { AbstractVertex otherVertex = (AbstractVertex) otherElement; // This condition is used to check for elements in the list that // have already been fused in which case comparison and fusion // is unnecessary if (!otherVertex.getAnnotation(SOURCE_REPORTER).equalsIgnoreCase(FUSED_SOURCE_REPORTER) && compare(newVertex, otherVertex)) { fuseAndReplace(newVertex, otherVertex); } } } } } // Check if the list size is exceeded. If yes, remove the element from // the head of the list and forward it to the next filter if (sourceList.size() > MAX_LIST_LENGTH) { Object removedElement = sourceList.poll(); if (removedElement instanceof AbstractVertex) { putInNextFilter((AbstractVertex) removedElement); } else if (removedElement instanceof AbstractEdge) { putInNextFilter((AbstractEdge) removedElement); } } }
Example 17
Source File: Splitter.java From cramtools with Apache License 2.0 | 4 votes |
static LinkedList<CigEl> pack(List<CigEl> list) { LinkedList<CigEl> result = new LinkedList<CigEl>(); for (CigEl e : list) { add(result, e); int prevIndex = result.size() - 1; while (prevIndex > 0) { CigEl lastE = result.get(prevIndex); char lastType = collapsibleType(lastE.op); if (lastType > 0) { --prevIndex; CigEl prevE = result.get(prevIndex); char prevType = collapsibleType(prevE.op); if (prevType == 0 || lastType == prevType) break; // collapse insertion and deletion and generate 'M'/'N' to // replace the overlapping part boolean prevEShorter = prevE.len < lastE.len; CigEl shortE = prevEShorter ? prevE : lastE; CigEl longE = !prevEShorter ? prevE : lastE; longE.len -= shortE.len; if (longE.op == 'I' || shortE.op == 'I') { shortE.op = 'M'; } else { shortE.op = 'N'; } if (prevE.len == 0) { result.remove(prevIndex); break; } else if (prevIndex > 0) { CigEl checkE = result.get(prevIndex - 1); if (checkE.op == prevE.op) { checkE.len += prevE.len; result.remove(prevIndex); } else { Collections.swap(result, prevIndex, prevIndex + 1); } } } else break; } } return result; }
Example 18
Source File: Histogram.java From chipster with MIT License | 4 votes |
private FloatArrayList getHistogram(int histogramSteps, String expression) throws MicroarrayException, IOException { // get data Iterable<Float> intensities = data.queryFeatures(expression).asFloats(); LinkedList<Float> values = new LinkedList<Float>(); for (float intensity : intensities) { values.add(intensity); } // sort it, so we don't have to search for value intervals Collections.sort(values); // filter out NaN's while (values.get(values.size() - 1).isNaN()) { values.remove(values.size() - 1); } if (values.size() < histogramSteps) { return new FloatArrayList(values); // can't make histogram, return // plain values } // determine step size float min = values.get(0); float max = values.get(values.size() - 1); float stepSize = (max - min) / ((float) histogramSteps); // initialise float[] histogram = new float[histogramSteps]; int valueIndex = 0; float roof = min + stepSize; // step through categories, counting matching values as we go for (int step = 0; step < histogram.length; step++) { while (valueIndex < values.size() && values.get(valueIndex) <= roof) { histogram[step]++; valueIndex++; } roof += stepSize; } // add to last category what was left out histogram[histogram.length - 1] += (values.size() - valueIndex); return new FloatArrayList(histogram); }
Example 19
Source File: get.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private void get(String command) throws Exception { if (gfsh.getCurrentRegion() == null) { gfsh.println("Error: Region undefined. Use 'cd' to change region first before executing this command."); return; } LinkedList list = new LinkedList(); gfsh.parseCommand(command, list); if (list.size() < 2) { gfsh.println("Error: get requires a query predicate"); } else { String input = (String) list.get(1); Object key = null; Object value; if (input.startsWith("'")) { int lastIndex = -1; if (input.endsWith("'") == false) { lastIndex = input.length(); } else { lastIndex = input.lastIndexOf("'"); } if (lastIndex <= 1) { gfsh.println("Error: Invalid key. Empty string not allowed."); return; } key = input.subSequence(1, lastIndex); // lastIndex exclusive } else { key = ObjectUtil.getPrimitive(gfsh, input, false); if (key == null) { key = gfsh.getQueryKey(list, 1); } } if (key == null) { return; } long startTime = System.currentTimeMillis(); value = gfsh.getCurrentRegion().get(key); long stopTime = System.currentTimeMillis(); if (value == null) { gfsh.println("Key not found."); return; } HashMap keyMap = new HashMap(); keyMap.put(1, key); PrintUtil.printEntries(gfsh.getCurrentRegion(), keyMap, null); if (gfsh.isShowTime()) { gfsh.println("elapsed (msec): " + (stopTime - startTime)); } } }
Example 20
Source File: PerBtwnArlAndLklT.java From java-core-learning-example with Apache License 2.0 | 4 votes |
/** * ArrayList与LinkedList各方法性能的对比 */ public static void testPerBtwnArlAndLkl(){ ArrayList<Integer> arrayList = new ArrayList<Integer>(); LinkedList<Integer> linkedList = new LinkedList<Integer>(); // ArrayList add方法 long startTime = System.nanoTime(); long endTime; long duration; for (int i = 0; i < 100000; i++) arrayList.add(i); endTime = System.nanoTime(); duration = endTime - startTime; System.out.println("ArrayList add: " + duration); // LinkedList add方法 startTime = System.nanoTime(); for (int i = 0; i < 100000; i++) linkedList.add(i); endTime = System.nanoTime(); duration = endTime - startTime; System.out.println("LinkedList add: " + duration); // ArrayList get方法 startTime = System.nanoTime(); for (int i = 0; i < 10000; i++) arrayList.get(i); endTime = System.nanoTime(); duration = endTime - startTime; System.out.println("ArrayList get: " + duration); // LinkedList get方法 startTime = System.nanoTime(); for (int i = 0; i < 10000; i++) linkedList.get(i); endTime = System.nanoTime(); duration = endTime - startTime; System.out.println("LinkedList get: " + duration); // ArrayList remove方法 startTime = System.nanoTime(); for (int i = 9999; i >=0; i--) arrayList.remove(i); endTime = System.nanoTime(); duration = endTime - startTime; System.out.println("ArrayList remove: " + duration); // LinkedList remove方法 startTime = System.nanoTime(); for (int i = 9999; i >=0; i--) linkedList.remove(i); endTime = System.nanoTime(); duration = endTime - startTime; System.out.println("LinkedList remove: " + duration); }