Search in sources :

Example 1 with StringUtils.capitalize

use of org.apache.commons.lang3.StringUtils.capitalize in project spring-roo by spring-projects.

the class RepositoryJpaCustomImplMetadataProviderImpl method buildFieldNamesMap.

/**
 * Build a Map<String, String> with field names and "path" field names
 * and adds it to the typesFieldMaps Map.
 *
 * @param entity
 * @param projection
 * @param entityProjectionAnnotation
 * @param typesFieldMaps
 */
private void buildFieldNamesMap(JavaType entity, JavaType projection, AnnotationMetadata entityProjectionAnnotation, Map<JavaType, List<Pair<String, String>>> typesFieldMaps) {
    List<Pair<String, String>> projectionFieldNames = new ArrayList<Pair<String, String>>();
    if (!typesFieldMaps.containsKey(projection)) {
        AnnotationAttributeValue<?> projectionFields = entityProjectionAnnotation.getAttribute("fields");
        if (projectionFields != null) {
            @SuppressWarnings("unchecked") List<StringAttributeValue> values = (List<StringAttributeValue>) projectionFields.getValue();
            // Get entity name as a variable name for building constructor expression
            String entityVariableName = StringUtils.uncapitalize(entity.getSimpleTypeName());
            for (StringAttributeValue field : values) {
                String[] splittedByDot = StringUtils.split(field.getValue(), ".");
                StringBuffer propertyName = new StringBuffer();
                for (int i = 0; i < splittedByDot.length; i++) {
                    if (i == 0) {
                        propertyName.append(splittedByDot[i]);
                    } else {
                        propertyName.append(StringUtils.capitalize(splittedByDot[i]));
                    }
                }
                String pathName = entityVariableName.concat(".").concat(field.getValue());
                projectionFieldNames.add(Pair.of(propertyName.toString(), pathName));
                typesFieldMaps.put(projection, projectionFieldNames);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with StringUtils.capitalize

use of org.apache.commons.lang3.StringUtils.capitalize in project FoodCraft-Reloaded by LasmGratel.

the class RegisterLoader method detectAndRegisterLiqueur.

public void detectAndRegisterLiqueur(RegistryEvent.Register<Item> event) {
    event.getRegistry().getKeys().stream().filter(s -> s.getResourcePath().contains("liqueur")).map(ForgeRegistries.ITEMS::getValue).collect(Collectors.toList()).forEach(liqueur -> {
        for (LiqueurType liqueurType : LiqueurTypes.values()) {
            if (liqueurType == LiqueurTypes.NORMAL)
                continue;
            ItemGeneratedLiqueur typedLiqueur = new ItemGeneratedLiqueur(MathHelper.floor(liqueurType.getHealModifier() * ((ItemFood) liqueur).getHealAmount(new ItemStack(liqueur))));
            typedLiqueur.setLiqueurType(liqueurType);
            typedLiqueur.setItemStackDisplayNameCallback(liqueur::getItemStackDisplayName);
            typedLiqueur.setRegistryName(liqueur.getRegistryName().getResourceDomain(), liqueurType.getUnlocalizedName() + "_" + liqueur.getRegistryName().getResourcePath());
            typedLiqueur.setUnlocalizedName(liqueur.getUnlocalizedName());
            event.getRegistry().register(typedLiqueur);
            OreDictionary.registerOre("listAll" + StringUtils.capitalize(liqueurType.getUnlocalizedName()) + "liqueur", typedLiqueur);
            OreDictionary.registerOre("listAllliqueur", typedLiqueur);
            OreDictionary.registerOre("listAllfoods", typedLiqueur);
            if (liqueur instanceof CustomModelMasking)
                FoodCraftReloadedMod.getLoader(LiqueurLoader.class).get().getLiqueurCustomModelMap().put(typedLiqueur, (CustomModelMasking) liqueur);
        }
    });
}
Also used : ItemGeneratedLiqueur(cc.lasmgratel.foodcraftreloaded.minecraft.common.item.food.ItemGeneratedLiqueur) Item(net.minecraft.item.Item) LiqueurTypes(cc.lasmgratel.foodcraftreloaded.minecraft.api.capability.liqueur.LiqueurTypes) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) ItemFood(net.minecraft.item.ItemFood) FoodCraftReloadedMod(cc.lasmgratel.foodcraftreloaded.minecraft.common.FoodCraftReloadedMod) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) LiqueurType(cc.lasmgratel.foodcraftreloaded.minecraft.api.capability.liqueur.LiqueurType) ItemStack(net.minecraft.item.ItemStack) MinecraftForge(net.minecraftforge.common.MinecraftForge) Load(cc.lasmgratel.foodcraftreloaded.minecraft.common.util.loader.annotation.Load) LoaderState(net.minecraftforge.fml.common.LoaderState) Side(net.minecraftforge.fml.relauncher.Side) OreDictionary(net.minecraftforge.oredict.OreDictionary) CustomModelMasking(cc.lasmgratel.foodcraftreloaded.minecraft.client.util.masking.CustomModelMasking) MathHelper(net.minecraft.util.math.MathHelper) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) RegistryEvent(net.minecraftforge.event.RegistryEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) LiqueurLoader(cc.lasmgratel.foodcraftreloaded.minecraft.common.loader.LiqueurLoader) ItemGeneratedLiqueur(cc.lasmgratel.foodcraftreloaded.minecraft.common.item.food.ItemGeneratedLiqueur) CustomModelMasking(cc.lasmgratel.foodcraftreloaded.minecraft.client.util.masking.CustomModelMasking) LiqueurType(cc.lasmgratel.foodcraftreloaded.minecraft.api.capability.liqueur.LiqueurType) ItemStack(net.minecraft.item.ItemStack)

Example 3 with StringUtils.capitalize

use of org.apache.commons.lang3.StringUtils.capitalize in project apps-android-wikipedia by wikimedia.

the class ShareHandler method shareSnippet.

private void shareSnippet(@NonNull CharSequence input) {
    final String selectedText = StringUtil.sanitizeText(input.toString());
    final PageTitle title = fragment.getTitle();
    final String leadImageNameText = fragment.getPage().getPageProperties().getLeadImageName() != null ? fragment.getPage().getPageProperties().getLeadImageName() : "";
    final PageTitle imageTitle = new PageTitle(Namespace.FILE.toLegacyString(), leadImageNameText, title.getWikiSite());
    disposables.add(ServiceFactory.get(title.getWikiSite()).getImageExtMetadata(imageTitle.getPrefixedText()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).map(response -> {
        // noinspection ConstantConditions
        MwQueryPage page = response.query().pages().get(0);
        return page.imageInfo() != null && page.imageInfo().getMetadata() != null ? new ImageLicense(page.imageInfo().getMetadata()) : new ImageLicense();
    }).subscribe(imageLicense -> {
        final Bitmap snippetBitmap = SnippetImage.getSnippetImage(fragment.requireContext(), fragment.getLeadImageBitmap(), title.getDisplayText(), fragment.getPage().isMainPage() ? "" : StringUtils.capitalize(title.getDescription()), selectedText, imageLicense);
        fragment.showBottomSheet(new PreviewDialog(fragment.getContext(), snippetBitmap, title, selectedText, funnel));
    }, caught -> {
        // If we failed to get license info for the lead image, just share the text
        PreviewDialog.shareAsText(fragment.requireContext(), title, selectedText, funnel);
        L.e("Error fetching image license info for " + title.getDisplayText(), caught);
    }));
}
Also used : Context(android.content.Context) ActionMode(android.view.ActionMode) Arrays(java.util.Arrays) NoDimBottomSheetDialog(org.wikipedia.page.NoDimBottomSheetDialog) ImageView(android.widget.ImageView) PageProperties(org.wikipedia.page.PageProperties) NonNull(android.support.annotation.NonNull) StringUtils(org.apache.commons.lang3.StringUtils) ShareUtil(org.wikipedia.util.ShareUtil) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MenuItem(android.view.MenuItem) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Locale(java.util.Locale) WikipediaApp(org.wikipedia.WikipediaApp) StringUtil(org.wikipedia.util.StringUtil) WiktionaryDialog(org.wikipedia.wiktionary.WiktionaryDialog) Menu(android.view.Menu) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) ImageLicense(org.wikipedia.gallery.ImageLicense) ActivityUtil(org.wikipedia.activity.ActivityUtil) ServiceFactory(org.wikipedia.dataclient.ServiceFactory) R(org.wikipedia.R) LayoutInflater(android.view.LayoutInflater) MwQueryPage(org.wikipedia.dataclient.mwapi.MwQueryPage) PageTitle(org.wikipedia.page.PageTitle) CommunicationBridge(org.wikipedia.bridge.CommunicationBridge) Namespace(org.wikipedia.page.Namespace) UriUtil(org.wikipedia.util.UriUtil) Prefs(org.wikipedia.settings.Prefs) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) ShareMode(org.wikipedia.analytics.ShareAFactFunnel.ShareMode) ShareAFactFunnel(org.wikipedia.analytics.ShareAFactFunnel) PageFragment(org.wikipedia.page.PageFragment) Bitmap(android.graphics.Bitmap) Page(org.wikipedia.page.Page) L(org.wikipedia.util.log.L) Nullable(android.support.annotation.Nullable) FeedbackUtil(org.wikipedia.util.FeedbackUtil) ImageLicense(org.wikipedia.gallery.ImageLicense) Bitmap(android.graphics.Bitmap) MwQueryPage(org.wikipedia.dataclient.mwapi.MwQueryPage) PageTitle(org.wikipedia.page.PageTitle)

