text:
/* eslint-disable @typescript-eslint/no-explicit-any */

import { ReactNode, useState } from 'react';
import { Control, FormState, useForm, UseFormSetError } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import {
  Button,
  Dialog,
  DialogActions,
  DialogContent,
  DialogTitle,
} from '@mui/material';
import { AnyObjectSchema } from 'yup';

import ConfirmationDialog from 'lib/components/core/dialogs/ConfirmationDialog';
import ErrorText from 'lib/components/core/ErrorText';
import useTranslation from 'lib/hooks/useTranslation';
import formTranslations from 'lib/translations/form';

type Data = Record<string, any>;

interface Props {
  open: boolean;
  editing: boolean;
  initialValues: Data;
  onClose: () => void;
  onSubmit: (data, setError: UseFormSetError<Data>) => void;
  title: string;
  formName: string;
  validationSchema?: AnyObjectSchema;
  children?: (control: Control, formState: FormState<any>) => ReactNode;
  primaryActionText?: string;
}

const FormDialog = (props: Props): JSX.Element => {
  const {
    open,
    editing,
    initialValues,
    onClose,
    onSubmit,
    title,
    formName,
    validationSchema,
    children,
    primaryActionText,
  } = props;

  const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
  const { t } = useTranslation();
  const { control, handleSubmit, setError, formState } = useForm({
    defaultValues: initialValues,
    resolver: validationSchema && yupResolver(validationSchema),
  });

  const handleCloseDialog = (): void => {
    if (formState.isDirty) {
      setConfirmationDialogOpen(true);
    } else {
      onClose();
    }
  };

  return (
    <>
      <Dialog
        className="top-10"
        disableEnforceFocus
        maxWidth="md"
        onClose={handleCloseDialog}
        open={open}
      >
        <DialogTitle>{title}</DialogTitle>
        <DialogContent>
          <form
            encType="multipart/form-data"
            id={formName}
            noValidate
            onSubmit={handleSubmit((data) => onSubmit(data, setError))}
          >
            <ErrorText errors={formState.errors} />
            {children?.(control, formState)}
          </form>
        </DialogContent>
        <DialogActions>
          <Button
            key="form-dialog-cancel-button"
            className="btn-cancel"
            color="secondary"
            disabled={formState.isSubmitting}
            onClick={handleCloseDialog}
          >
            {t(formTranslations.cancel)}
          </Button>
          <Button
            className="btn-submit"
            color="primary"
            disabled={formState.isSubmitting || !formState.isDirty}
            form={formName}
            id={
              editing
                ? 'form-dialog-update-button'
                : 'form-dialog-submit-button'
            }
            type="submit"
            variant="contained"
          >
            {primaryActionText ??
              (editing
                ? t(formTranslations.update)
                : t(formTranslations.submit))}
          </Button>
        </DialogActions>
      </Dialog>
      <ConfirmationDialog
        confirmDiscard
        onCancel={(): void => setConfirmationDialogOpen(false)}
        onConfirm={(): void => {
          setConfirmationDialogOpen(false);
          onClose();
        }}
        open={confirmationDialogOpen}
      />
    </>
  );
};

export default FormDialog;


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.Framework.Logging.Console;
using PubSub;
using Microsoft.AspNet.WebSockets.Server;

