Example usage for org.joda.time Period Period

List of usage examples for org.joda.time Period Period

Introduction

In this page you can find the example usage for org.joda.time Period Period.

Prototype

public Period() 

Source Link

Document

Creates a new empty period with the standard set of fields.

Usage

From source file:ca.phon.ui.participant.ParticipantTableModel.java

License:Open Source License

private Object getValueForField(ParticipantTableField field) {
    if (field == ParticipantTableField.Name) {
        return (participant.getName() == null ? new String() : participant.getName());
    } else if (field == ParticipantTableField.Age) {
        return (participant.getAge(sessionDate) == null ? new Period() : participant.getAge(sessionDate));
    } else if (field == ParticipantTableField.Birthday) {
        return (participant.getBirthDate() == null ? DateTime.now() : participant.getBirthDate());
    } else if (field == ParticipantTableField.Education) {
        return (participant.getEducation() == null ? new String() : participant.getEducation());
    } else if (field == ParticipantTableField.Group) {
        return (participant.getGroup() == null ? new String() : participant.getGroup());
    } else if (field == ParticipantTableField.Sex) {
        return (participant.getSex() == null ? Sex.MALE : participant.getSex());
    } else if (field == ParticipantTableField.Role) {
        return (participant.getRole() == null ? new String() : participant.getRole());
    } else if (field == ParticipantTableField.Language) {
        return (participant.getLanguage() == null ? new String() : participant.getLanguage());
    } else {//from   ww  w .j ava 2 s  .  c o  m
        return new String();
    }
}

From source file:cd.go.contrib.elasticagents.docker.PluginSettings.java

License:Apache License

public Period getAutoRegisterPeriod() {
    if (this.autoRegisterPeriod == null) {
        this.autoRegisterPeriod = new Period().withMinutes(Integer.parseInt(getAutoRegisterTimeout()));
    }//from ww w.j  a  v  a2 s .co  m
    return this.autoRegisterPeriod;
}

From source file:com.jajja.jorm.mixins.Postgres.java

License:Open Source License

public static Period toPeriod(PGInterval interval) {
    if (interval == null) {
        return null;
    }//from ww w .  java 2s . c o m

    int seconds = (int) interval.getSeconds();
    int millis = (int) (interval.getSeconds() * 1000.0 - seconds);

    return new Period().plusYears(interval.getYears()).plusMonths(interval.getMonths())
            .plusDays(interval.getDays()).plusHours(interval.getHours()).plusMinutes(interval.getMinutes())
            .plusSeconds(seconds).plusMillis(millis);
}

From source file:com.jbirdvegas.mgerrit.search.AgeSearch.java

License:Apache License

/**
 * Parses a string into a Period object according to the replacers
 *  mapping. This allows for duplicate fields (e.g. seconds being
 *  declared twice as in "2s 3 sec") with the duplicate fields being
 *  added together (the above example would be the same as "5 seconds").
 * The order of the fields is not important.
 *
 * @param dateOffset The parameter without the operator. If the operator
 *                   is passed in it will be ignored
 * @return A period corresponding to the parsed input string
 *//* w w  w. ja v  a  2  s. c  om*/
private Period toPeriod(final String dateOffset) {
    String regexp = "(\\d+) *([a-zA-z]+)";
    Period period = new Period();

    if (dateOffset == null || dateOffset.isEmpty())
        return period;

    Pattern pattern = Pattern.compile(regexp);
    Matcher matcher = pattern.matcher(dateOffset);
    while (matcher.find()) {
        String svalue = matcher.toMatchResult().group(1);
        DurationFieldType fieldType = replacers.get(matcher.toMatchResult().group(2));
        if (fieldType != null) {
            // Note that both these methods do not modify their objects
            period = period.withFieldAdded(fieldType, Integer.parseInt(svalue));
        }
    }

    return period;
}

From source file:com.microsoft.azure.management.servicebus.implementation.QueueImpl.java

License:Open Source License

@Override
public Period defaultMessageTtlDuration() {
    if (this.inner().defaultMessageTimeToLive() == null) {
        return null;
    }/*from  ww w .j av  a 2 s  .  c o  m*/
    TimeSpan timeSpan = TimeSpan.parse(this.inner().defaultMessageTimeToLive());
    return new Period().withDays(timeSpan.days()).withHours(timeSpan.hours()).withSeconds(timeSpan.seconds())
            .withMinutes(timeSpan.minutes()).withMillis(timeSpan.milliseconds());
}

From source file:com.microsoft.azure.management.servicebus.implementation.QueueImpl.java

License:Open Source License

