Java Code Examples for java.util.LinkedList#getFirst()

The following examples show how to use java.util.LinkedList#getFirst() . 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: StatsItem.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
private static StatsSnapshot computeStatsData(final LinkedList<CallSnapshot> csList) {
    StatsSnapshot statsSnapshot = new StatsSnapshot();
    synchronized (csList) {
        double tps = 0;
        double avgpt = 0;
        long sum = 0;
        if (!csList.isEmpty()) {
            CallSnapshot first = csList.getFirst();
            CallSnapshot last = csList.getLast();
            sum = last.getValue() - first.getValue();
            tps = (sum * 1000.0d) / (last.getTimestamp() - first.getTimestamp());

            long timesDiff = last.getTimes() - first.getTimes();
            if (timesDiff > 0) {
                avgpt = (sum * 1.0d) / timesDiff;
            }
        }

        statsSnapshot.setSum(sum);
        statsSnapshot.setTps(tps);
        statsSnapshot.setAvgpt(avgpt);
    }

    return statsSnapshot;
}
 
Example 2
Source File: Solution4.java    From LeetCode-Solution-in-Good-Style with Apache License 2.0 6 votes vote down vote up
public int[] maxSlidingWindow(int[] nums, int k) {
    int len = nums.length;
    if (len == 0) {
        return new int[0];
    }
    int[] res = new int[len - k + 1];
    LinkedList<Integer> queue = new LinkedList<>();
    for (int i = 0; i < len; i++) {
        if (i >= k && queue.getFirst() == i - k) {
            queue.removeFirst();
        }
        while (!queue.isEmpty() && nums[queue.getLast()] <= nums[i]) {
            queue.removeLast();
        }
        queue.add(i);
        if (i >= k - 1) {
            res[i - k + 1] = nums[queue.getFirst()];
        }
    }
    return res;
}
 
Example 3
Source File: StatsItem.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private static StatsSnapshot computeStatsData(final LinkedList<CallSnapshot> csList) {
    StatsSnapshot statsSnapshot = new StatsSnapshot();
    synchronized (csList) {
        double tps = 0;
        double avgpt = 0;
        long sum = 0;
        if (!csList.isEmpty()) {
            CallSnapshot first = csList.getFirst();
            CallSnapshot last = csList.getLast();
            sum = last.getValue() - first.getValue();
            tps = (sum * 1000.0d) / (last.getTimestamp() - first.getTimestamp());

            long timesDiff = last.getTimes() - first.getTimes();
            if (timesDiff > 0) {
                avgpt = (sum * 1.0d) / (timesDiff);
            }
        }

        statsSnapshot.setSum(sum);
        statsSnapshot.setTps(tps);
        statsSnapshot.setAvgpt(avgpt);
    }

    return statsSnapshot;
}
 
Example 4
Source File: OverloadedDynamicMethod.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
SingleDynamicMethod getMethodForExactParamTypes(final String paramTypes) {
    final LinkedList<SingleDynamicMethod> matchingMethods = new LinkedList<>();
    for(final SingleDynamicMethod method: methods) {
        final SingleDynamicMethod matchingMethod = method.getMethodForExactParamTypes(paramTypes);
        if(matchingMethod != null) {
            matchingMethods.add(matchingMethod);
        }
    }
    switch(matchingMethods.size()) {
        case 0: {
            return null;
        }
        case 1: {
            return matchingMethods.getFirst();
        }
        default: {
            throw new BootstrapMethodError("Can't choose among " + matchingMethods + " for argument types "
                    + paramTypes + " for method " + getName());
        }
    }
}
 
Example 5
Source File: OverloadedDynamicMethod.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
SingleDynamicMethod getMethodForExactParamTypes(String paramTypes) {
    final LinkedList<SingleDynamicMethod> matchingMethods = new LinkedList<>();
    for(SingleDynamicMethod method: methods) {
        final SingleDynamicMethod matchingMethod = method.getMethodForExactParamTypes(paramTypes);
        if(matchingMethod != null) {
            matchingMethods.add(matchingMethod);
        }
    }
    switch(matchingMethods.size()) {
        case 0: {
            return null;
        }
        case 1: {
            return matchingMethods.getFirst();
        }
        default: {
            throw new BootstrapMethodError("Can't choose among " + matchingMethods + " for argument types "
                    + paramTypes + " for method " + getName());
        }
    }
}
 