namespace TestMonitorWeb
{
    public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            Configuration = new Configuration()
                .AddJsonFile("config.json")
                .AddEnvironmentVariables();
        }

        public IConfiguration Configuration { get; set; }

        // This method gets called by the runtime.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
            services.AddMvc();

            // add publisher
            services.AddPublisher();
        }

        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
        {
            // Configure the HTTP request pipeline.

            // Add the console logger.
            loggerfactory.AddConsole();

            // Add the following to the request pipeline only in development environment.
            if (env.IsEnvironment("Development"))
            {
                app.UseBrowserLink();
                app.UseErrorPage(ErrorPageOptions.ShowAll);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // send the request to the following path or controller action.
                app.UseErrorHandler("/Home/Error");
            }

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            app.UseWebSockets(new WebSocketOptions { ReplaceFeature = true });
            //app.Map("/ws", m =>
            //{
            //    m.UseWebSockets(new WebSocketOptions { ReplaceFeature = true });
            //});

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
package com.mossle.pim.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mossle.api.auth.CurrentUserHolder;
import com.mossle.api.store.StoreDTO;
import com.mossle.api.tenant.TenantHolder;

import com.mossle.client.store.StoreClient;

import com.mossle.core.export.Exportor;
import com.mossle.core.export.TableModel;
import com.mossle.core.mapper.BeanMapper;
import com.mossle.core.mapper.JsonMapper;
import com.mossle.core.page.Page;
import com.mossle.core.query.PropertyFilter;
import com.mossle.core.spring.MessageHelper;
import com.mossle.core.store.MultipartFileDataSource;
import com.mossle.core.util.ServletUtils;

import com.mossle.pim.persistence.domain.WorkReportAttachment;
import com.mossle.pim.persistence.domain.WorkReportInfo;
import com.mossle.pim.persistence.manager.WorkReportAttachmentManager;
import com.mossle.pim.persistence.manager.WorkReportInfoManager;

import org.apache.commons.io.IOUtils;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
@RequestMapping("pim")
public class WorkReportInfoController {
    private WorkReportInfoManager workReportInfoManager;
    private WorkReportAttachmentManager workReportAttachmentManager;
    private MessageHelper messageHelper;
    private Exportor exportor;
    private BeanMapper beanMapper = new BeanMapper();
    private JsonMapper jsonMapper = new JsonMapper();
    private CurrentUserHolder currentUserHolder;
    private TenantHolder tenantHolder;
    private StoreClient storeClient;

    @RequestMapping("work-report-info-list")
    public String list(@ModelAttribute Page page,
            @RequestParam Map<String, Object> parameterMap, Model model) {
        String userId = currentUserHolder.getUserId();
        List<PropertyFilter> propertyFilters = PropertyFilter
                .buildFromMap(parameterMap);
        propertyFilters.add(new PropertyFilter("EQS_userId", userId));
        page = workReportInfoManager.pagedQuery(page, propertyFilters);
        model.addAttribute("page", page);

        return "pim/work-report-info-list";
    }

    @RequestMapping("work-report-info-input")
    public String input(@RequestParam(value = "id", required = false) Long id,
            Model model) {
        if (id != null) {
            WorkReportInfo workReportInfo = workReportInfoManager.get(id);
            model.addAttribute("model", workReportInfo);
        }

        return "pim/work-report-info-input";
    }

    @RequestMapping("work-report-info-save")
    public String save(
            @ModelAttribute WorkReportInfo workReportInfo,
            @RequestParam(value = "attachmentIds", required = false) List<Long> attachmentIds,
            RedirectAttributes redirectAttributes) {
        String userId = currentUserHolder.getUserId();
        String tenantId = tenantHolder.getTenantId();
        Long id = workReportInfo.getId();
        WorkReportInfo dest = null;

        if (id != null) {
            dest = workReportInfoManager.get(id);
            beanMapper.copy(workReportInfo, dest);
        } else {
            dest = workReportInfo;
            dest.setUserId(userId);
            dest.setCreateTime(new Date());
        }

        workReportInfoManager.save(dest);
        dest = workReportInfoManager.get(dest.getId());

        List<Long> requestIds = null;

        if (attachmentIds == null) {
            requestIds = new ArrayList<Long>();
        } else {
            requestIds = attachmentIds;
        }

        List<Long> existIds = new ArrayList<Long>();

        for (WorkReportAttachment workReportAttachment : workReportAttachmentManager
                .findBy("workReportInfo", dest)) {
            existIds.add(workReportAttachment.getId());
        }

        List<Long> inserted = new ArrayList<Long>();
        List<Long> removed = new ArrayList<Long>();

        for (Long theId : requestIds) {
            if (!existIds.contains(theId)) {
                inserted.add(theId);
            }
        }

        for (Long theId : existIds) {
            if (!requestIds.contains(theId)) {
                removed.add(theId);
            }
        }

        for (Long theId : removed) {
            WorkReportAttachment workReportAttachment = workReportAttachmentManager
                    .get(theId);
            workReportAttachment.setWorkReportInfo(null);
            dest.getWorkReportAttachments().remove(workReportAttachment);
            workReportAttachmentManager.remove(workReportAttachment);
        }

        for (Long theId : inserted) {
            WorkReportAttachment workReportAttachment = workReportAttachmentManager
                    .get(theId);
            workReportAttachment.setWorkReportInfo(dest);
            workReportAttachmentManager.save(workReportAttachment);
        }

        messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
                "保存成功");

        return "redirect:/pim/work-report-info-list.do";
    }

    @RequestMapping("work-report-info-remove")
    public String remove(@RequestParam("selectedItem") List<Long> selectedItem,
            RedirectAttributes redirectAttributes) {
        List<WorkReportInfo> workReportInfos = workReportInfoManager
                .findByIds(selectedItem);
        workReportInfoManager.removeAll(workReportInfos);
        messageHelper.addFlashMessage(redirectAttributes,
                "core.success.delete", "删除成功");

        return "redirect:/pim/work-report-info-list.do";
    }

    @RequestMapping("work-report-info-export")
    public void export(@ModelAttribute Page page,
            @RequestParam Map<String, Object> parameterMap,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String userId = currentUserHolder.getUserId();
        List<PropertyFilter> propertyFilters = PropertyFilter
                .buildFromMap(parameterMap);
        propertyFilters.add(new PropertyFilter("EQS_userId", userId));
        page = workReportInfoManager.pagedQuery(page, propertyFilters);

        List<WorkReportInfo> workReportInfos = (List<WorkReportInfo>) page
                .getResult();

        TableModel tableModel = new TableModel();
        tableModel.setName("pim info");
        tableModel.addHeaders("id", "name");
        tableModel.setData(workReportInfos);
        exportor.export(request, response, tableModel);
    }

    @RequestMapping("work-report-info-download")
    @ResponseBody
    public String download(@RequestParam("id") Long id) throws Exception {
        List<WorkReportAttachment> workReportAttachments = workReportAttachmentManager
                .findBy("workReportInfo.id", id);

        Map<String, Object> data = new HashMap<String, Object>();
        List<Map<String, Object>> files = new ArrayList<Map<String, Object>>();
        data.put("files", files);

        for (WorkReportAttachment workReportAttachment : workReportAttachments) {
            Map<String, Object> map = new HashMap<String, Object>();
            files.add(map);
            map.put("name", workReportAttachment.getName());
            map.put("url", "work-report-info-image.do?id="
                    + workReportAttachment.getId());

            // map.put("thumbnailUrl", "./rs/cms/image?key=" + storeDto.getKey());
        }

        return jsonMapper.toJson(data);
    }

    @RequestMapping("work-report-info-upload")
    @ResponseBody
    public String upload(@RequestParam("id") Long id,
            @RequestParam("files[]") MultipartFile attachment) throws Exception {
        String tenantId = tenantHolder.getTenantId();
        StoreDTO storeDto = this.storeClient.saveStore("workReport/attachment",
                new MultipartFileDataSource(attachment), tenantId);
        WorkReportInfo workReportInfo = null;

        if (id != null) {
            workReportInfo = workReportInfoManager.get(id);
        }

        WorkReportAttachment workReportAttachment = new WorkReportAttachment();
        workReportAttachment.setWorkReportInfo(workReportInfo);
        workReportAttachment.setName(attachment.getOriginalFilename());
        workReportAttachment.setRef(storeDto.getKey());
        workReportAttachmentManager.save(workReportAttachment);

        Map<String, Object> data = new HashMap<String, Object>();
        List<Map<String, Object>> files = new ArrayList<Map<String, Object>>();
        data.put("files", files);

        Map<String, Object> map = new HashMap<String, Object>();
        files.add(map);
        map.put("id", workReportAttachment.getId());
        map.put("name", attachment.getOriginalFilename());
        // map.put("url", "../rs/cms/image?key=" + storeDto.getKey());
        map.put("url",
                "work-report-info-image.do?id=" + workReportAttachment.getId());

        // map.put("thumbnailUrl", "./rs/cms/image?key=" + storeDto.getKey());
        return jsonMapper.toJson(data);
    }

    @RequestMapping("work-report-info-attachment")
    public void attachment(@RequestParam("id") Long id,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String tenantId = tenantHolder.getTenantId();
        WorkReportAttachment workReportAttachment = workReportAttachmentManager
                .get(id);
        StoreDTO storeDto = this.storeClient.getStore("workReport/attachment",
                workReportAttachment.getRef(), tenantId);
        ServletUtils.setFileDownloadHeader(request, response,
                workReportAttachment.getName());
        IOUtils.copy(storeDto.getDataSource().getInputStream(),
                response.getOutputStream());
    }

    // ~ ======================================================================
    @Resource
    public void setWorkReportInfoManager(
            WorkReportInfoManager workReportInfoManager) {
        this.workReportInfoManager = workReportInfoManager;
    }

    @Resource
    public void setWorkReportAttachmentManager(
            WorkReportAttachmentManager workReportAttachmentManager) {
        this.workReportAttachmentManager = workReportAttachmentManager;
    }

    @Resource
    public void setMessageHelper(MessageHelper messageHelper) {
        this.messageHelper = messageHelper;
    }

    @Resource
    public void setExportor(Exportor exportor) {
        this.exportor = exportor;
    }

    @Resource
    public void setCurrentUserHolder(CurrentUserHolder currentUserHolder) {
        this.currentUserHolder = currentUserHolder;
    }

    @Resource
    public void setTenantHolder(TenantHolder tenantHolder) {
        this.tenantHolder = tenantHolder;
    }

    @Resource
    public void setStoreClient(StoreClient storeClient) {
        this.storeClient = storeClient;
    }
}