@Override
public Period duplicateMessageDetectionHistoryDuration() {
    if (this.inner().duplicateDetectionHistoryTimeWindow() == null) {
        return null;
    }/*  w ww .  ja  v  a2s.  c  o  m*/
    TimeSpan timeSpan = TimeSpan.parse(this.inner().duplicateDetectionHistoryTimeWindow());
    return new Period().withDays(timeSpan.days()).withHours(timeSpan.hours()).withMinutes(timeSpan.minutes())
            .withSeconds(timeSpan.seconds()).withMillis(timeSpan.milliseconds());
}

From source file:com.microsoft.azure.management.servicebus.implementation.ServiceBusSubscriptionImpl.java

License:Open Source License

@Override
public Period defaultMessageTtlDuration() {
    if (this.inner().defaultMessageTimeToLive() == null) {
        return null;
    }//w w w  . j  a v a 2  s  .  co m
    TimeSpan timeSpan = TimeSpan.parse(this.inner().defaultMessageTimeToLive());
    return new Period().withDays(timeSpan.days()).withHours(timeSpan.hours()).withMinutes(timeSpan.minutes())
            .withSeconds(timeSpan.seconds()).withMillis(timeSpan.milliseconds());
}

From source file:com.microsoft.azure.management.servicebus.samples.ServiceBusPublishSubscribeAdvanceFeatures.java

License:Open Source License

/**
 * Main function which runs the actual sample.
 * @param azure instance of the azure client
 * @return true if sample runs successfully
 *///from   w ww  .ja v  a2 s .c om