Example 6
Source File: 10650 Determinate Prime.java    From UVA with GNU General Public License v3.0 6 votes vote down vote up
public static void writeStr(LinkedList<Integer> seq, StringBuilder sb, int min, int max) {
	if (seq.size()>2) {
		int diff=seq.get(1)-seq.getFirst();
		int extendLeft=seq.getFirst()-diff;
		if (!notPrime[extendLeft] && primeIndex[seq.getFirst()]-1==primeIndex[extendLeft] && extendLeft<min) return;

		int extendRight=seq.getLast()+diff;
		if (!notPrime[extendRight] && primeIndex[seq.getLast()]+1==primeIndex[extendRight] && extendRight>max) return;
		
		for (int n : seq) {
			sb.append(n);
			sb.append(' ');
		}
		sb.setLength(sb.length()-1);
		sb.append('\n');
	}
}
 
Example 7
Source File: TCPEndpoint.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the current list of known transports.
 * The returned list is an unshared collection of Transports,
 * including all transports which may have channels to remote
 * endpoints.
 */
private static Collection<TCPTransport> allKnownTransports() {
    // Loop through local endpoints, getting the transport of each one.
    Set<TCPTransport> s;
    synchronized (localEndpoints) {
        // presize s to number of localEndpoints
        s = new HashSet<TCPTransport>(localEndpoints.size());
        for (LinkedList<TCPEndpoint> epList : localEndpoints.values()) {
            /*
             * Each local endpoint has its transport added to s.
             * Note: the transport is the same for all endpoints
             * in the list, so it is okay to pick any one of them.
             */
            TCPEndpoint ep = epList.getFirst();
            s.add(ep.transport);
        }
    }
    return s;
}
 
Example 8
Source File: GeoServerIT.java    From geowave with Apache License 2.0 6 votes vote down vote up
public boolean updatePoint(final String lockID) throws Exception {
  final Pair<CloseableHttpClient, HttpClientContext> clientAndContext = createClientAndContext();
  final CloseableHttpClient httpclient = clientAndContext.getLeft();
  final HttpClientContext context = clientAndContext.getRight();
  try {
    final HttpPost command = createWFSTransaction(httpclient, "1.1.0");
    command.setEntity(new StringEntity(update));
    final LinkedList<HttpResponse> capturedResponse = new LinkedList<>();
    run(new Runnable() {
      @Override
      public void run() {
        try {
          capturedResponse.add(httpclient.execute(command, context));
        } catch (final Exception e) {
          throw new RuntimeException("update point client failed", e);
        }
      }
    }, 500000);

    final HttpResponse r = capturedResponse.getFirst();

    return r.getStatusLine().getStatusCode() == Status.OK.getStatusCode();
  } finally {
    httpclient.close();
  }
}
 
Example 9
Source File: TCPEndpoint.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the current list of known transports.
 * The returned list is an unshared collection of Transports,
 * including all transports which may have channels to remote
 * endpoints.
 */
private static Collection<TCPTransport> allKnownTransports() {
    // Loop through local endpoints, getting the transport of each one.
    Set<TCPTransport> s;
    synchronized (localEndpoints) {
        // presize s to number of localEndpoints
        s = new HashSet<TCPTransport>(localEndpoints.size());
        for (LinkedList<TCPEndpoint> epList : localEndpoints.values()) {
            /*
             * Each local endpoint has its transport added to s.
             * Note: the transport is the same for all endpoints
             * in the list, so it is okay to pick any one of them.
             */
            TCPEndpoint ep = epList.getFirst();
            s.add(ep.transport);
        }
    }
    return s;
}
 
Example 10
Source File: GlobalExceptionHandler.java    From mPaaS with Apache License 2.0 6 votes vote down vote up
@Override
public ModelAndView resolveException(HttpServletRequest request,
                                     HttpServletResponse response,
                                     Object handler,
                                     Exception ex) {
    String traceid = TraceUtil.getTraceId();
    Determine determine = ExceptionUtil.determineType(ex);
    log.error("TraceId[{}]发生异常[{}]", traceid, determine.getName(), ex);
    ModelAndView mv = new ModelAndView(view);
    Response<?> result = null;
    LinkedList<Stack> stacks = ExceptionUtil.getStacks(ex, app, traceid);
    Stack stack = stacks.getFirst();
    Map<String, Object> data = new HashMap<>();
    data.put("traceid", traceid);
    data.put("stacks", stacks);
    result = Response.err(stack.getCode(), stack.getMessage(), data);
    mv.setStatus(determine.getStatus());
    return mv.addObject(result);
}
 
Example 11
Source File: PageInfo.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public String getURI(String prefix) {

        String uri = null;

        LinkedList<String> stack = xmlPrefixMapper.get(prefix);
        if (stack == null || stack.size() == 0) {
            uri = jspPrefixMapper.get(prefix);
        } else {
            uri = stack.getFirst();
        }

        return uri;
    }
 
