List of usage examples for com.google.common.collect Lists newLinkedList
@GwtCompatible(serializable = true) public static <E> LinkedList<E> newLinkedList()
From source file:org.opendaylight.protocol.bgp.util.BinaryBGPDumpFileParser.java
/** * Extract BGP messages from binary file in MRT format. * * @param byteArray array of bytes with BGP messages in binary form. * @return list with byte arrays representing extracted messages. *///w w w .j a v a 2s. c o m public static List<byte[]> parseMessages(final byte[] byteArray) { final List<byte[]> messages = Lists.newLinkedList(); // search for 16 FFs for (int i = 0; i < byteArray.length; i++) { final byte b = byteArray[i]; // Marker start if (b == UnsignedBytes.MAX_VALUE) { final int start = i; int ffCount = 0; for (int j = i; j <= i + MARKER_LENGTH; j++) { // Check marker if (byteArray[j] == UnsignedBytes.MAX_VALUE) { ffCount++; } else if (ffCount == MARKER_LENGTH) { if (j == (i + MARKER_LENGTH)) { // Parse length final int length = ByteArray.bytesToInt(new byte[] { byteArray[j], byteArray[j + 1] }); Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + start + ", length atribute is lower than " + MINIMAL_LENGTH); final byte[] message = Arrays.copyOfRange(byteArray, start, start + length); messages.add(message); j += length - MARKER_LENGTH; } i = j; break; } else { break; } } } } LOG.info("Succesfully extracted {} messages", messages.size()); return messages; }
From source file:io.druid.query.aggregation.AggregatorUtil.java
/** * returns the list of dependent postAggregators that should be calculated in order to calculate given postAgg * * @param postAggregatorList List of postAggregator, there is a restriction that the list should be in an order * such that all the dependencies of any given aggregator should occur before that aggregator. * See AggregatorUtilTest.testOutOfOrderPruneDependentPostAgg for example. * @param postAggName name of the postAgg on which dependency is to be calculated * * @return the list of dependent postAggregators */// w w w. ja v a 2 s . co m public static List<PostAggregator> pruneDependentPostAgg(List<PostAggregator> postAggregatorList, String postAggName) { LinkedList<PostAggregator> rv = Lists.newLinkedList(); Set<String> deps = new HashSet<>(); deps.add(postAggName); // Iterate backwards to find the last calculated aggregate and add dependent aggregator as we find dependencies in reverse order for (PostAggregator agg : Lists.reverse(postAggregatorList)) { if (deps.contains(agg.getName())) { rv.addFirst(agg); // add to the beginning of List deps.remove(agg.getName()); deps.addAll(agg.getDependentFields()); } } return rv; }
From source file:org.des.tao.ide.builder.EventBuilder.java
public EventBuilder() { this.eventMap = Maps.newHashMap(); this.edgeList = Lists.newLinkedList(); this.eventMap.put("edges", this.edgeList); }
From source file:voldemort.server.rebalance.RebalancerState.java
public static RebalancerState create(String json) { List<RebalanceTaskInfo> stealInfoList = Lists.newLinkedList(); JsonReader reader = new JsonReader(new StringReader(json)); for (Object o : reader.readArray()) { Map<?, ?> m = (Map<?, ?>) o; stealInfoList.add(RebalanceTaskInfo.create(m)); }// w w w. ja v a2s . c om return new RebalancerState(stealInfoList); }
From source file:com.lastcalc.parsers.currency.Currencies.java
public static List<Parser> getParsers() { if (currenciesByCode == null) { updateExchangeRates();/* ww w .j av a 2 s . c om*/ } final LinkedList<Parser> parsers = Lists.newLinkedList(); if (currenciesByCode != null) { for (final Entry<String, Currency> e : currenciesByCode.entrySet()) { parsers.add(new UnitParser(e.getValue(), TokenList.createD(e.getKey()))); parsers.add(new UnitParser(e.getValue(), TokenList.createD(e.getKey().toLowerCase()))); } parsers.add(new UnitParser(currenciesByCode.get("USD"), TokenList.createD("$"))); parsers.add(new UnitParser(currenciesByCode.get("EUR"), TokenList.createD(""))); parsers.add(new UnitParser(currenciesByCode.get("JPY"), TokenList.createD(""))); parsers.add(new UnitParser(currenciesByCode.get("GBP"), TokenList.createD(""))); parsers.add(new CurrencyReverser()); } return parsers; }
From source file:org.immutables.value.processor.meta.TelescopicBuild.java
static TelescopicBuild from(List<ValueAttribute> attributes) { List<ValueAttribute> mandatory = Lists.newArrayList(); List<ValueAttribute> finals = Lists.newArrayList(); for (ValueAttribute a : attributes) { if (a.isBuilderParameter) { continue; }/*from w ww. ja v a 2s. c om*/ if (a.isMandatory()) { mandatory.add(a); } else { finals.add(a); } } LinkedList<TelescopicStage> stages = Lists.newLinkedList(); if (!mandatory.isEmpty()) { Collections.reverse(mandatory); @Nullable TelescopicStage next = null; for (ValueAttribute m : mandatory) { next = new TelescopicStage(m, next); stages.addFirst(next); } } return new TelescopicBuild(stages, finals); }
From source file:org.trancecode.xml.saxon.SaxonBuilders.java
public static QName addAttribute(final QName name, final String value, final XdmNode namespaceContext, final SaxonBuilder builder) { // Namespace Fixup QName fixedupQName = name;//from w ww . j a v a 2 s .c o m boolean isNamespaceDeclared = false; boolean shouldChangePrefix = false; final Iterator<XdmNode> inscopeNamespaces = SaxonAxis.namespaces(namespaceContext).iterator(); final List<String> inscopePrefixes = Lists.newLinkedList(); // Check if the namespace is already declared... while (!isNamespaceDeclared && inscopeNamespaces.hasNext()) { final XdmNode inscopeNamespace = inscopeNamespaces.next(); final String inscopeNamespacePrefix = inscopeNamespace.getNodeName().getLocalName(); final String inscopeNamespaceUri = inscopeNamespace.getStringValue(); if (inscopeNamespaceUri.equals(fixedupQName.getNamespaceURI())) { LOG.trace("Namespace {} already declared", fixedupQName.getNamespaceURI()); isNamespaceDeclared = true; shouldChangePrefix = false; if (!inscopeNamespacePrefix.equals(fixedupQName.getPrefix())) { LOG.trace("Prefix '{}' changed to existing prefix '{}'", fixedupQName.getNamespaceURI(), inscopeNamespacePrefix); fixedupQName = new QName(inscopeNamespacePrefix, inscopeNamespaceUri, fixedupQName.getLocalName()); } } else if (inscopeNamespacePrefix.equals(fixedupQName.getPrefix())) { LOG.trace("Prefix '{}' already in use for namespace '{}'", inscopeNamespacePrefix, inscopeNamespaceUri); shouldChangePrefix = true; } inscopePrefixes.add(inscopeNamespacePrefix); } // If the attribute namespace has no prefix, create a dummy one if (!isNamespaceDeclared && "".equals(fixedupQName.getPrefix()) && !"".equals(fixedupQName.getNamespaceURI())) { fixedupQName = new QName("ns", fixedupQName.getNamespaceURI(), fixedupQName.getLocalName()); shouldChangePrefix = true; } if (shouldChangePrefix) { final int count = 1; String newPrefix = fixedupQName.getPrefix(); while (shouldChangePrefix) { newPrefix = newPrefix + count; shouldChangePrefix = false; final Iterator<String> prefixIterator = inscopePrefixes.iterator(); while (!shouldChangePrefix && prefixIterator.hasNext()) { if (newPrefix.equals(prefixIterator.next())) { shouldChangePrefix = true; } } } fixedupQName = new QName(newPrefix, fixedupQName.getNamespaceURI(), fixedupQName.getLocalName()); } // If the attribute namespace is not declared, explicitly declare it if (!isNamespaceDeclared) { builder.namespace(fixedupQName.getPrefix(), fixedupQName.getNamespaceURI()); } // Do add the attribute builder.attribute(fixedupQName, value); return fixedupQName; }
From source file:cc.kave.commons.model.naming.impl.v0.NameUtils.java
public static List<ITypeParameterName> ParseTypeParameterList(String id, int open, int close) { if (StringUtils.isNullOrEmpty(id) || open < 0 || close >= id.length() || close < open || id.charAt(open) != '[' || id.charAt(close) != ']') { Asserts.fail(f("error parsing parameters from '%s' (%d, %d)", id, open, close)); }/*w w w . j a v a 2s.c o m*/ List<ITypeParameterName> parameters = Lists.newLinkedList(); for (int cur = open; cur < close;) { cur++; // skip open bracket or comma cur = StringUtils.FindNext(id, cur, '['); int closeParam = StringUtils.FindCorrespondingCloseBracket(id, cur); cur++; // skip bracket String tpId = id.substring(cur, closeParam); parameters.add(new TypeParameterName(tpId)); closeParam++; // skip bracket cur = StringUtils.FindNext(id, closeParam, ',', ']'); } return parameters; }
From source file:com.jivesoftware.licenseserver.ActivityStreamServiceFactory.java
public ActivityStreamService build() { Map<String, String> headers = Maps.newHashMap(); headers.put("Accept", "application/json"); headers.put("Content-Type", "application/json"); List<Interceptor> interceptorList = Lists.newLinkedList(); interceptorList.add(new SignedFetchInterceptor()); JAXRSClientFactoryBean sf = new JAXRSClientFactoryBean(); sf.setResourceClass(ActivityStreamService.class); sf.setAddress("https://gateway.jivesoftware.com/gateway/api/activity/v1"); sf.setHeaders(headers);/*from ww w . j ava 2s. c o m*/ sf.setProvider(new JacksonJaxbJsonProvider()); sf.setOutInterceptors(interceptorList); BindingFactoryManager manager = sf.getBus().getExtension(BindingFactoryManager.class); JAXRSBindingFactory factory = new JAXRSBindingFactory(); factory.setBus(sf.getBus()); manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, factory); ActivityStreamService service = sf.create(ActivityStreamService.class); return service; }
From source file:com.textocat.textokit.commons.io.ProcessIOUtils.java
/** * @param proc process which input stream will receive bytes from the * argument input stream/*from w w w. ja va2s .co m*/ * @param in input stream. Note that it is closed at the end. */ public static void feedProcessInput(Process proc, final InputStream in, final boolean closeStdIn) throws IOException { final OutputStream procStdIn = proc.getOutputStream(); final List<Exception> exceptions = Lists.newLinkedList(); Thread writerThread = new Thread(new Runnable() { @Override public void run() { try { IOUtils.copy(in, procStdIn); if (closeStdIn) { procStdIn.flush(); closeQuietly(procStdIn); } } catch (Exception e) { exceptions.add(e); } finally { closeQuietly(in); } } }); writerThread.start(); try { writerThread.join(); } catch (InterruptedException e) { // do nothing, just set flag Thread.currentThread().interrupt(); } if (!exceptions.isEmpty()) { Exception ex = exceptions.get(0); throw ex instanceof IOException ? (IOException) ex : new IOException("Unexpected exception in writing thread", ex); } }