public static boolean runSample(Azure azure) {
    // New resources
    final String rgName = SdkContext.randomResourceName("rgSB04_", 24);
    final String namespaceName = SdkContext.randomResourceName("namespace", 20);
    final String topic1Name = SdkContext.randomResourceName("topic1_", 24);
    final String topic2Name = SdkContext.randomResourceName("topic2_", 24);
    final String subscription1Name = SdkContext.randomResourceName("subs_", 24);
    final String subscription2Name = SdkContext.randomResourceName("subs_", 24);
    final String subscription3Name = SdkContext.randomResourceName("subs_", 24);
    final String sendRuleName = "SendRule";
    final String manageRuleName = "ManageRule";

    try {
        //============================================================
        // Create a namespace.

        System.out.println("Creating name space " + namespaceName + " in resource group " + rgName + "...");

        ServiceBusNamespace serviceBusNamespace = azure.serviceBusNamespaces().define(namespaceName)
                .withRegion(Region.US_WEST).withNewResourceGroup(rgName).withSku(NamespaceSku.PREMIUM_CAPACITY1)
                .withNewTopic(topic1Name, 1024).create();

        System.out.println("Created service bus " + serviceBusNamespace.name());
        Utils.print(serviceBusNamespace);

        System.out.println("Created topic following topic along with namespace " + namespaceName);

        Topic firstTopic = serviceBusNamespace.topics().getByName(topic1Name);
        Utils.print(firstTopic);

        //============================================================
        // Create a service bus subscription in the topic with session and dead-letter enabled.

        System.out.println("Creating subscription " + subscription1Name + " in topic " + topic1Name + "...");
        ServiceBusSubscription firstSubscription = firstTopic.subscriptions().define(subscription1Name)
                .withSession().withDefaultMessageTTL(new Period().withMinutes(20))
                .withMessageMovedToDeadLetterSubscriptionOnMaxDeliveryCount(20)
                .withExpiredMessageMovedToDeadLetterSubscription()
                .withMessageMovedToDeadLetterSubscriptionOnFilterEvaluationException().create();
        System.out.println("Created subscription " + subscription1Name + " in topic " + topic1Name + "...");

        Utils.print(firstSubscription);

        //============================================================
        // Create another subscription in the topic with auto deletion of idle entities.
        System.out.println(
                "Creating another subscription " + subscription2Name + " in topic " + topic1Name + "...");

        ServiceBusSubscription secondSubscription = firstTopic.subscriptions().define(subscription2Name)
                .withSession().withDeleteOnIdleDurationInMinutes(20).create();
        System.out.println("Created subscription " + subscription2Name + " in topic " + topic1Name + "...");

        Utils.print(secondSubscription);

        //============================================================
        // Create second topic with new Send Authorization rule, partitioning enabled and a new Service bus Subscription.

        System.out.println("Creating second topic " + topic2Name
                + ", with De-duplication and AutoDeleteOnIdle features...");

        Topic secondTopic = serviceBusNamespace.topics().define(topic2Name).withNewSendRule(sendRuleName)
                .withPartitioning().withNewSubscription(subscription3Name).create();

        System.out.println("Created second topic in namespace");

        Utils.print(secondTopic);

        System.out.println("Creating following authorization rules in second topic ");

        PagedList<TopicAuthorizationRule> authorizationRules = secondTopic.authorizationRules().list();
        for (TopicAuthorizationRule authorizationRule : authorizationRules) {
            Utils.print(authorizationRule);
        }

        //============================================================
        // Update second topic to change time for AutoDeleteOnIdle time, without Send rule and with a new manage authorization rule.
        System.out.println("Updating second topic " + topic2Name + "...");

        secondTopic = secondTopic.update().withDeleteOnIdleDurationInMinutes(5)
                .withoutAuthorizationRule(sendRuleName).withNewManageRule(manageRuleName).apply();

        System.out.println("Updated second topic to change its auto deletion time");

        Utils.print(secondTopic);
        System.out.println(
                "Updated  following authorization rules in second topic, new list of authorization rules are ");

        authorizationRules = secondTopic.authorizationRules().list();
        for (TopicAuthorizationRule authorizationRule : authorizationRules) {
            Utils.print(authorizationRule);
        }

        //=============================================================
        // Get connection string for default authorization rule of namespace

        PagedList<NamespaceAuthorizationRule> namespaceAuthorizationRules = serviceBusNamespace
                .authorizationRules().list();
        System.out.println("Number of authorization rule for namespace :" + namespaceAuthorizationRules.size());

        for (NamespaceAuthorizationRule namespaceAuthorizationRule : namespaceAuthorizationRules) {
            Utils.print(namespaceAuthorizationRule);
        }

        System.out.println("Getting keys for authorization rule ...");

        AuthorizationKeys keys = namespaceAuthorizationRules.get(0).getKeys();
        Utils.print(keys);

        //=============================================================
        // Send a message to topic.
        try {
            Configuration config = Configuration.load();
            config.setProperty(ServiceBusConfiguration.CONNECTION_STRING, keys.primaryConnectionString());
            ServiceBusContract service = ServiceBusService.create(config);
            service.sendTopicMessage(topic1Name, new BrokeredMessage("Hello World"));
        } catch (Exception ex) {
        }
        //=============================================================
        // Delete a topic and namespace
        System.out.println("Deleting topic " + topic1Name + "in namespace " + namespaceName + "...");
        serviceBusNamespace.topics().deleteByName(topic1Name);
        System.out.println("Deleted topic " + topic1Name + "...");

        System.out.println("Deleting namespace " + namespaceName + "...");
        // This will delete the namespace and topic within it.
        try {
            azure.serviceBusNamespaces().deleteById(serviceBusNamespace.id());
        } catch (Exception ex) {
        }
        System.out.println("Deleted namespace " + namespaceName + "...");

        return true;
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
    } finally {
        try {
            System.out.println("Deleting Resource Group: " + rgName);
            azure.resourceGroups().beginDeleteByName(rgName);
            System.out.println("Deleted Resource Group: " + rgName);
        } catch (NullPointerException npe) {
            System.out.println("Did not create any resources in Azure. No clean up is necessary");
        } catch (Exception g) {
            g.printStackTrace();
        }
    }
    return false;
}

From source file:com.microsoft.azure.management.servicebus.samples.ServiceBusQueueAdvanceFeatures.java

License:Open Source License

/**
 * Main function which runs the actual sample.
 * @param azure instance of the azure client
 * @return true if sample runs successfully
 */// w  ww  .j  av a  2 s  .co m