text:
require "apis/version"
require "apis/apis"

module Apis

end


text:
package symbol

var pathToExceptions = map[string]map[string]bool{
	// RawMessage.MarshalJSON was introduced in go1, but in go1.8 the receiver
	// was changed from a point (*RawMessage) to a value (RawMessage).
	// See https://golang.org/doc/go1.8#encoding_json. This resulted in
	// golang.org/pkg/encoding/json to show that this symbol was introduced in
	// go1.8. We want to show go1.1 on pkg.go.dev.
	"encoding/json": {
		"RawMessage.MarshalJSON": true,
	},
	// Package syscall doesn't follow the Go 1 compatibility promise like all
	// other normal packages in the standard library. See
	// https://golang.org/s/go1.4-syscall and its API varies significantly
	// between different GOOS/GOARCH pairs.
	"syscall": {
		// RawSockaddrInet6 is listed in api/go1.txt as:
		//     pkg syscall (darwin-386), type RawSockaddrInet6 struct
		// It is listed in api/go1.1.txt as:
		//     pkg syscall type RawSockaddrInet6 struct
		// As a result, golang.org/pkg/syscall only recognizes its existence as
		// of go1.1.
		// The same is true for RawSockaddrUnix, TimespecToNsec, and
		// NsecToTimespec.
		"RawSockaddrInet6":          true,
		"RawSockaddrInet6.Addr":     true,
		"RawSockaddrInet6.Flowinfo": true,
		"RawSockaddrInet6.Port":     true,
		"RawSockaddrInet6.Scope_id": true,
		"RawSockaddrUnix":           true,
		"TimespecToNsec":            true,
		"NsecToTimespec":            true,
	},
}

// pathToEmbeddedMethods contains methods that appear on a struct, because it
// was added to an embedded struct. pkgsite does not currently support embedding,
// so these methods are skipped by when comparing the stdlib API for now.
var pathToEmbeddedMethods = map[string]map[string]string{
	"archive/zip": {
		// https://pkg.go.dev/archive/zip@go1.6#ReadCloser
		// Embedded https://pkg.go.dev/archive/zip#Reader.RegisterDecompressor
		"ReadCloser.RegisterDecompressor": "v1.6.0",
		// https://pkg.go.dev/archive/zip@go1.16#ReadCloser
		// method Open was added to embedded struct in go1.16
		// https://pkg.go.dev/archive/zip@go1.16#Reader.Open
		// Release notes: https://golang.org/doc/go1.16#archive/zip
		"ReadCloser.Open": "v1.16.0",
	},
	"bufio": {
		// https://pkg.go.dev/bufio@go1.1#ReadWriter
		// Embedded https://pkg.go.dev/bufio#Writer.ReadFrom
		"ReadWriter.ReadFrom": "v1.1.0",
		// https://pkg.go.dev/bufio@go1.1#ReadWriter
		// Embedded https://pkg.go.dev/bufio#Reader.WriteTo
		"ReadWriter.WriteTo": "v1.1.0",
		// https://pkg.go.dev/bufio@go1.5#ReadWriter
		// Embedded https://pkg.go.dev/bufio#Reader.Discard
		"ReadWriter.Discard": "v1.5.0",
	},
	"crypto/rsa": {
		// https://pkg.go.dev/crypto/rsa@go1.11#PrivateKey
		// Embedded https://pkg.go.dev/crypto/rsa#PublicKey.Size
		"PrivateKey.Size": "v1.11.0",
	},
	"debug/dwarf": {
		// https://pkg.go.dev/debug/dwarf@go1.13#UnsupportedType
		// Embedded https://pkg.go.dev/debug/dwarf#CommonType.Common
		"UnsupportedType.Common": "v1.13.0",
		// https://pkg.go.dev/debug/dwarf@go1.13#UnsupportedType
		// Embedded https://pkg.go.dev/debug/dwarf#CommonType.Size
		"UnsupportedType.Size": "v1.13.0",
		// https://pkg.go.dev/debug/dwarf@go1.4#UnspecifiedType
		// Embedded https://pkg.go.dev/debug/dwarf#CommonType.Common
		"UnspecifiedType.Common": "v1.4.0",
		// https://pkg.go.dev/debug/dwarf@go1.4#UnspecifiedType
		// Embedded https://pkg.go.dev/debug/dwarf#CommonType.Size
		"UnspecifiedType.Size": "v1.4.0",
		// https://pkg.go.dev/debug/dwarf@go1.4#UnspecifiedType
		// Embedded https://pkg.go.dev/debug/dwarf#BasicType.Basic
		"UnspecifiedType.Basic": "v1.4.0",
		// https://pkg.go.dev/debug/dwarf@go1.4#UnspecifiedType
		// Embedded https://pkg.go.dev/debug/dwarf#BasicType.String
		"UnspecifiedType.String": "v1.4.0",
	},
	"debug/macho": {
		// https://pkg.go.dev/debug/macho@go1.3#FatArch
		// Embedded https://pkg.go.dev/debug/macho#File.Close
		"FatArch.Close": "v1.3.0",
		// https://pkg.go.dev/debug/macho@go1.3#FatArch
		// Embedded https://pkg.go.dev/debug/macho#File.DWARF
		"FatArch.DWARF": "v1.3.0",
		// https://pkg.go.dev/debug/macho@go1.3#FatArch
		// Embedded https://pkg.go.dev/debug/macho#File.ImportedLibraries
		"FatArch.ImportedLibraries": "v1.3.0",
		// https://pkg.go.dev/debug/macho@go1.3#FatArch
		// Embedded https://pkg.go.dev/debug/macho#File.ImportedSymbols
		"FatArch.ImportedSymbols": "v1.3.0",
		// https://pkg.go.dev/debug/macho@go1.3#FatArch
		// Embedded https://pkg.go.dev/debug/macho#File.Section
		"FatArch.Section": "v1.3.0",
		// https://pkg.go.dev/debug/macho@go1.3#FatArch
		// Embedded https://pkg.go.dev/debug/macho#File.Segment
		"FatArch.Segment": "v1.3.0",
		// https://pkg.go.dev/debug/macho@go1.10#Rpath
		// Embeddded https://pkg.go.dev/debug/macho#LoadBytes.Raw
		"Rpath.Raw": "v1.10.0",
	},
	"debug/plan9obj": {
		// https://pkg.go.dev/debug/plan9obj@go1.3#Section
		// Embedded https://pkg.go.dev/io#ReaderAt.ReadAt
		"Section.ReadAt": "v1.3.0",
	},
	"go/types": {
		// https://pkg.go.dev/go/types@go1.5#Checker
		// Embedded https://pkg.go.dev/go/types#Info.ObjectOf
		"Checker.ObjectOf": "v1.5.0",
		// https://pkg.go.dev/go/types@go1.5#Checker
		// Embedded https://pkg.go.dev/go/types@go1.5#Info.TypeOf
		"Checker.TypeOf": "v1.5.0",
	},
	"image": {
		// https://pkg.go.dev/image@go1.6#NYCbCrA
		// Embedded https://pkg.go.dev/image#YCbCr.Bounds
		"NYCbCrA.Bounds": "v1.6.0",
		// https://pkg.go.dev/image@go1.6#NYCbCrA
		// Embedded https://pkg.go.dev/image@go1.6#YCbCr.COffset
		"NYCbCrA.COffset": "v1.6.0",
		// https://pkg.go.dev/image@go1.6#NYCbCrA
		// Embedded https://pkg.go.dev/image@go1.6#YCbCr.YCbCrAt
		"NYCbCrA.YCbCrAt": "v1.6.0",
		// https://pkg.go.dev/image@go1.6#NYCbCrA
		// Embedded https://pkg.go.dev/image@go1.6#YCbCr.YOffset
		"NYCbCrA.YOffset": "v1.6.0",
	},
	"os/exec": {
		// https://pkg.go.dev/os/exec@go1.12#ExitError
		// Embedded https://pkg.go.dev/os#ProcessState.ExitCode
		"ExitError.ExitCode": "v1.12.0",
	},
	"runtime": {
		// https://pkg.go.dev/runtime@go1.1#BlockProfileRecord
		// Embedded https://pkg.go.dev/runtime#StackRecord.Stack
		"BlockProfileRecord.Stack": "v1.1.0",
	},
	"text/template": {
		// https://pkg.go.dev/text/template@go1.2#Template
		// Embedded https://pkg.go.dev/text/template/parse#Tree.ErrorContext
		"Template.ErrorContext": "v1.1.0",
		// https://pkg.go.dev/text/template@go1.2#Template
		// Embedded https://pkg.go.dev/text/template/parse#Tree.Copy
		"Template.Copy": "v1.2.0",
	},
	"text/template/parse": {
		// https://pkg.go.dev/text/template/parse@go1.1#ActionNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"ActionNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#BoolNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"BoolNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#Branch
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"BranchNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#ChainNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"ChainNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#ChainNode
		// Embedded https://pkg.go.dev/text/template/parse@go1.1#NodeType.Type
		"ChainNode.Type": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#CommandNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"CommandNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.16#CommentNode
		// Embedded https://pkg.go.dev/text/template/parse@go1.16#Pos.Position
		// Release notes: https://golang.org/doc/go1.16#text/template/parse
		"CommentNode.Position": "v1.16.0",
		// https://pkg.go.dev/text/template/parse@go1.16#CommentNode
		// Embedded https://pkg.go.dev/text/template/parse@go1.16#NodeType.Type
		// Release notes: https://golang.org/doc/go1.16#text/template/parse
		"CommentNode.Type": "v1.16.0",
		// https://pkg.go.dev/text/template/parse@go1.1#DotNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"DotNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#FieldNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"FieldNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#IdentifierNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"IdentifierNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#IfNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"IfNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#ListNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"ListNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#NilNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"NilNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#NumberNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"NumberNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#PipeNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"PipeNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#RangeNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"RangeNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#StringNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"StringNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#TemplateNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"TemplateNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#TextNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"TextNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#VariableNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"VariableNode.Position": "v1.1.0",
		// https://pkg.go.dev/text/template/parse@go1.1#WithNode
		// Embedded https://pkg.go.dev/text/template/parse#Pos.Position
		"WithNode.Position": "v1.1.0",
	},
}


