本文整理汇总了Java中org.cubeengine.dirigent.context.Context类的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于org.cubeengine.dirigent.context包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseFormatter
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
* Parses the {@link NumberFormat} to use from the context arguments.
*
* @param context The context.
* @param args The arguments of the macro.
*
* @return the {@link NumberFormat}.
*/
private NumberFormat parseFormatter(Context context, Arguments args)
{
final String format = args.get(FORMAT_PARAM_NAME);
final Locale locale = context.get(LOCALE);
if (format != null)
{
return new DecimalFormat(format, DecimalFormatSymbols.getInstance(locale));
}
final Mode mode = Mode.loadFromContext(args, this.defaultMode);
if (Mode.INTEGER.equals(mode))
{
return NumberFormat.getIntegerInstance(locale);
}
if (Mode.CURRENCY.equals(mode))
{
return NumberFormat.getCurrencyInstance(locale);
}
if (Mode.PERCENT.equals(mode))
{
return NumberFormat.getPercentInstance(locale);
}
return NumberFormat.getInstance(locale);
}
示例2: buildAny
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
* Appends a Component to the builder
*
* @param component the component
* @param builder the builder
* @param context the context
*/
protected final void buildAny(Component component, BuilderT builder, Context context)
{
if (component instanceof ResolvedMacro)
{
buildResolved((ResolvedMacro)component, builder, context);
}
else if (component instanceof UnresolvableMacro)
{
buildUnresolvable((UnresolvableMacro)component, builder, context);
}
else if (component instanceof TextComponent)
{
buildText((TextComponent)component, builder, context);
}
else if (component instanceof ComponentGroup)
{
buildGroup((ComponentGroup)component, builder, context);
}
else
{
buildOther(component, builder, context);
}
}
示例3: parseFormatter
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
* Parses the {@link DateFormat} to use from the context arguments.
*
* @param context The context.
* @param args The arguments of the macro.
*
* @return the {@link DateFormat}.
*/
private DateFormat parseFormatter(Context context, Arguments args)
{
final String format = args.get(FORMAT_PARAM_NAME);
final Locale locale = context.get(LOCALE);
if (format != null)
{
return new SimpleDateFormat(format, locale);
}
final int defaultFormatStyle = parseDateFormatStyle(args);
final int dateFormatStyle = parseDateFormatStyle(args.get(DATE_PARAM_NAME), defaultFormatStyle);
final int timeFormatStyle = parseDateFormatStyle(args.get(TIME_PARAM_NAME), defaultFormatStyle);
if (Mode.DATE_TIME.equals(mode))
{
return DateFormat.getDateTimeInstance(dateFormatStyle, timeFormatStyle, locale);
}
else if (Mode.DATE.equals(mode))
{
return DateFormat.getDateInstance(dateFormatStyle, locale);
}
else if (Mode.TIME.equals(mode))
{
return DateFormat.getTimeInstance(timeFormatStyle, locale);
}
return DateFormat.getInstance();
}
示例4: parseNumberToString
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
* Parses the given number to a string depending on the context.
*
* @param number The number to parse.
* @param context The context to use.
* @param args The arguments of the macro.
*
* @return The number as a string.
*/
protected String parseNumberToString(Number number, Context context, Arguments args)
{
final NumberFormat numberFormat = parseFormatter(context, args);
final Currency currency = context.get(Contexts.CURRENCY);
if (currency != null)
{
numberFormat.setCurrency(currency);
}
return numberFormat.format(number);
}
示例5: format
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
protected Component format(final Object input, Context context, Arguments args)
{
final Class<?> inputClass = input.getClass();
final List<Formatter> candidates = new ArrayList<Formatter>();
for (Entry<Class<?>, Formatter> entry : formats.entrySet())
{
Class<?> formatterClass = entry.getKey();
if (inputClass == formatterClass)
{
// exact match will be used directly
return this.formats.get(formatterClass).format(input, context, args);
}
else if (formatterClass.isAssignableFrom(inputClass))
{
candidates.add(entry.getValue());
}
}
if (candidates.isEmpty())
{
return null;
}
Collections.sort(candidates, new Comparator<ReflectedFormatter.Formatter>()
{
@Override
public int compare(ReflectedFormatter.Formatter a, ReflectedFormatter.Formatter b)
{
// sort descending, so the highest priority value will be first.
return b.prio - a.prio;
}
});
return candidates.get(0).format(input, context, args);
}
示例6: compose
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
public MessageT compose(Context context, String source, Object... inputs)
{
List<Element> elements = Parser.parse(source);
ComponentGroup message = resolve(elements, context, inputs);
return compose(message, context);
}
示例7: applyPostProcessors
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
* Executes all attached {@link PostProcessor}s to process the specified {@link Component}.
*
* @param in The component to process.
* @param context The compose context.
* @param args The macro arguments.
*
* @return The processed component.
*/
private Component applyPostProcessors(Component in, Context context, Arguments args)
{
Component out = in;
for (final PostProcessor postProcessor : postProcessors)
{
out = postProcessor.process(out, context, args);
}
return out;
}
示例8: compose
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
protected MessageT compose(ComponentGroup componentGroup, Context context)
{
BuilderT builder = mBuilder.newBuilder();
mBuilder.buildGroup(componentGroup, builder, context);
return mBuilder.finalize(builder, context);
}
示例9: buildUnresolvable
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
public void buildUnresolvable(UnresolvableMacro component, StringBuilder builder, Context context)
{
Macro macro = component.getMacro();
if (macro instanceof NamedMacro)
{
builder.append("{{unresolved: ").append(((NamedMacro)macro).getName()).append("}}");
}
else
{
builder.append("{{unresolved}}");
}
}
示例10: buildGroup
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
/**
* Appends a chain of Components to the builder
*
* @param group the chained Components
* @param builder the builder
* @param context the context
*/
public void buildGroup(ComponentGroup group, BuilderT builder, Context context)
{
for (Component component : group.getComponents())
{
buildAny(component, builder, context);
}
}
示例11: checkFormat
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
private void checkFormat(final String expected, final Number number, final Locale locale, final Currency currency,
final String mode, final String value)
{
final Context context = createContext(LOCALE.with(locale), CURRENCY.with(currency));
final Arguments args = args(mode, value);
final Component component = numberFormatter.format(number, context, args);
Assert.assertTrue(component instanceof Text);
Assert.assertEquals(expected, ((Text)component).getText());
}
示例12: checkFormat
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
private void checkFormat(final String expected, final Date date, final Locale locale, final TimeZone timeZone,
final String defaultStyle, final String dateStyle, final String timeStyle,
final String format)
{
final Context context = createContext(Contexts.LOCALE.with(locale), Contexts.TIMEZONE.with(timeZone));
final Arguments args = createArguments(defaultStyle, dateStyle, timeStyle, format);
final Component component = formatter.format(date, context, args);
Assert.assertTrue(component instanceof Text);
Assert.assertEquals(expected, ((Text)component).getText());
}
示例13: testWrongParamsThreeParametersWithContext
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Test(expected = InvalidFormatMethodException.class)
public void testWrongParamsThreeParametersWithContext()
{
@Names("test")
class WrongParams extends ReflectedFormatter {
@Format
public Component test(String s, Context c, Integer i) {return null;}
}
new WrongParams();
}
示例14: testWrongParamsMoreParameters
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Test(expected = InvalidFormatMethodException.class)
public void testWrongParamsMoreParameters()
{
@Names("test")
class WrongParams extends ReflectedFormatter {
@Format
public Component test(String s, Context c, Arguments a, Integer i) {return null;}
}
new WrongParams();
}
示例15: format
import org.cubeengine.dirigent.context.Context; //导入依赖的package包/类
@Override
public Component format(TeleportPoint object, Context context, Arguments args)
{
String cmd = "/" + (object instanceof Home ? "home" : "warp") + " tp " + object.name + " " + object.getOwner().getName();
return styled(UNDERLINE, runCommand(cmd, hoverText(i18n.translate(context, NONE, "Click to teleport to {}", object.name), object.getOwner().getName())));
}