本文整理汇总了Java中org.cactoos.map.StickyMap类的典型用法代码示例。如果您正苦于以下问题:Java StickyMap类的具体用法?Java StickyMap怎么用?Java StickyMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StickyMap类属于org.cactoos.map包,在下文中一共展示了StickyMap类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertsMapToProperties
import org.cactoos.map.StickyMap; //导入依赖的package包/类
@Test
public void convertsMapToProperties() {
MatcherAssert.assertThat(
"Can't convert map to properties",
new PropertiesOf(
new StickyMap<>(
new MapOf<Integer, String>(
new MapEntry<>(0, "hello, world"),
new MapEntry<>(1, "how are you?")
)
)
),
new ScalarHasValue<>(
new MatcherOf<Properties>(
props -> {
return props.getProperty("0").endsWith(", world");
}
)
)
);
}
示例2: pay
import org.cactoos.map.StickyMap; //导入依赖的package包/类
@Override
public void pay(final long cents, final String token, final String email)
throws IOException {
final String customer;
try {
customer = Customer.create(
new StickyMap<String, Object>(
new MapEntry<>("email", email),
new MapEntry<>("source", token)
),
new RequestOptions.RequestOptionsBuilder().setApiKey(
Manifests.read("ThreeCopies-StripeSecret")
).build()
).getId();
} catch (final APIException | APIConnectionException
| AuthenticationException | CardException
| InvalidRequestException ex) {
throw new IOException(ex);
}
this.item().put(
new AttributeUpdates()
.with(
"stripe_cents",
new AttributeValueUpdate().withValue(
new AttributeValue().withN(Long.toString(cents))
).withAction(AttributeAction.PUT)
)
.with(
"stripe_customer",
new AttributeValueUpdate().withValue(
new AttributeValue().withS(customer)
).withAction(AttributeAction.PUT)
)
);
this.rebill();
}
示例3: rebill
import org.cactoos.map.StickyMap; //导入依赖的package包/类
/**
* Charge him again.
* @throws IOException If fails
*/
private void rebill() throws IOException {
final Item item = this.item();
final Long cents = Long.parseLong(item.get("stripe_cents").getN());
final String customer = item.get("stripe_customer").getS();
try {
Charge.create(
new StickyMap<String, Object>(
new MapEntry<>("amount", cents),
new MapEntry<>("currency", "usd"),
new MapEntry<>(
"description",
String.format("ThreeCopies: %s", this.name)
),
new MapEntry<>("customer", customer)
),
new RequestOptions.RequestOptionsBuilder().setApiKey(
Manifests.read("ThreeCopies-StripeSecret")
).build()
);
} catch (final APIException | APIConnectionException
| AuthenticationException | CardException
| InvalidRequestException ex) {
throw new IOException(ex);
}
this.item().put(
"paid",
new AttributeValueUpdate().withValue(
new AttributeValue().withN(
Long.toString(cents * TimeUnit.HOURS.toSeconds(1L))
)
).withAction(AttributeAction.ADD)
);
}