text:
package com.outerspacecat.util;

import javax.annotation.concurrent.ThreadSafe;

/**
 * Defines methods for an object that tracks its own usage and availability.
 * Used in combination with {@link ResourcePool}.
 *
 * @author Caleb Richardson
 * @param T the type of the resource
 */
@ThreadSafe
public interface Resource<T extends Resource<T>>
{
  /**
   * Returns the current usage of this resource.
   *
   * @return the current usage of this resource. >= 0.
   */
  int getUsage ();

  /**
   * Returns the usage ratio of this resource relative to other resources.
   *
   * @return the usage ratio of this resource relative to other resources. >= 0.
   */
  int getRatio ();

  /**
   * Returns whether or not this resource is available.
   *
   * @return whether or not this resource is available
   */
  boolean isUp ();
}


text:
using NSubstitute.Core;
using NSubstitute.Routing;
using NSubstitute.Specs.Infrastructure;
using NUnit.Framework;

namespace NSubstitute.Specs.Routing
{
    public class RouteSpecs
    {
        public class When_handling_a_call : ConcernFor<Route>
        {
            private object _result;
            private ICall _call;
            private ICallHandler _firstHandler;
            private ICallHandler _secondHandler;
            private readonly object _valueToReturn = new object();
            private ICallHandler[] _handlers;

            [Test]
            public void Should_return_result_from_when_a_handler_provides_a_result()
            {
                Assert.That(_result, Is.SameAs(_valueToReturn));
            }

            public override void Because()
            {
                _result = sut.Handle(_call);
            }

            public override void Context()
            {
                _call = mock<ICall>();
                _firstHandler = mock<ICallHandler>();
                _firstHandler.stub(x => x.Handle(_call)).Return(RouteAction.Continue());
                _secondHandler = mock<ICallHandler>();
                _secondHandler.stub(x => x.Handle(_call)).Return(RouteAction.Return(_valueToReturn));

                _handlers = new[] { _firstHandler, _secondHandler };
            }

            public override Route CreateSubjectUnderTest()
            {
                return new Route(_handlers);
            }
        }
    }
}


text:
using System.Collections.Generic;
using System;

namespace GLSLSyntaxAST.Preprocessor
{
	internal class AtomLookup
	{
		private readonly Dictionary<string, int> mAtomMap;
		private readonly Dictionary<int, string> mStringMap;
		internal AtomLookup ()
		{
			mAtomMap = new Dictionary<string, int> ();
			mStringMap = new Dictionary<int, string> ();
			NextAtom = (int) CppEnums.FIRST_USER_TOKEN_SY;
		}

		/// <summary>
		/// Add forced mapping of string to atom.
		/// </summary>
		/// <returns>The fixed atom.</returns>
		/// <param name="s">S.</param>
		/// <param name="atom">Atom.</param>
		internal int AddFixedAtom(string s, int atom)
		{
			mAtomMap.Add (s, atom);
			mStringMap.Add (atom, s);
			return atom;
		}