Example 4 with StringUtils.capitalize

use of org.apache.commons.lang3.StringUtils.capitalize in project oap by oaplatform.

the class UniqueField method check.

@Override
@SuppressWarnings("unchecked")
public void check(T object, Storage<T> storage, Function<T, String> id) throws ConstraintException {
    val idValue = id.apply(object);
    val value = valueFunc.apply(object);
    if (storage.select().filter(obj -> filter.test(object, obj)).anyMatch(itemObject -> equals(value, valueFunc.apply(itemObject)) && !idValue.equals(id.apply(itemObject)))) {
        throw new ConstraintException(StringUtils.capitalize(type) + " '" + value + "' already exists.");
    }
}
Also used : lombok.val(lombok.val) Objects(java.util.Objects) BiPredicate(java.util.function.BiPredicate) List(java.util.List) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function)

Example 5 with StringUtils.capitalize

use of org.apache.commons.lang3.StringUtils.capitalize in project oap by oaplatform.

the class Linker method linkListeners.

@SuppressWarnings("unchecked")
private void linkListeners(Module.Service service, Object instance) {
    service.listen.forEach((listener, reference) -> {
        log.debug("setting " + service.name + " to listen to " + reference + " with listener " + listener);
        String methodName = "add" + StringUtils.capitalize(listener) + "Listener";
        Object linked = kernel.service(linkedServiceName(reference));
        if (linked == null)
            throw new ApplicationException("for " + service.name + " listening object " + reference + " is not found");
        Optionals.fork(Reflect.reflect(linked.getClass()).method(methodName)).ifPresent(m -> m.invoke(linked, instance)).ifAbsentThrow(() -> new ReflectException("listener " + listener + " should have method " + methodName + " in " + reference));
    });
}
Also used : Reflect(oap.reflect.Reflect) LinkedHashMap(java.util.LinkedHashMap) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Optionals(oap.util.Optionals) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) Map(java.util.Map) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) ReflectException(oap.reflect.ReflectException) ReflectException(oap.reflect.ReflectException)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)8 List (java.util.List)5 Collectors (java.util.stream.Collectors)4 java.util (java.util)2 Arrays (java.util.Arrays)2 Slf4j (lombok.extern.slf4j.Slf4j)2 lombok.val (lombok.val)2 Context (android.content.Context)1 Bitmap (android.graphics.Bitmap)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 ActionMode (android.view.ActionMode)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LiqueurType (cc.lasmgratel.foodcraftreloaded.minecraft.api.capability.liqueur.LiqueurType)1 LiqueurTypes (cc.lasmgratel.foodcraftreloaded.minecraft.api.capability.liqueur.LiqueurTypes)1 CustomModelMasking (cc.lasmgratel.foodcraftreloaded.minecraft.client.util.masking.CustomModelMasking)1