List of usage examples for com.google.common.collect Iterables get
public static <T> T get(Iterable<T> iterable, int position)
From source file:com.tage.calcite.adapter.druid.DruidTable.java
/** Creates a {@link com.tage.calcite.adapter.druid.DruidTable} * * @param druidSchema Druid schema/*w w w . j a v a2s .com*/ * @param dataSourceName Data source name in Druid, also table name * @param intervals Intervals, or null to use default * @param fieldMap Mutable map of fields (dimensions plus metrics); * may be partially populated already * @param metricNameSet Mutable set of metric names; * may be partially populated already * @param timestampColumnName Name of timestamp column, or null * @param connection If not null, use this connection to find column * definitions * @return A table */ static Table create(DruidSchema druidSchema, String dataSourceName, List<String> intervals, Map<String, SqlTypeName> fieldMap, Set<String> metricNameSet, String timestampColumnName, com.tage.calcite.adapter.druid.DruidConnectionImpl connection) { if (connection != null) { connection.metadata(dataSourceName, intervals, fieldMap, metricNameSet); } final ImmutableMap<String, SqlTypeName> fields = ImmutableMap.copyOf(fieldMap); if (timestampColumnName == null) { timestampColumnName = Iterables.get(fieldMap.keySet(), 0); } return new com.tage.calcite.adapter.druid.DruidTable(druidSchema, dataSourceName, new MapRelProtoDataType(fields), ImmutableSet.copyOf(metricNameSet), intervals, Util.first(timestampColumnName, "__time")); }
From source file:com.opengamma.financial.analytics.model.pnl.HistoricalValuationPnLFunction.java
@Override public Set<ValueRequirement> getRequirements(FunctionCompilationContext context, ComputationTarget target, ValueRequirement desiredValue) { final ValueProperties outputConstraints = desiredValue.getConstraints(); Set<String> startDates = desiredValue.getConstraints() .getValues(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY); if (startDates == null || startDates.size() != 1) { return null; }//from w w w .j a va 2 s .c o m Set<String> endDates = desiredValue.getConstraints() .getValues(HistoricalTimeSeriesFunctionUtils.END_DATE_PROPERTY); if (endDates == null || endDates.size() != 1) { return null; } Set<String> desiredCurrencies = desiredValue.getConstraints().getValues(ValuePropertyNames.CURRENCY); if (desiredCurrencies == null || desiredCurrencies.isEmpty()) { Collection<Currency> targetCurrencies = FinancialSecurityUtils .getCurrencies(target.getPosition().getSecurity(), context.getSecuritySource()); // REVIEW jonathan 2013-03-12 -- should we pass through all the currencies and see what it wants to produce? desiredCurrencies = ImmutableSet.of(Iterables.get(targetCurrencies, 0).getCode()); } String pnlSeriesStartDateProperty = ValueRequirementNames.PNL_SERIES + "_" + HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY; ValueProperties.Builder requirementConstraints = desiredValue.getConstraints().copy() .withoutAny(ValuePropertyNames.CURRENCY) .with(HistoricalValuationFunction.PASSTHROUGH_PREFIX + ValuePropertyNames.CURRENCY, desiredCurrencies) .withoutAny(ValuePropertyNames.PROPERTY_PNL_CONTRIBUTIONS) .withoutAny(ValuePropertyNames.SCHEDULE_CALCULATOR).withoutAny(ValuePropertyNames.SAMPLING_FUNCTION) .withoutAny(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY) .with(pnlSeriesStartDateProperty, outputConstraints.getValues(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY)) .withOptional(pnlSeriesStartDateProperty); String startDate = getPriceSeriesStart(outputConstraints); if (startDate == null) { return null; } requirementConstraints.with(HistoricalTimeSeriesFunctionUtils.START_DATE_PROPERTY, startDate); removeTransformationProperties(requirementConstraints); return ImmutableSet.of(new ValueRequirement(ValueRequirementNames.HISTORICAL_TIME_SERIES, target.toSpecification(), requirementConstraints.get())); }
From source file:com.urswolfer.intellij.plugin.gerrit.git.GerritGitUtil.java
public static void fetchChange(final Project project, final GitRepository gitRepository, final String branch, @Nullable final Callable<Void> successCallable) { GitVcs.runInBackground(new Task.Backgroundable(project, "Fetching...", false) { @Override/* w w w.j a va 2 s . c o m*/ public void onSuccess() { super.onSuccess(); try { if (successCallable != null) { successCallable.call(); } } catch (Exception e) { throw new RuntimeException(e); } } @Override public void run(@NotNull ProgressIndicator indicator) { final VirtualFile virtualFile = gitRepository.getGitDir(); final GitRemote gitRemote = Iterables.get(gitRepository.getRemotes(), 0); final String url = Iterables.get(gitRepository.getRemotes(), 0).getFirstUrl(); GerritGitUtil.fetchNatively(virtualFile, gitRemote, url, branch, project, indicator); } }); }
From source file:org.jclouds.gogrid.compute.strategy.FindPublicIpThenCreateNodeInGroup.java
@Override public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) { Server addedServer = null;/*from w w w .j av a2 s . com*/ boolean notStarted = true; int numOfRetries = 20; // lock-free consumption of a shared resource: IP address pool while (notStarted) { // TODO: replace with Predicate-based thread // collision avoidance for // simplicity Set<Ip> availableIps = client.getIpServices().getIpList(new GetIpListOptions().onlyUnassigned() .onlyWithType(IpType.PUBLIC).inDatacenter(template.getLocation().getId())); if (availableIps.size() == 0) throw new RuntimeException("No public IPs available on this identity."); int ipIndex = new SecureRandom().nextInt(availableIps.size()); Ip availableIp = Iterables.get(availableIps, ipIndex); try { addedServer = addServer(name, template, availableIp); notStarted = false; } catch (Exception e) { if (--numOfRetries == 0) Throwables.propagate(e); notStarted = true; } } if (template.getOptions().shouldBlockUntilRunning()) { serverLatestJobCompleted.apply(addedServer); client.getServerServices().power(addedServer.getName(), PowerCommand.START); serverLatestJobCompletedShort.apply(addedServer); addedServer = Iterables .getOnlyElement(client.getServerServices().getServersByName(addedServer.getName())); } return serverToNodeMetadata.apply(addedServer); }
From source file:blue.lapis.pore.impl.inventory.PorePlayerInventory.java
@Override public void setHelmet(ItemStack helmet) { // this code relies on the notion that Mojang won't implement hydra-people or something Iterables.get(this.getHandle().query(EquipmentTypes.HEADWEAR).<Slot>slots(), 0) .set(ItemStackConverter.of(helmet)); }
From source file:com.yahoo.yqlplus.language.logical.TypeCheckers.java
@SuppressWarnings("unchecked") private static OperatorTypeChecker createChecker(Operator parent, int idx, Object value) { if (value instanceof TypeLiteral) { TypeLiteral<?> lit = (TypeLiteral<?>) value; Class<?> raw = lit.getRawType(); if (List.class.isAssignableFrom(raw)) { Preconditions.checkArgument(lit.getType() instanceof ParameterizedType, "TypeLiteral without a ParameterizedType for List"); ParameterizedType type = (ParameterizedType) lit.getType(); TypeLiteral<?> arg = TypeLiteral.get(type.getActualTypeArguments()[0]); if (OperatorNode.class.isAssignableFrom(arg.getRawType())) { Preconditions.checkArgument(arg.getType() instanceof ParameterizedType, "Type spec must be List<OperatorNode<?>>"); Class<? extends Operator> optype = (Class<? extends Operator>) TypeLiteral .get(((ParameterizedType) arg.getType()).getActualTypeArguments()[0]).getRawType(); return new OperatorNodeListTypeChecker(parent, idx, optype, ImmutableSet.<Operator>of()); } else { return new JavaListTypeChecker(parent, idx, arg.getRawType()); }/*from w w w . jav a2 s . c o m*/ } throw new IllegalArgumentException("don't know how to handle TypeLiteral " + value); } if (value instanceof Class) { Class<?> clazz = (Class<?>) value; if (Operator.class.isAssignableFrom(clazz)) { return new NodeTypeChecker(parent, idx, (Class<? extends Operator>) clazz, ImmutableSet.<Operator>of()); } else { return new JavaTypeChecker(parent, idx, clazz); } } else if (value instanceof Operator) { Operator operator = (Operator) value; Class<? extends Operator> clazz = operator.getClass(); Set<? extends Operator> allowed; if (Enum.class.isInstance(value)) { Class<? extends Enum> enumClazz = (Class<? extends Enum>) clazz; allowed = (Set<? extends Operator>) EnumSet.of(enumClazz.cast(value)); } else { allowed = ImmutableSet.of(operator); } return new NodeTypeChecker(parent, idx, clazz, allowed); } else if (value instanceof EnumSet) { EnumSet<?> v = (EnumSet<?>) value; Enum elt = Iterables.get(v, 0); if (elt instanceof Operator) { Class<? extends Operator> opclass = (Class<? extends Operator>) elt.getClass(); Set<? extends Operator> allowed = (Set<? extends Operator>) v; return new NodeTypeChecker(parent, idx, opclass, allowed); } } else if (value instanceof Set) { // Set<Class<?>> return new JavaUnionTypeChecker(parent, idx, (Set<Class<?>>) value); } throw new IllegalArgumentException("I don't know how to create a checker from " + value); }
From source file:org.dtolabs.rundeck.jclouds.impl.BaseRundeckMapper.java
String mapHostname(final NodeMetadata metadata) { if (null != metadata.getPublicAddresses() && metadata.getPublicAddresses().size() > 0) { return Iterables.get(metadata.getPublicAddresses(), 0); } else if (null != metadata.getPrivateAddresses() && metadata.getPrivateAddresses().size() > 0) { return Iterables.get(metadata.getPrivateAddresses(), 0); }/*from w w w . j av a 2 s .co m*/ return null; }
From source file:org.icgc.dcc.portal.util.ElasticsearchResponseUtils.java
public static Long getLong(Object value) { if (null == value) { return null; }//from w w w . ja va2 s .c o m if (value instanceof Long) { return (Long) value; } if (value instanceof Float) { return ((Float) value).longValue(); } if (value instanceof Integer) { return Long.valueOf((Integer) value); } if (value instanceof Iterable<?>) { val iterable = (Iterable<?>) value; return Iterables.isEmpty(iterable) ? null : Longs.tryParse(Iterables.get(iterable, 0).toString()); } return Longs.tryParse(value.toString()); }
From source file:com.replaymod.replaystudio.pathing.change.RemoveKeyframe.java
@Override public void undo(Timeline timeline) { Preconditions.checkState(applied, "Not yet applied!"); Path path = timeline.getPaths().get(this.path); path.insert(removedKeyframe);// ww w.jav a2 s . c o m if (removedInterpolator != null) { if (index == path.getSegments().size()) { // The keyframe is the last one, restore the previous interpolator Iterables.get(path.getSegments(), index - 1).setInterpolator(removedInterpolator); } else { // Save the next iterpolator Iterables.get(path.getSegments(), index).setInterpolator(removedInterpolator); } } applied = false; }
From source file:org.richfaces.request.MultipartRequest25.java
@Override public String getParameter(String name) { String parameter = super.getParameter(name); if (parameter != null) { return parameter; }/* w w w.j a v a 2s.co m*/ parseIfNecessary(); Collection<String> values = params.get(name); if (values.isEmpty()) { return null; } return Iterables.get(values, 0); }