		internal int NextAtom { get; private set; }

		/// <summary>
		/// Map a new or existing string to an atom, inventing a new atom if necessary.
		/// </summary>
		/// <returns>The up add string.</returns>
		/// <param name="s">S.</param>
		internal int LookUpAddString(string s)
		{
			int result;
			if (mAtomMap.TryGetValue (s, out result))
			{
				return result;
			}
			else
			{
				return AddFixedAtom (s, NextAtom++);
			}
		}

		internal int GetAtomKey(string key)
		{
			return mAtomMap [key];
		}

		/// <summary>
		/// Map an already created atom to its string.
		/// </summary>
		/// <returns>The atom string.</returns>
		/// <param name="atom">Atom.</param>
		internal string GetAtomString(int atom)
		{
			if (atom == 0)
				return "<null atom>";
			if (atom < 0)
				return "<EOF>";

			string result;
			if (mStringMap.TryGetValue (atom, out result))
			{
				return result;
			}
			else
			{
				return "<invalid atom>";
			}
		}

		/// <summary>
		/// Add a token to the end of a list for later playback.
		/// </summary>
		/// <param name="pTok">P tok.</param>
		/// <param name="token">Token.</param>
		/// <param name="ppToken">Pp token.</param>
		internal void RecordToken(TokenStream pTok, int token, PreprocessorToken ppToken)
		{
			if (token > 256)
				pTok.lAddByte( (UInt16)((token & 0x7f) + 0x80));
			else
				pTok.lAddByte( (UInt16)(token & 0x7f));

			switch (token) {
			case (int) CppEnums.IDENTIFIER:
			case (int) CppEnums.STRCONSTANT:
				string s = GetAtomString(ppToken.atom);
				foreach(var letter in s)
				{
					pTok.lAddByte((UInt16) letter);
				}
				pTok.lAddByte(0);
				break;
			case (int) CppEnums.INTCONSTANT:
			case (int) CppEnums.UINTCONSTANT:
			case (int) CppEnums.FLOATCONSTANT:
			case (int) CppEnums.DOUBLECONSTANT:
				string str = ppToken.name;
				foreach (var letter in str)
				{
					pTok.lAddByte((UInt16) letter);
				}
				pTok.lAddByte(0);
				break;
			default:
				break;
			}
		}
	}
}


text:
package br.com.find.cep.resource;

import br.com.find.cep.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.UUID;

/**
 * The type Address resource.
 * @author Felipe Adorno (felipeadsc@gmail.com)
 */
@RestController
@RequestMapping(value = "/address")
@Validated
public class AddressResource {