public static boolean runSample(Azure azure) {
    // New resources
    final String rgName = SdkContext.randomResourceName("rgSB04_", 24);
    final String namespaceName = SdkContext.randomResourceName("namespace", 20);
    final String queue1Name = SdkContext.randomResourceName("queue1_", 24);
    final String queue2Name = SdkContext.randomResourceName("queue2_", 24);
    final String sendRuleName = "SendRule";

    try {
        //============================================================
        // Create a namespace.

        System.out.println("Creating name space " + namespaceName + " in resource group " + rgName + "...");

        ServiceBusNamespace serviceBusNamespace = azure.serviceBusNamespaces().define(namespaceName)
                .withRegion(Region.US_WEST).withNewResourceGroup(rgName).withSku(NamespaceSku.PREMIUM_CAPACITY1)
                .create();

        System.out.println("Created service bus " + serviceBusNamespace.name());
        Utils.print(serviceBusNamespace);

        //============================================================
        // Add a queue in namespace with features session and dead-lettering.
        System.out.println("Creating first queue " + queue1Name
                + ", with session, time to live and move to dead-letter queue features...");

        Queue firstQueue = serviceBusNamespace.queues().define(queue1Name).withSession()
                .withDefaultMessageTTL(new Period().withMinutes(10)).withExpiredMessageMovedToDeadLetterQueue()
                .withMessageMovedToDeadLetterQueueOnMaxDeliveryCount(40).create();
        Utils.print(firstQueue);

        //============================================================
        // Create second queue with Deduplication and AutoDeleteOnIdle feature

        System.out.println("Creating second queue " + queue2Name
                + ", with De-duplication and AutoDeleteOnIdle features...");

        Queue secondQueue = serviceBusNamespace.queues().define(queue2Name).withSizeInMB(2048)
                .withDuplicateMessageDetection(new Period().withMinutes(10))
                .withDeleteOnIdleDurationInMinutes(10).create();

        System.out.println("Created second queue in namespace");

        Utils.print(secondQueue);

        //============================================================
        // Update second queue to change time for AutoDeleteOnIdle.

        secondQueue = secondQueue.update().withDeleteOnIdleDurationInMinutes(5).apply();

        System.out.println("Updated second queue to change its auto deletion time");

        Utils.print(secondQueue);

        //=============================================================
        // Update first queue to disable dead-letter forwarding and with new Send authorization rule
        secondQueue = firstQueue.update().withoutExpiredMessageMovedToDeadLetterQueue()
                .withNewSendRule(sendRuleName).apply();

        System.out.println("Updated first queue to change dead-letter forwarding");

        Utils.print(secondQueue);

        //=============================================================
        // Get connection string for default authorization rule of namespace

        PagedList<NamespaceAuthorizationRule> namespaceAuthorizationRules = serviceBusNamespace
                .authorizationRules().list();
        System.out.println("Number of authorization rule for namespace :" + namespaceAuthorizationRules.size());

        for (NamespaceAuthorizationRule namespaceAuthorizationRule : namespaceAuthorizationRules) {
            Utils.print(namespaceAuthorizationRule);
        }

        System.out.println("Getting keys for authorization rule ...");

        AuthorizationKeys keys = namespaceAuthorizationRules.get(0).getKeys();
        Utils.print(keys);

        //=============================================================
        // Update first queue to remove Send Authorization rule.
        firstQueue.update().withoutAuthorizationRule(sendRuleName).apply();

        //=============================================================
        // Send a message to queue.

        try {
            Configuration config = Configuration.load();
            config.setProperty(ServiceBusConfiguration.CONNECTION_STRING, keys.primaryConnectionString());
            ServiceBusContract service = ServiceBusService.create(config);
            BrokeredMessage message = new BrokeredMessage("Hello");
            message.setSessionId("23424");
            service.sendQueueMessage(queue1Name, message);
        } catch (Exception ex) {
        }

        //=============================================================
        // Delete a queue and namespace
        System.out.println("Deleting queue " + queue1Name + "in namespace " + namespaceName + "...");
        serviceBusNamespace.queues().deleteByName(queue1Name);
        System.out.println("Deleted queue " + queue1Name + "...");

        System.out.println("Deleting namespace " + namespaceName + "...");
        // This will delete the namespace and queue within it.
        try {
            azure.serviceBusNamespaces().deleteById(serviceBusNamespace.id());
        } catch (Exception ex) {
        }
        System.out.println("Deleted namespace " + namespaceName + "...");

        return true;
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
    } finally {
        try {
            System.out.println("Deleting Resource Group: " + rgName);
            azure.resourceGroups().beginDeleteByName(rgName);
            System.out.println("Deleted Resource Group: " + rgName);
        } catch (NullPointerException npe) {
            System.out.println("Did not create any resources in Azure. No clean up is necessary");
        } catch (Exception g) {
            g.printStackTrace();
        }
    }
    return false;
}

From source file:com.nestedbird.models.eventtime.EventTime.java

License:Open Source License

@Builder
private EventTime(final String id, final Event event, final DateTime startTime, final Period duration,
        final Period repeatTime, final DateTime repeatEnd, final Boolean active) {
    super(id);/*from   w  w  w  . j  av  a 2  s.  c o  m*/

    // Fatal if null
    if (event == null)
        throw new NullPointerException("A time must have an event");
    this.event = event;

    // Null Safe
    this.startTime = Optional.ofNullable(startTime).orElse(new DateTime());
    this.duration = Optional.ofNullable(duration).orElse(new Period());
    this.repeatTime = Optional.ofNullable(repeatTime).orElse(new Period());
    this.repeatEnd = Optional.ofNullable(repeatEnd).orElse(new DateTime());
    setActive(Optional.ofNullable(active).orElse(false));
}