Example 12
Source File: SnapshotCommands.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
protected void processArguments(LinkedList<PathData> items)
throws IOException {
  super.processArguments(items);
  if (numErrors != 0) { // check for error collecting paths
    return;
  }
  assert(items.size() == 1);
  PathData sroot = items.getFirst();
  Path snapshotPath = sroot.fs.createSnapshot(sroot.path, snapshotName);
  out.println("Created snapshot " + snapshotPath);
}
 
Example 13
Source File: MediationTimeoutTest.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Test csm banner timeout set on Console
 *
 * @throws Exception
 */
@Test
public void testBannerCSMResponseNonZeroTimeout() throws Exception {
    String bannerCSMString = TestResponsesUT.mediatedSuccessfulBannerTimeoutNonZero();

    utAdResponse = new UTAdResponse(bannerCSMString, null, MediaType.BANNER, "v");

    assertNotNull(utAdResponse);
    LinkedList<BaseAdResponse> list = utAdResponse.getAdList();
    assertNotNull(utAdResponse.getAdList());
    CSMSDKAdResponse baseCSMSDKAdResponse = (CSMSDKAdResponse) list.getFirst();
    assertEquals("csm", baseCSMSDKAdResponse.getContentSource());
    assertEquals(200, baseCSMSDKAdResponse.getNetworkTimeout());
}
 
Example 14
Source File: LargeCollectionPageReader.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Вовзращаем первй элемент списка.
 * Из списка этот элемент будет удален
 */
private static <T> T getAndRemoveFirst(LinkedList<T> list) {
    if (list == null || list.isEmpty())
        return null;
    T first = list.getFirst();
    list.removeFirst();
    return first;
}
 
Example 15
Source File: 11054 Wine trading in Gergovia.java    From UVA with GNU General Public License v3.0 5 votes vote down vote up
public static void main (String [] args) throws Exception {
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	String s;
	while (!(s=br.readLine()).equals("0")) {
		int N=Integer.parseInt(s);
		
		StringTokenizer st=new StringTokenizer(br.readLine());
		LinkedList<House> sell=new LinkedList<>();
		LinkedList<House> buy=new LinkedList<>();
		for (int n=0;n<N;n++) {
			House h=new House(n,Integer.parseInt(st.nextToken()));
			if (h.value<0) sell.add(h);
			else if (h.value>0) buy.add(h);
		}
		
		long ans=0;
		while (!sell.isEmpty() && !buy.isEmpty()) {
			House firstSell=sell.getFirst();
			House firstBuy=buy.getFirst();
			long v=Math.min(-firstSell.value,firstBuy.value);
			firstSell.value+=v;
			firstBuy.value-=v;
			ans+=(v*Math.abs(firstSell.index-firstBuy.index));
			if (firstSell.value==0) sell.removeFirst();
			if (firstBuy.value==0) buy.removeFirst();
		}
		
		System.out.println(ans);
	}
}
 
Example 16
Source File: PageInfo.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public String getURI(String prefix) {

        String uri = null;

        LinkedList<String> stack = xmlPrefixMapper.get(prefix);
        if (stack == null || stack.size() == 0) {
            uri = jspPrefixMapper.get(prefix);
        } else {
            uri = stack.getFirst();
        }

        return uri;
    }
 
Example 17
Source File: MediationTimeoutTest.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Test csm native server timeout
 *
 * @throws Exception
 */
@Test
public void testNativeCSMResponse() throws Exception {
    String bannerCSMString = TestResponsesUT.mediatedSuccessfulNative();

    utAdResponse = new UTAdResponse(bannerCSMString, null, MediaType.BANNER, "v");

    assertNotNull(utAdResponse);
    LinkedList<BaseAdResponse> list = utAdResponse.getAdList();
    assertNotNull(utAdResponse.getAdList());
    CSMSDKAdResponse baseCSMSDKAdResponse = (CSMSDKAdResponse) list.getFirst();
    assertEquals("csm", baseCSMSDKAdResponse.getContentSource());
    assertEquals(15000, baseCSMSDKAdResponse.getNetworkTimeout());
}
 
Example 18
Source File: JSONParser.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
private int peekStatus(LinkedList statusStack) {
    if (statusStack.size() == 0)
        return -1;
    Integer status = (Integer) statusStack.getFirst();
    return status.intValue();
}
 
Example 19
Source File: JSONParser.java    From hangout with MIT License 4 votes vote down vote up
private int peekStatus(LinkedList statusStack){
	if(statusStack.size()==0)
		return -1;
	Integer status=(Integer)statusStack.getFirst();
	return status.intValue();
}
 
Example 20
Source File: JSONParser.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private int peekStatus(LinkedList statusStack){
	if(statusStack.size()==0)
		return -1;
	Integer status=(Integer)statusStack.getFirst();
	return status.intValue();
}