    @Autowired
    private AddressService addressService;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpEntity<AddressRequest> getAddressById(@PathVariable String id) {
        AddressRequest addressRequest = addressService.findAddressById(id);
        return new ResponseEntity<>(addressRequest, HttpStatus.OK);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpEntity deleteAddressById(@PathVariable String id) {
        addressService.removeAddressById(id);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpEntity<AddressRequest> saveAddress(@Valid @RequestBody AddressRequest addressRequest) {
        addressRequest.setId(UUID.randomUUID().toString());
        addressService.saveAddress(addressRequest);
        return new ResponseEntity<>(addressRequest, HttpStatus.CREATED);
    }

    @RequestMapping(method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpEntity<AddressRequest> editAddress(@Valid @RequestBody AddressRequest addressRequest) {
        addressService.saveAddress(addressRequest);
        return new ResponseEntity<>(addressRequest, HttpStatus.OK);
    }

}


text:
BSLS_IDENT_RCSID(bdlt_datetimeinterval_cpp,"$Id$ $CSID$")

#include <bdlb_bitutil.h>

#include <bslim_printer.h>

#include <bslmf_assert.h>

#include <bsls_libraryfeatures.h>
#include <bsls_platform.h>

#include <bsl_ostream.h>

#include <bsl_cmath.h>     // 'modf, 'fabs', 'isinf', 'isnan'
#include <bsl_cstdio.h>    // 'sprintf'

namespace {
namespace u {

using namespace BloombergLP;

typedef bsls::Types::Int64  Int64;
typedef bsls::Types::Uint64 Uint64;

typedef bdlt::TimeUnitRatio TimeUnitRatio;

// Assert fundamental assumptions made in the implementation.

BSLMF_ASSERT(-3 / 2 == -1);
BSLMF_ASSERT(-5 % 4 == -1);

const Int64 k_MAX_INT64       = static_cast<bsls::Types::Int64>(
                                                 ~static_cast<Uint64>(0) >> 1);
const Int64 k_MIN_INT64       = ~k_MAX_INT64;

const Int64 k_MAX_INT         = static_cast<Int64>(
                                               ~static_cast<unsigned>(0) >> 1);
const Int64 k_MIN_INT         = ~k_MAX_INT;

const Int64 k_HOURS_CEILING   = (k_MAX_INT + 1) * TimeUnitRatio::k_H_PER_D - 1;
const Int64 k_HOURS_FLOOR     = (k_MIN_INT - 1) * TimeUnitRatio::k_H_PER_D + 1;
const Int64 k_MINUTES_CEILING = (k_MAX_INT + 1) * TimeUnitRatio::k_M_PER_D - 1;
const Int64 k_MINUTES_FLOOR   = (k_MIN_INT - 1) * TimeUnitRatio::k_M_PER_D + 1;
const Int64 k_SECONDS_CEILING = (k_MAX_INT + 1) * TimeUnitRatio::k_S_PER_D - 1;
const Int64 k_SECONDS_FLOOR   = (k_MIN_INT - 1) * TimeUnitRatio::k_S_PER_D + 1;
const Int64 k_MILLISECONDS_CEILING
                              = (k_MAX_INT + 1) * TimeUnitRatio::k_MS_PER_D -1;
const Int64 k_MILLISECONDS_FLOOR
                              = (k_MIN_INT - 1) * TimeUnitRatio::k_MS_PER_D +1;

const double maxInt64AsDouble = static_cast<double>(k_MAX_INT64);
const double minInt64AsDouble = static_cast<double>(k_MIN_INT64);

// HELPER FUNCTIONS
int printToBufferFormatted(char       *result,
                           int         numBytes,
                           const char *spec,
                           int         day,
                           int         hour,
                           int         minute,
                           int         second,
                           int         microsecond,
                           int         fractionalSecondPrecision)
{
#if defined(BSLS_LIBRARYFEATURES_HAS_C99_SNPRINTF)
    return 0 == fractionalSecondPrecision
           ? bsl::snprintf(result,
                           numBytes,
                           spec,
                           day,
                           hour,
                           minute,
                           second)
           : bsl::snprintf(result,
                           numBytes,
                           spec,
                           day,
                           hour,
                           minute,
                           second,
                           microsecond);

#elif defined(BSLS_PLATFORM_CMP_MSVC)
    // Windows uses a different variant of snprintf that does not necessarily
    // null-terminate and returns -1 (or 'numBytes') on overflow.

    int rc;

    if (0 == fractionalSecondPrecision) {
        rc = _snprintf(result,
                       numBytes,
                       spec,
                       day,
                       hour,
                       minute,
                       second);
    }
    else {
        rc = _snprintf(result,
                       numBytes,
                       spec,
                       day,
                       hour,
                       minute,
                       second,
                       microsecond);
    }

    if (0 > rc || rc == numBytes) {
        if (numBytes > 0) {
            result[numBytes - 1] = '\0';  // Make sure to null-terminate on
                                          // overflow.
        }

        // Need to determine the length that would have been printed without
        // overflow.

        if (0 == fractionalSecondPrecision) {
            //   '_' hh: mm: ss
            rc =  1 + 3 + 3 + 2;
        }
        else {
            //   '_' hh: mm: ss. mmm uuu
            rc =  1 + 3 + 3 + 3 + fractionalSecondPrecision;
        }

        if (-10 < day && 10 > day) {
            rc += 1;
        }
        else if (-100 < day && 100 > day) {
            rc += 2;
        }
        else if (-1000 < day && 1000 > day) {
            rc += 3;
        }
        else if (-10000 < day && 10000 > day) {
            rc += 4;
        }
        else if (-100000 < day && 100000 > day) {
            rc += 5;
        }
        else if (-1000000 < day && 1000000 > day) {
            rc += 6;
        }
        else if (-10000000 < day && 10000000 > day) {
            rc += 7;
        }
        else if (-100000000 < day && 100000000 > day) {
            rc += 8;
        }
        else if (-1000000000 < day && 1000000000 > day) {
            rc += 9;
        }
        else {
            rc += 10;
        }
    }

    return rc;
#else
# error THIS CONFIGURATION DOES NOT SUPPORT 'snprintf'
#endif
}

#ifdef BSLS_LIBRARYFEATURES_HAS_C99_FP_CLASSIFY
# define U_IS_INF(x)    bsl::isinf(x)
# define U_IS_NAN(x)    bsl::isnan(x)
#else
# define U_IS_INF(x)    false
# define U_IS_NAN(x)    false
#endif

}  // close namespace u
}  // close unnamed namespace

namespace BloombergLP {
namespace bdlt {

                          // ----------------------
                          // class DatetimeInterval
                          // ----------------------

// PRIVATE MANIPULATORS
void DatetimeInterval::assign(bsls::Types::Int64 days,
                              bsls::Types::Int64 microseconds)
{
    const Int64 micDays = microseconds / TimeUnitRatio::k_US_PER_D;

    BSLS_ASSERT(!(days > 0 && micDays > 0) || micDays <= u::k_MAX_INT - days);
    BSLS_ASSERT(!(days < 0 && micDays < 0) || u::k_MIN_INT - days <= micDays);

    days         += micDays;
    microseconds %= TimeUnitRatio::k_US_PER_D;

    if (days > 0 && microseconds < 0) {
        --days;
        microseconds += TimeUnitRatio::k_US_PER_D;
    }
    else if (days < 0 && microseconds > 0) {
        ++days;
        microseconds -= TimeUnitRatio::k_US_PER_D;
    }

    BSLS_ASSERT(days <= u::k_MAX_INT);
    BSLS_ASSERT(days >= u::k_MIN_INT);

    d_days         = static_cast<int>(days);
    d_microseconds = microseconds;
}

int DatetimeInterval::assignIfValid(bsls::Types::Int64 days,
                                    bsls::Types::Int64 microseconds)
{
    const Int64 micDays = microseconds / TimeUnitRatio::k_US_PER_D;

    if   ((days > 0 && micDays > 0 && u::k_MAX_INT - days < micDays)
       || (days < 0 && micDays < 0 && micDays < u::k_MIN_INT - days)) {
        return -1;                                                    // RETURN
    }

    days         += micDays;
    microseconds %= TimeUnitRatio::k_US_PER_D;

    if (days > 0 && microseconds < 0) {
        --days;
        microseconds += TimeUnitRatio::k_US_PER_D;
    }
    else if (days < 0 && microseconds > 0) {
        ++days;
        microseconds -= TimeUnitRatio::k_US_PER_D;
    }

    if   (days < u::k_MIN_INT || u::k_MAX_INT < days) {
        return -1;                                                    // RETURN
    }

    d_days         = static_cast<int>(days);
    d_microseconds = microseconds;

    return 0;
}

// CLASS METHODS
bool DatetimeInterval::isValid(int                days,
                               bsls::Types::Int64 hours,
                               bsls::Types::Int64 minutes,
                               bsls::Types::Int64 seconds,
                               bsls::Types::Int64 milliseconds,
                               bsls::Types::Int64 microseconds)
{
    if   (u::k_HOURS_CEILING        < hours
       || u::k_MINUTES_CEILING      < minutes
       || u::k_SECONDS_CEILING      < seconds
       || u::k_MILLISECONDS_CEILING < milliseconds
       || u::k_HOURS_FLOOR          > hours
       || u::k_MINUTES_FLOOR        > minutes
       || u::k_SECONDS_FLOOR        > seconds
       || u::k_MILLISECONDS_FLOOR   > milliseconds) {
        return false;                                                 // RETURN
    }

    bsls::Types::Int64 d = static_cast<bsls::Types::Int64>(days)
                         + hours        / TimeUnitRatio::k_H_PER_D
                         + minutes      / TimeUnitRatio::k_M_PER_D
                         + seconds      / TimeUnitRatio::k_S_PER_D
                         + milliseconds / TimeUnitRatio::k_MS_PER_D
                         + microseconds / TimeUnitRatio::k_US_PER_D;

    hours        %= TimeUnitRatio::k_H_PER_D;
    minutes      %= TimeUnitRatio::k_M_PER_D;
    seconds      %= TimeUnitRatio::k_S_PER_D;
    milliseconds %= TimeUnitRatio::k_MS_PER_D;
    microseconds %= TimeUnitRatio::k_US_PER_D;

    bsls::Types::Int64 us = hours        * TimeUnitRatio::k_US_PER_H
                          + minutes      * TimeUnitRatio::k_US_PER_M
                          + seconds      * TimeUnitRatio::k_US_PER_S
                          + milliseconds * TimeUnitRatio::k_US_PER_MS
                          + microseconds;

    d += us / TimeUnitRatio::k_US_PER_D;

    if   (d < u::k_MIN_INT || u::k_MAX_INT < d) {
        return false;                                                 // RETURN
    }

    return true;
}

// MANIPULATORS
void DatetimeInterval::setInterval(int                days,
                                   bsls::Types::Int64 hours,
                                   bsls::Types::Int64 minutes,
                                   bsls::Types::Int64 seconds,
                                   bsls::Types::Int64 milliseconds,
                                   bsls::Types::Int64 microseconds)
{
    bsls::Types::Int64 d = static_cast<bsls::Types::Int64>(days)
                         + hours        / TimeUnitRatio::k_H_PER_D
                         + minutes      / TimeUnitRatio::k_M_PER_D
                         + seconds      / TimeUnitRatio::k_S_PER_D
                         + milliseconds / TimeUnitRatio::k_MS_PER_D
                         + microseconds / TimeUnitRatio::k_US_PER_D;

    hours        %= TimeUnitRatio::k_H_PER_D;
    minutes      %= TimeUnitRatio::k_M_PER_D;
    seconds      %= TimeUnitRatio::k_S_PER_D;
    milliseconds %= TimeUnitRatio::k_MS_PER_D;
    microseconds %= TimeUnitRatio::k_US_PER_D;

    bsls::Types::Int64 us = hours        * TimeUnitRatio::k_US_PER_H
                          + minutes      * TimeUnitRatio::k_US_PER_M
                          + seconds      * TimeUnitRatio::k_US_PER_S
                          + milliseconds * TimeUnitRatio::k_US_PER_MS
                          + microseconds;

    assign(d, us);
}

int DatetimeInterval::setIntervalIfValid(int                days,
                                         bsls::Types::Int64 hours,
                                         bsls::Types::Int64 minutes,
                                         bsls::Types::Int64 seconds,
                                         bsls::Types::Int64 milliseconds,
                                         bsls::Types::Int64 microseconds)
{
    if   (u::k_HOURS_CEILING        < hours
       || u::k_MINUTES_CEILING      < minutes
       || u::k_SECONDS_CEILING      < seconds
       || u::k_MILLISECONDS_CEILING < milliseconds
       || u::k_HOURS_FLOOR          > hours
       || u::k_MINUTES_FLOOR        > minutes
       || u::k_SECONDS_FLOOR        > seconds
       || u::k_MILLISECONDS_FLOOR   > milliseconds) {
        return -1;                                                    // RETURN
    }

    bsls::Types::Int64 d = static_cast<bsls::Types::Int64>(days)
                         + hours        / TimeUnitRatio::k_H_PER_D
                         + minutes      / TimeUnitRatio::k_M_PER_D
                         + seconds      / TimeUnitRatio::k_S_PER_D
                         + milliseconds / TimeUnitRatio::k_MS_PER_D
                         + microseconds / TimeUnitRatio::k_US_PER_D;

    hours        %= TimeUnitRatio::k_H_PER_D;
    minutes      %= TimeUnitRatio::k_M_PER_D;
    seconds      %= TimeUnitRatio::k_S_PER_D;
    milliseconds %= TimeUnitRatio::k_MS_PER_D;
    microseconds %= TimeUnitRatio::k_US_PER_D;

    bsls::Types::Int64 us = hours        * TimeUnitRatio::k_US_PER_H
                          + minutes      * TimeUnitRatio::k_US_PER_M
                          + seconds      * TimeUnitRatio::k_US_PER_S
                          + milliseconds * TimeUnitRatio::k_US_PER_MS
                          + microseconds;

    return assignIfValid(d, us);
}

void DatetimeInterval::setTotalSecondsFromDouble(double seconds)
{
    BSLS_ASSERT(!U_IS_INF(seconds));
    BSLS_ASSERT(!U_IS_NAN(seconds));

    double wholeDays;
    bsl::modf(seconds / TimeUnitRatio::k_S_PER_D, &wholeDays);
        // Ignoring fractional part to maintain as much accuracy from
        // 'seconds' as possible.

    BSLS_ASSERT(bsl::fabs(wholeDays) <= u::maxInt64AsDouble);
        // Failing for bsl::numeric_limits<bsls::Types::Int64>::min() is OK
        // here, because wholeDays has to fit into 32 bits.  Here we're just
        // checking that we are not about to run into UB when casting to
        // bsls::Types::Int64.

    volatile double microseconds =
                   (seconds - wholeDays * TimeUnitRatio::k_S_PER_D)
                   * TimeUnitRatio::k_US_PER_S + copysign(0.5, seconds);
        // On GCC x86 platforms we have to force copying a floating-point value
        // to memory using 'volatile' type qualifier to round-down the value
        // stored in x87 unit register.

    int rc = assignIfValid(static_cast<bsls::Types::Int64>(wholeDays),
                           static_cast<bsls::Types::Int64>(microseconds));

    BSLS_ASSERT(0 == rc);  (void)rc;
}

int DatetimeInterval::setTotalSecondsFromDoubleIfValid(double seconds)
{
    if (U_IS_INF(seconds) || U_IS_NAN(seconds)) {
        return -1;                                                    // RETURN
    }

    double wholeDays;
    bsl::modf(seconds / TimeUnitRatio::k_S_PER_D, &wholeDays);
        // Ignoring fractional part to maintain as much accuracy from
        // 'seconds' as possible.

    if (u::maxInt64AsDouble < wholeDays || wholeDays < u::minInt64AsDouble) {
        return -1;                                                    // RETURN
    }

    const double secondsRemainder =  seconds -
                                          wholeDays * TimeUnitRatio::k_S_PER_D;

    // On GCC x86 platforms we have to force copying a floating-point value to
    // memory using 'volatile' type qualifier to round-down the value stored in
    // x87 unit register.

    volatile double microseconds =
         secondsRemainder * TimeUnitRatio::k_US_PER_S + copysign(0.5, seconds);

    return assignIfValid(static_cast<bsls::Types::Int64>(wholeDays),
                         static_cast<bsls::Types::Int64>(microseconds));
}

DatetimeInterval& DatetimeInterval::addInterval(
                                               int                days,
                                               bsls::Types::Int64 hours,
                                               bsls::Types::Int64 minutes,
                                               bsls::Types::Int64 seconds,
                                               bsls::Types::Int64 milliseconds,
                                               bsls::Types::Int64 microseconds)
{
    bsls::Types::Int64 d = static_cast<bsls::Types::Int64>(days)
                         + hours        / TimeUnitRatio::k_H_PER_D
                         + minutes      / TimeUnitRatio::k_M_PER_D
                         + seconds      / TimeUnitRatio::k_S_PER_D
                         + milliseconds / TimeUnitRatio::k_MS_PER_D
                         + microseconds / TimeUnitRatio::k_US_PER_D;

    hours        %= TimeUnitRatio::k_H_PER_D;
    minutes      %= TimeUnitRatio::k_M_PER_D;
    seconds      %= TimeUnitRatio::k_S_PER_D;
    milliseconds %= TimeUnitRatio::k_MS_PER_D;
    microseconds %= TimeUnitRatio::k_US_PER_D;

    bsls::Types::Int64 us = hours        * TimeUnitRatio::k_US_PER_H
                          + minutes      * TimeUnitRatio::k_US_PER_M
                          + seconds      * TimeUnitRatio::k_US_PER_S
                          + milliseconds * TimeUnitRatio::k_US_PER_MS
                          + microseconds;

    assign(static_cast<bsls::Types::Int64>(d_days) + d,
           d_microseconds + us);

    return *this;
}

int DatetimeInterval::addIntervalIfValid(int                days,
                                         bsls::Types::Int64 hours,
                                         bsls::Types::Int64 minutes,
                                         bsls::Types::Int64 seconds,
                                         bsls::Types::Int64 milliseconds,
                                         bsls::Types::Int64 microseconds)
{
    bsls::Types::Int64 d = static_cast<bsls::Types::Int64>(days)
                         + hours        / TimeUnitRatio::k_H_PER_D
                         + minutes      / TimeUnitRatio::k_M_PER_D
                         + seconds      / TimeUnitRatio::k_S_PER_D
                         + milliseconds / TimeUnitRatio::k_MS_PER_D
                         + microseconds / TimeUnitRatio::k_US_PER_D;

    hours        %= TimeUnitRatio::k_H_PER_D;
    minutes      %= TimeUnitRatio::k_M_PER_D;
    seconds      %= TimeUnitRatio::k_S_PER_D;
    milliseconds %= TimeUnitRatio::k_MS_PER_D;
    microseconds %= TimeUnitRatio::k_US_PER_D;

    bsls::Types::Int64 us = hours        * TimeUnitRatio::k_US_PER_H
                          + minutes      * TimeUnitRatio::k_US_PER_M
                          + seconds      * TimeUnitRatio::k_US_PER_S
                          + milliseconds * TimeUnitRatio::k_US_PER_MS
                          + microseconds;

    // Note that 'k_MAX_INT' and 'k_MIN_INT' are, unlike 'INT_MAX' or
    // 'INT_MIN', 64-bit entities.

    if   ((d_days > 0 && d > 0 && u::k_MAX_INT - d_days < d)
       || (d_days < 0 && d < 0 && d < u::k_MIN_INT - d_days)
       || (d_microseconds > 0 && us > 0 && u::k_MAX_INT64-d_microseconds < us)
       || (d_microseconds < 0 && us < 0 &&
                                       us < u::k_MIN_INT64 - d_microseconds)) {
        return -1;                                                    // RETURN
    }

    return assignIfValid(static_cast<bsls::Types::Int64>(d_days) + d,
                         d_microseconds + us);
}

// ACCESSORS

                                  // Aspects

int DatetimeInterval::printToBuffer(char *result,
                                    int   numBytes,
                                    int   fractionalSecondPrecision) const
{
    BSLS_ASSERT(result);
    BSLS_ASSERT(0 <= numBytes);
    BSLS_ASSERT(0 <= fractionalSecondPrecision     );
    BSLS_ASSERT(     fractionalSecondPrecision <= 6);

    int d  = days();
    int h  = hours();
    int m  = minutes();
    int s  = seconds();
    int ms = milliseconds();
    int us = microseconds();

    // Values with a non-negative day component will have the sign
    // "pre-printed".

    int printedLength = 0;

    if (0 <= d_days) {
        if (1 < numBytes) {
            if (0 <= d_microseconds) {
                *result++ = '+';
            }
            else {
                *result++ = '-';
            }
            --numBytes;
        }
        printedLength = 1;
    }

    // Invert the time component values when the value is negative.

    if (0 > d_days || 0 > d_microseconds) {
        h  = -h;
        m  = -m;
        s  = -s;
        ms = -ms;
        us = -us;
    }

    int value;

    switch (fractionalSecondPrecision) {
      case 0: {
        char spec[] = "%d_%02d:%02d:%02d";

        // Add one for the sign.

        return u::printToBufferFormatted(result,
                                         numBytes,
                                         spec,
                                         d,
                                         h,
                                         m,
                                         s,
                                         0,
                                         0) + printedLength;          // RETURN
      } break;
      case 1: {
        value = ms / 100;
      } break;
      case 2: {
        value = ms / 10 ;
      } break;
      case 3: {
        value = ms;
      } break;
      case 4: {
        value = ms * 10   + us / 100;
      } break;
      case 5: {
        value = ms * 100  + us / 10;
      } break;
      default: {
        value = ms * 1000 + us;
      } break;
    }

    char spec[] = "%d_%02d:%02d:%02d.%0Xd";

    const int PRECISION_INDEX = sizeof spec - 3;

    spec[PRECISION_INDEX] = static_cast<char>('0' + fractionalSecondPrecision);

    // Add one for the sign.

    return u::printToBufferFormatted(
                                    result,
                                    numBytes,
                                    spec,
                                    d,
                                    h,
                                    m,
                                    s,
                                    value,
                                    fractionalSecondPrecision) + printedLength;
}

bsl::ostream& DatetimeInterval::print(bsl::ostream& stream,
                                      int           level,
                                      int           spacesPerLevel) const
{
    // Format the output to a buffer first instead of inserting into 'stream'
    // directly to improve performance and in case the caller has done
    // something like:
    //..
    //  os << bsl::setw(20) << myInterval;
    //..
    // The user-specified width will be effective when 'buffer' is written to
    // the 'stream' (below).

    const int k_BUFFER_SIZE = 32;
    char      buffer[k_BUFFER_SIZE];

    int rc = printToBuffer(buffer,
                           k_BUFFER_SIZE,
                           k_DEFAULT_FRACTIONAL_SECOND_PRECISION);

    (void)rc;

    bslim::Printer printer(&stream, level, spacesPerLevel);
    printer.start(true);    // 'true' -> suppress '['
    stream << buffer;
    printer.end(true);      // 'true' -> suppress ']'

    return stream;
}

#ifndef BDE_OMIT_INTERNAL_DEPRECATED  // BDE2.22

// DEPRECATED METHODS
bsl::ostream& DatetimeInterval::streamOut(bsl::ostream& stream) const
{
    return stream << *this;
}

#endif // BDE_OMIT_INTERNAL_DEPRECATED -- BDE2.22

}  // close package namespace
}  // close enterprise namespace

// ----------------------------------------------------------------------------
// Copyright 2017 Bloomberg Finance L.P.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------- END-OF-FILE ----------------------------------


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

  <title>Project Status</title>
  <meta name="Name" content="App: Project Status" />
  <meta name="Version" content="2012.11.28" />
  <meta name="Vendor" content="Rally Software" />